Commit ac3fcbf0 authored by droces's avatar droces

Several JS-related fixes for Book page

parent 57e355c3
......@@ -10,6 +10,7 @@ abookings:
- core/drupal
- core/drupalSettings
- core/jquery
- core/jquery.ui.dialog
# - core/jquery.once
# - abookings/moment
......
......@@ -151,7 +151,7 @@ label.form-required {
margin: 0;
}
.fc table td {
cursor: pointer;
/*cursor: pointer;*/
}
.fc table tr {
background: none;
......@@ -213,7 +213,7 @@ label.form-required {
}
.fc .fc-bg .fc-day:hover,
.fc .fc-bg .fc-day:focus {
background-color: rgba(30, 149, 188, 0.3); /* blue */
background-color: none; /* rgba(30, 149, 188, 0.3); */ /* blue */
}
.fc-unthemed td.fc-today {
/*background: rgba(105, 197, 255, 0.16);*/ /* pale blue */
......
......@@ -42,6 +42,8 @@
.validate_booking_form()
*/
var page_setup = false;
var calendar,
booking_form,
events = {},
......@@ -71,100 +73,104 @@ Drupal.behaviors.abookings = {
// console.log('settings: ', settings);
// console.log('drupalSettings: ', drupalSettings);
switch (drupalSettings.route.name) {
case 'abookings.book_page':
Drupal.abookings.set_booking_form('#node-booking-form', context);
break;
case 'entity.node.edit_form':
Drupal.abookings.set_booking_form('#node-booking-edit-form', context);
break;
case 'node.add':
Drupal.abookings.set_booking_form('#node-booking-form', context);
break;
}
if (! page_setup) {
switch (drupalSettings.route.name) {
case 'abookings.book_page':
Drupal.abookings.set_booking_form('#node-booking-form', context);
break;
case 'entity.node.edit_form':
Drupal.abookings.set_booking_form('#node-booking-edit-form', context);
break;
case 'node.add':
Drupal.abookings.set_booking_form('#node-booking-form', context);
break;
}
Drupal.abookings.set_page_elements(context);
Drupal.abookings.set_page_elements(context);
if (calendar.length >= 1) {
set_up_calendar(context);
}
if (calendar.length >= 1) {
set_up_calendar(context);
}
var backend_url = drupalSettings.booking_settings['backend_url'];
var bookable_nid = Drupal.abookings.get_bookable_nid();
var backend_url = drupalSettings.booking_settings['backend_url'];
var bookable_nid = Drupal.abookings.get_bookable_nid();
if (! is_bookable_data_fetched) {
Drupal.abookings.fetch_bookable_data('seasons', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('bookings', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('addons', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('bookables', 'all', backend_url);
is_bookable_data_fetched = true;
}
if (! is_bookable_data_fetched) {
Drupal.abookings.fetch_bookable_data('seasons', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('bookings', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('addons', bookable_nid, backend_url);
Drupal.abookings.fetch_bookable_data('bookables', 'all', backend_url);
is_bookable_data_fetched = true;
}
// Bind a click handler on the ctools modal dialog's backdrop that closes that modal.
$(document).on('dialog_opened', function(event) {
// Bind a click handler on the modal dialogs' backdrops that closes modals.
$('.ui-widget-overlay', context).once('backdrop-close-modal').click(function() {
// console.log('.ui-widget-overlay.click()');
to_dialog.dialog( "close" );
// Bind a click handler on the ctools modal dialog's backdrop that closes that modal.
$(document).on('dialog_opened', function(event) {
// Bind a click handler on the modal dialogs' backdrops that closes modals.
$('.ui-widget-overlay', context).once('backdrop-close-modal').click(function() {
// console.log('.ui-widget-overlay.click()');
to_dialog.dialog( "close" );
});
});
});
add_booking_data_fetched_listener();
add_booking_data_fetched_listener();
// Define hover listeners
// Define hover listeners
var calendar_days = $(calendar).find('.fc-day');
// console.log('calendar_days: ', calendar_days);
var calendar_days = $(calendar).find('.fc-day');
// console.log('calendar_days: ', calendar_days);
calendar_days.on('mouseenter', function() {
// calendar_days.removeClass('active');
// $(this).addClass('active');
});
calendar_days.on('mouseleave', function() {
// $(this).removeClass('active');
});
calendar_days.on('mouseenter', function() {
// calendar_days.removeClass('active');
// $(this).addClass('active');
});
calendar_days.on('mouseleave', function() {
// $(this).removeClass('active');
});
// Define listeners
// Define listeners
booking_form.once('booking_form:on_submit').on('submit', function(event) {
if (drupalSettings.route.name == 'entity.node.edit_form'
|| drupalSettings.route.name == 'node.add') {
return true;
}
booking_form.once('booking_form:on_submit').on('submit', function(event) {
if (drupalSettings.route.name == 'entity.node.edit_form'
|| drupalSettings.route.name == 'node.add') {
return true;
}
if (! is_valid_promo) {
alert('Promo code is not valid.');
return false;
}
if (! is_valid_promo) {
alert('Promo code is not valid.');
return false;
}
// Save the booking using AJAX
// Save the booking using AJAX
event.preventDefault();
event.preventDefault();
is_valid = Drupal.abookings.validate_booking_form();
if (! is_valid) {
return false;
}
is_valid = Drupal.abookings.validate_booking_form();
if (! is_valid) {
return false;
}
var serialized_form = $(this).serializeArray();
// console.log('serialized_form: ', serialized_form);
var serialized_form = $(this).serializeArray();
// console.log('serialized_form: ', serialized_form);
Drupal.abookings.create_booking(serialized_form);
});
Drupal.abookings.create_booking(serialized_form);
});
add_field_listeners();
add_field_listeners();
$('#validate_promo').once('validate_promo').click(function(event) {
event.preventDefault();
// console.log('promo_code: ', promo_code);
Drupal.abookings.validate_promo();
});
$('#validate_promo').once('validate_promo').click(function(event) {
event.preventDefault();
// console.log('promo_code: ', promo_code);
Drupal.abookings.validate_promo();
});
refresh_main_info();
refresh_main_info();
// show_thank_you_dialog('test', booking_info_container);
// show_thank_you_dialog('test', booking_info_container);
page_setup = true;
}
}
};
......@@ -533,8 +539,11 @@ function show_thank_you_dialog(nid, container) {
+ 'We have sent you an email with your provisional booking information.</p>'
+ '<p>Your reference number is <strong>' + nid + '</strong></p></div>';
var message = $(message_text)
.appendTo(container.find('.message_container'))
.dialog({
.appendTo(container.find('.message_container'));
console.log('container: ', container);
console.log('message: ', message);
message.dialog({
title: 'Booking successful',
dialogClass: 'no-close',
modal: true,
......@@ -998,6 +1007,9 @@ Drupal.abookings = {
var active_bookable_data = Drupal.abookings.get_bookable_data();
// console.log('active_bookable_data: ', active_bookable_data);
if (! active_bookable_data) {
return null;
}
// If there is no current event, quit.
if ((drupalSettings.route.name == 'abookings.book_page') && (! events.hasOwnProperty('current'))) {
......
......@@ -104,6 +104,7 @@ function booking_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Form for creating new booking nodes
case 'node_booking_form':
$form['actions']['publish']['#value'] = t('Book');
$form['actions']['submit']['#value'] = t('Book');
if (in_array("/book", $build_info_args)) {
// kint('is front-end booking form');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment