{% set villes_hotels = getVillesHotels('SHT',false,app.request.get('destination','all')) %}
{% set selected_destination = villes_hotels.selected_destination %}
{% set villes_hotels = villes_hotels.destinations %}
{% set nuitees = app.request.get('nuitees',1) %}
{% set checkin = app.request.get('checkin',date('now')) %}
{% set rooms = roomsToArray(app.request.get('rooms','2')) %}
<script>
var vjsAdvancedSearch = new Vue({
el: '#vjs-advanced-search',
delimiters: ['${', '}'],
data: {
rooms: {{ rooms|json_encode|raw }},
checkin_fr: '{{ checkin|date('d/m/Y') }}',
checkout_fr: '{{ checkin|date_modify("+" ~ nuitees ~ " day")|date('d/m/Y') }}',
checkin_en: '{{ checkin|date('Y-m-d') }}',
checkout_en: '{{ checkin|date_modify("+" ~ nuitees ~ " day")|date('Y-m-d') }}',
nuitees: {{ nuitees }},
pays: '{{ (selected_destination and selected_destination.pays is defined) ? selected_destination.pays : 'all' }}',
ville: '{{ (selected_destination and selected_destination.ville is defined) ? selected_destination.ville : 'all' }}',
hotel: '{{ (selected_destination and selected_destination.hotel is defined) ? selected_destination.hotel : 'tous' }}',
destination: '{{ selected_destination ? selected_destination.type ~ '-' ~ selected_destination.id : 'all' }}',
lbl_destination: '{{ selected_destination ? selected_destination.name : '' }}',
occupations: '',
recap_occupations: '',
},
methods: {
callAvailability() {
if ($('.typeahead.destination').val() == '') {
viewAlert('Veuillez choisir une ville ou un hôtel', 'danger')
return
}
//$('#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);
//$('#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' : ''}`);
//$('#mobile-occupations').html(this.recap_occupations);
$('#btnSearch').prop('disabled', true)
$('#btnSearch').html('<i class="fa fa-spinner fa-spin"></i> Veuillez patienter ')
$('#btnSearch').html('<i class="fa fa-spinner fa-spin"></i> Veuillez patienter ')
window.location = Routing.generate('sejour_hotel_availability', {
checkin: this.checkin_en,
nuitees: this.nuitees,
rooms: this.occupations,
/*destination: this.destination*/
pays: this.pays,
ville: this.ville,
hotel: this.hotel,
})
},
Recap() {
let nbrR = this.rooms.length,
nbrA = 0,
nbrC = 0;
let rooms = []
this.rooms.map(x => {
nbrA += parseInt(x['Adult']);
nbrC += parseInt(x['children']);
rooms.push(([x['Adult']].concat(x['Child'])).join(','))
});
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' : '')
$('[data-target="#occupations"]').val(text);
this.occupations = rooms.join(';')
this.recap_occupations = text
$('#occupations').modal('hide')
},
editChildren(index) {
let old_child = this.rooms[index]['Child'].length;
let new_child = this.rooms[index]['children'];
if (old_child > new_child)
this.rooms[index]['Child'].length = new_child;
else
do
this.rooms[index]['Child'].push(1)
while (this.rooms[index]['Child'].length < new_child);
},
removeRoom(index) {
this.rooms.splice(index, 1);
},
addRoom() {
this.rooms.push({
Adult: 2,
children: 0,
Child: []
})
},
},
mounted() {
$('.typeahead.destination').val(this.lbl_destination)
this.Recap()
$(this.$refs.select).selectpicker('refresh')
},
updated() {
$(this.$refs.select).selectpicker('refresh')
},
destroyed() {
$(this.$refs.select).off().selectpicker('destroy')
}
});
$(function() {
var date=new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('input[name="daterange"]').daterangepicker({
"autoApply": false,
"startDate": vjsAdvancedSearch.checkin_fr,
"endDate": vjsAdvancedSearch.checkout_fr,
"minDate": new Date(currentYear, currentMonth, currentDate),
"opens": "right",
"drops": "down",
"locale": {
"applyLabel": "Valider",
"cancelLabel": "Annuler",
"format": "DD/MM/YYYY",
"fromLabel": "De",
"toLabel": "à",
"customRangeLabel": "Custom",
"daysOfWeek": [
"Dim",
"Lun",
"Mar",
"Mer",
"Jeu",
"Ven",
"Sam"
],
"monthNames": [
"Janvier",
"Février",
"Mars",
"Avril",
"Mai",
"Juin",
"Juillet",
"Août",
"Septembre",
"Octobre",
"Novembre",
"Décembre"
],
"firstDay": 1,
}
},
function (start, end, label) {
vjsAdvancedSearch.checkin_en = start.format('YYYY-MM-DD')
vjsAdvancedSearch.checkout_en = end.format('YYYY-MM-DD')
vjsAdvancedSearch.checkin_fr = start.format('DD/MM/YYYY')
vjsAdvancedSearch.checkout_fr = end.format('DD/MM/YYYY')
vjsAdvancedSearch.nuitees = parseInt((end - start) / 1000 / 60 / 60 / 24)
});
});
var $input = $("input.typeahead.destination");
$input.typeahead({
limit: 20,
source: {{ villes_hotels|json_encode|raw }},
autoSelect: true,
displayText: function (item) {
return item.name
},
//highlighter: Object,
afterSelect: function (item) {
$input.val(item.name).change();
vjsAdvancedSearch.pays = item.pays
vjsAdvancedSearch.ville = item.ville
vjsAdvancedSearch.hotel = (item.hotel === undefined ? 'tous' : item.hotel)
vjsAdvancedSearch.destination = `${item.type}-${item.id}`
vjsAdvancedSearch.lbl_destination = item.name
}
});
</script>