Commit 064fbf10 authored by droces's avatar droces

Loads of JS fixes and improvements

parent e46778d7
......@@ -15,19 +15,27 @@
/**
CONTENTS
add_field_listeners()
add_booking_data_fetched_listener()
set_up_calendar()
refresh_main_info()
save_booking()
get_addons_sum()
get_addons_total()
.set_up_dialogs()
.add_booking_form_submit_handler()
.add_field_listeners()
.check_num_guests()
.check_date_field_valid_value()
.add_booking_data_fetched_listener()
.setup_addons()
.get_addons_total_guests()
.calculate_max_guests()
.set_up_calendar()
.refresh_main_info()
.save_booking()
.show_thank_you_dialog()
.get_addons_sum()
.get_addons_total()
Drupal.abookings
.get_bookable_nid()
.get_bookable_data()
.set_booking_form()
.set_page_elements()
.find_page_elements()
.dayHasPrice()
.dayRender()
.dayHover()
......@@ -89,7 +97,7 @@ Drupal.behaviors.abookings = {
break;
}
Drupal.abookings.set_page_elements(context);
Drupal.abookings.find_page_elements(context);
if (calendar.length >= 1) {
set_up_calendar(context);
......@@ -174,7 +182,9 @@ function add_booking_form_submit_handler(context) {
var serialized_form = $(this).serializeArray();
// console.log('serialized_form: ', serialized_form);
Drupal.abookings.create_booking(serialized_form);
var data_object = Drupal.abookings.create_booking(serialized_form);
// console.log('data_object: ', data_object);
save_booking(data_object, 'booking');
});
}
......@@ -413,6 +423,9 @@ function add_booking_data_fetched_listener() {
}
function setup_addons() {}
function get_addons_total_guests() {
var guests = 0;
addon_checkboxes = $('input[name^="field_addons"]:checked');
......@@ -439,11 +452,11 @@ function calculate_max_guests() {
return null;
}
var bookable_max_guests = parseInt(bookable_data['field_max_guests']);
// console.log('bookable_max_guests: ', bookable_max_guests);
console.log('bookable_max_guests: ', bookable_max_guests);
var addons_guests = get_addons_total_guests();
// console.log('addons_guests: ', addons_guests);
console.log('addons_guests: ', addons_guests);
max_guests = bookable_max_guests + addons_guests;
// console.log('max_guests: ', max_guests);
console.log('max_guests: ', max_guests);
var label = num_guests_field.siblings('label');
if (! label.find('span').length) {
......@@ -804,8 +817,7 @@ Drupal.abookings = {
set_page_elements: function(context) {
// console.log('set_page_elements()');
find_page_elements: function(context) {
// console.log('booking_form: ', booking_form);
// Define calendar and booking_form
......@@ -819,28 +831,22 @@ Drupal.abookings = {
if (booking_info_container.length == 0) {
booking_info_container =
$('<div id="booking_info"><div class="message_container"></div></div>')
$('<div id="booking_info"><div class="message_container"></div></div>', context)
.prependTo('body');
}
// console.log('booking_info_container: ', booking_info_container);
}
// console.log('booking_info_container: ', booking_info_container);
// arrival_field = booking_form.find('[name="field_checkin_date"]');
// departure_field = booking_form.find('[name="field_checkout_date"]');
// nights_field = booking_form.find('[name="field_num_nights"]');
// num_guests_field = booking_form.find('input[name="field_num_guests"]');
// base_cost_field = booking_form.find('[name="field_base_cost"]');
bookable_field = booking_form.find('[name="field_bookable_unit"]');
arrival_field = booking_form.find('[name="field_checkin_date[0][value][date]"]');
departure_field = booking_form.find('[name="field_checkout_date[0][value][date]"]');
nights_field = booking_form.find('[name="field_num_nights[0][value]"]');
num_guests_field = booking_form.find('input[name="field_num_guests[0][value]"]');
num_nights_field = booking_form.find('input[name="field_num_nights[0][value]"]');
bookable_field = booking_form.find('input[name="field_bookable_unit"]');
arrival_field = booking_form.find('input[name^="field_checkin_date"]');
departure_field = booking_form.find('input[name^="field_checkout_date"]');
nights_field = booking_form.find('input[name^="field_num_nights"]');
num_guests_field = booking_form.find('input[name^="field_num_guests"]');
num_nights_field = booking_form.find('input[name^="field_num_nights"]');
addons_field = booking_form.find('input[name^="field_addons"]');
base_cost_field = booking_form.find('[name="field_base_cost[0][value]"]');
promo_field = booking_form.find('[name="field_promo_code_provided[0][value]"]');
base_cost_field = booking_form.find('input[name^="field_base_cost"]');
promo_field = booking_form.find('input[name^="field_promo_code_provided"]');
},
......@@ -1111,6 +1117,9 @@ Drupal.abookings = {
// },
/**
* Creates a booking object that can be saved to fullCalendar.
*/
create_booking: function(serialized_form) {
var data_object_raw = {};
$.each(serialized_form, function () {
......@@ -1162,8 +1171,7 @@ Drupal.abookings = {
data_object.field_addons.push(nid);
});
// console.log('data_object: ', data_object);
save_booking(data_object, 'booking');
return data_object;
},
......
......@@ -41,7 +41,7 @@ Drupal.behaviors.booking_stats_page = {
// console.log('drupalSettings: ', drupalSettings);
Drupal.booking_stats_page.build_charts(context, settings);
var bookable = getParameterByName('bookable');
$('select[name="bookable_filter"]').val(bookable);
......@@ -63,7 +63,7 @@ Drupal.booking_stats_page = {
build_charts: function(context, settings) {
// console.log('build_charts()');
var chart_container = $("#bookingCharts");
var chart_container = $("#bookingCharts", context);
var charts = [
'bookings_count',
......
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