templates/vuejs-filtre-home.html.twig line 1

Open in your IDE?
  1. {% set villes_hotels = getVillesHotels('SHT',false,app.request.get('destination','all')) %}
  2. {% set selected_destination = villes_hotels.selected_destination %}
  3. {% set villes_hotels = villes_hotels.destinations %}
  4. {% set nuitees = app.request.get('nuitees',1) %}
  5. {% set checkin = app.request.get('checkin',date('now')) %}
  6. {% set rooms = roomsToArray(app.request.get('rooms','2')) %}
  7. <script>
  8.     var vjsAdvancedSearch = new Vue({
  9.         el: '#vjs-advanced-search',
  10.         delimiters:  ['${', '}'],
  11.         data: {
  12.             rooms: {{ rooms|json_encode|raw }},
  13.             checkin_fr: '{{ checkin|date('d/m/Y') }}',
  14.             checkout_fr: '{{ checkin|date_modify("+" ~ nuitees ~ " day")|date('d/m/Y') }}',
  15.             checkin_en: '{{ checkin|date('Y-m-d') }}',
  16.             checkout_en: '{{ checkin|date_modify("+" ~ nuitees ~ " day")|date('Y-m-d') }}',
  17.             nuitees: {{ nuitees }},
  18.             pays: '{{ (selected_destination and selected_destination.pays is defined) ? selected_destination.pays : 'all' }}',
  19.             ville: '{{ (selected_destination and selected_destination.ville is defined) ? selected_destination.ville : 'all' }}',
  20.             hotel: '{{ (selected_destination and selected_destination.hotel is defined) ? selected_destination.hotel : 'tous' }}',
  21.             destination: '{{ selected_destination ? selected_destination.type ~ '-' ~ selected_destination.id : 'all' }}',
  22.             lbl_destination: '{{ selected_destination ? selected_destination.name : '' }}',
  23.             occupations: '',
  24.             recap_occupations: '',
  25.         },
  26.         methods: {
  27.             callAvailability() {
  28.                 if ($('.typeahead.destination').val() == '') {
  29.                     viewAlert('Veuillez choisir une ville ou un hôtel', 'danger')
  30.                     return
  31.                 }
  32.                 //$('#mobile-destination').html(`<i class="fa fa-${this.destination.split('-')[0] == 'v' ? 'map-marker' : 'hotel'} fa-1" aria-hidden="true" style=" margin-left: 1px;"></i> ` + this.lbl_destination);
  33.                 //$('#mobile-sejour').html(`Du ${this.checkin_fr.substr(0, 5)} au ${this.checkout_fr.substr(0, 5)} soit ${this.nuitees == 1 ? 'une' : this.nuitees} nuitée${this.nuitees > 1 ? 's' : ''}`);
  34.                 //$('#mobile-occupations').html(this.recap_occupations);
  35.                 $('#btnSearch').prop('disabled', true)
  36.                 $('#btnSearch').html('<i class="fa fa-spinner fa-spin"></i> Veuillez patienter ')
  37.                 $('#btnSearch').html('<i class="fa fa-spinner fa-spin"></i> Veuillez patienter ')
  38.                 window.location = Routing.generate('sejour_hotel_availability', {
  39.                     checkin: this.checkin_en,
  40.                     nuitees: this.nuitees,
  41.                     rooms: this.occupations,
  42.                     /*destination: this.destination*/
  43.                     pays: this.pays,
  44.                     ville: this.ville,
  45.                     hotel: this.hotel,
  46.                 })
  47.             },
  48.             Recap() {
  49.                 let nbrR = this.rooms.length,
  50.                     nbrA = 0,
  51.                     nbrC = 0;
  52.                 let rooms = []
  53.                 this.rooms.map(x => {
  54.                     nbrA += parseInt(x['Adult']);
  55.                     nbrC += parseInt(x['children']);
  56.                     rooms.push(([x['Adult']].concat(x['Child'])).join(','))
  57.                 });
  58.                 let text = (nbrR == 1 ? 'une' : nbrR) + ' chambre' + (nbrR > 1 ? 's' : '') + ': ' + (nbrA == 1 ? 'un' : nbrA) + ' adulte' + (nbrA > 1 ? 's' : '') + ' et ' + (nbrC == 1 ? 'un' : nbrC) + ' enfant' + (nbrC > 1 ? 's' : '')
  59.                 $('[data-target="#occupations"]').val(text);
  60.                 this.occupations = rooms.join(';')
  61.                 this.recap_occupations = text
  62.                 $('#occupations').modal('hide')
  63.             },
  64.             editChildren(index) {
  65.                 let old_child = this.rooms[index]['Child'].length;
  66.                 let new_child = this.rooms[index]['children'];
  67.                 if (old_child > new_child)
  68.                     this.rooms[index]['Child'].length = new_child;
  69.                 else
  70.                     do
  71.                         this.rooms[index]['Child'].push(1)
  72.                     while (this.rooms[index]['Child'].length < new_child);
  73.             },
  74.             removeRoom(index) {
  75.                 this.rooms.splice(index, 1);
  76.             },
  77.             addRoom() {
  78.                 this.rooms.push({
  79.                     Adult: 2,
  80.                     children: 0,
  81.                     Child: []
  82.                 })
  83.             },
  84.         },
  85.         mounted() {
  86.             $('.typeahead.destination').val(this.lbl_destination)
  87.             this.Recap()
  88.             $(this.$refs.select).selectpicker('refresh')
  89.         },
  90.         updated() {
  91.             $(this.$refs.select).selectpicker('refresh')
  92.         },
  93.         destroyed() {
  94.             $(this.$refs.select).off().selectpicker('destroy')
  95.         }
  96.     });
  97.     $(function() {
  98.         var date=new Date();
  99.         var currentMonth = date.getMonth();
  100.         var currentDate = date.getDate();
  101.         var currentYear = date.getFullYear();
  102.         $('input[name="daterange"]').daterangepicker({
  103.                 "autoApply": false,
  104.                 "startDate": vjsAdvancedSearch.checkin_fr,
  105.                 "endDate": vjsAdvancedSearch.checkout_fr,
  106.                 "minDate": new Date(currentYear, currentMonth, currentDate),
  107.                 "opens": "right",
  108.                 "drops": "down",
  109.                 "locale": {
  110.                     "applyLabel": "Valider",
  111.                     "cancelLabel": "Annuler",
  112.                     "format": "DD/MM/YYYY",
  113.                     "fromLabel": "De",
  114.                     "toLabel": "à",
  115.                     "customRangeLabel": "Custom",
  116.                     "daysOfWeek": [
  117.                         "Dim",
  118.                         "Lun",
  119.                         "Mar",
  120.                         "Mer",
  121.                         "Jeu",
  122.                         "Ven",
  123.                         "Sam"
  124.                     ],
  125.                     "monthNames": [
  126.                         "Janvier",
  127.                         "Février",
  128.                         "Mars",
  129.                         "Avril",
  130.                         "Mai",
  131.                         "Juin",
  132.                         "Juillet",
  133.                         "Août",
  134.                         "Septembre",
  135.                         "Octobre",
  136.                         "Novembre",
  137.                         "Décembre"
  138.                     ],
  139.                     "firstDay": 1,
  140.                 }
  141.             },
  142.             function (start, end, label) {
  143.                 vjsAdvancedSearch.checkin_en = start.format('YYYY-MM-DD')
  144.                 vjsAdvancedSearch.checkout_en = end.format('YYYY-MM-DD')
  145.                 vjsAdvancedSearch.checkin_fr = start.format('DD/MM/YYYY')
  146.                 vjsAdvancedSearch.checkout_fr = end.format('DD/MM/YYYY')
  147.                 vjsAdvancedSearch.nuitees = parseInt((end - start) / 1000 / 60 / 60 / 24)
  148.             });
  149.     });
  150.     var $input = $("input.typeahead.destination");
  151.     $input.typeahead({
  152.         limit: 20,
  153.         source: {{ villes_hotels|json_encode|raw }},
  154.         autoSelect: true,
  155.         displayText: function (item) {
  156.             return item.name
  157.         },
  158.         //highlighter: Object,
  159.         afterSelect: function (item) {
  160.             $input.val(item.name).change();
  161.             vjsAdvancedSearch.pays = item.pays
  162.             vjsAdvancedSearch.ville = item.ville
  163.             vjsAdvancedSearch.hotel = (item.hotel === undefined ? 'tous' : item.hotel)
  164.             vjsAdvancedSearch.destination = `${item.type}-${item.id}`
  165.             vjsAdvancedSearch.lbl_destination = item.name
  166.         }
  167.     });
  168. </script>