Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mews
Mews.Distributor({
configurationIds: $.map(iweb_mews_config, function (o) {
return o["configurationid"];
}),
hotelIds : ['1', '2'], // Hacky workaround to force Distributor into chain mode.
}, function (distributor) {
// Hook into booking links, optionally prepopulate a voucher code.
$('.js-booking-link').on('click', function (e) {
e.preventDefault();
if ($(e.target).attr('data-voucher')) {
distributor.setVoucherCode($(e.target).data('voucher'));
}
distributor.open();
});
// Hook into booking forms. Prepopulate date and hostel.
$('.clink-booknow form').on('submit', function (e) {
e.preventDefault();
$('#hostel option:selected', e.target).data('cityid')
var start_date = new Date($('#dci', e.target).val());
var nights = parseInt($('#nights', e.target).val());
var end_date = get_end_date(start_date, nights);
distributor.setStartDate(start_date);
distributor.setEndDate(end_date);
console.log(iweb_mews_config[$('#hostel', e.target).val()]["cityid"]);
distributor.setCity(iweb_mews_config[$('#hostel', e.target).val()]["cityid"]);
distributor.showRooms(iweb_mews_config[$('#hostel', e.target).val()]["hotelid"]);
distributor.open();
});
});
// Work out end date based on start date and number of nights.
function get_end_date(start_date, nights) {
var end_date = new Date(start_date);
end_date.setDate(end_date.getDate() + nights);
return end_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.