Commit b7ae3bf9 authored by droces's avatar droces

Several booking form fixes

parent 3feb9782
......@@ -60,7 +60,11 @@ var calendar,
price_suffix = '',
discount = 0,
is_valid_promo = true,
max_guests = 0;
max_guests = null;
// When calendar is clicked, first click (1) used for check in date,
// second click (2) used for check out date.
var last_calendar_click = null;
var bookable_field,
arrival_field,
......@@ -195,9 +199,14 @@ function add_booking_form_submit_handler(context) {
function add_field_listeners(context) {
// Define field value change listeners
// console.log('add_field_listeners()');
calculate_max_guests();
num_guests_field.change(function() {
// Check that there's bookable data
if (jQuery.isEmptyObject(Drupal.abookings.get_bookable_data())) {
alert('Please select a bookable unit');
return false;
}
var change_okay = check_num_guests();
if (! change_okay) {
return null;
......@@ -248,7 +257,6 @@ function add_field_listeners(context) {
});
addons_field.change(function() {
calculate_max_guests();
check_num_guests();
refresh_main_info();
});
......@@ -266,6 +274,7 @@ function add_field_listeners(context) {
function check_num_guests() {
calculate_max_guests();
var num_guests = parseInt(num_guests_field.val());
// console.log('max_guests: ', max_guests);
......@@ -448,15 +457,17 @@ function get_addons_total_guests() {
function calculate_max_guests() {
var bookable_data = Drupal.abookings.get_bookable_data();
// console.log('bookable_data: ', bookable_data);
if (! bookable_data) {
// throw 'No booking data in 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) {
......@@ -479,22 +490,32 @@ function set_up_calendar() {
// This doesn't work, because days aren't events!
// Drupal.abookings.dayHover(event, jsEvent, view);
},
dayClick: function(date_arrive, jsEvent, view, resourceObj) {
dayClick: function(date_clicked, jsEvent, view, resourceObj) {
var date_arrive,
date_depart;
// Check that there's bookable data
if (jQuery.isEmptyObject(Drupal.abookings.get_bookable_data())) {
alert('Please select a bookable unit');
return null;
}
if(! Drupal.abookings.dayHasPrice(date_arrive)) {
if(! Drupal.abookings.dayHasPrice(date_clicked)) {
alert('Please select a date that has a price');
}
var nights = parseInt(nights_field.val());
// console.log('nights: ', nights);
// If the calendar hasn't been clicked, or the last click was for check out
if (last_calendar_click !== 1) {
date_arrive = date_clicked;
var nights = parseInt(nights_field.val());
var date_depart = moment(date_arrive);
date_depart.add(nights, 'day');
date_depart = moment(date_arrive);
date_depart.add(nights, 'day');
}
else {
date_depart = date_clicked;
date_arrive = moment(arrival_field.val());
num_nights = date_depart.diff(date_arrive, 'days');
}
// If this new event overlaps with any others
var overlap = Drupal.abookings.check_event_overlap(date_arrive, date_depart);
......@@ -515,6 +536,16 @@ function set_up_calendar() {
Drupal.abookings.add_booking('current', booking_data);
refresh_main_info();
if (last_calendar_click == null) {
last_calendar_click = 1;
}
else if (last_calendar_click == 1) {
last_calendar_click = 2;
}
else {
last_calendar_click = 1;
}
}
});
};
......@@ -788,7 +819,7 @@ Drupal.abookings = {
*/
get_bookable_data: function() {
var bookable_nid = Drupal.abookings.get_bookable_nid();
// console.log('bookable_nid: ', bookable_nid);
console.log('bookable_nid: ', bookable_nid);
var active_bookable = null;
$.each(bookable_data['bookables'], function(index, bookable) {
......@@ -838,7 +869,7 @@ Drupal.abookings = {
}
// console.log('booking_info_container: ', booking_info_container);
bookable_field = booking_form.find('input[name="field_bookable_unit"]');
bookable_field = booking_form.find('select[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"]');
......
......@@ -159,9 +159,6 @@ function fe_booking_form_alter(&$form, FormStateInterface $form_state, $form_id)
$form['field_base_cost']['#attributes']['class'][] = 'hidden';
$form['field_num_nights']['#attributes']['class'][] = 'hidden';
$form['field_checkin_date']['#weight'] = -10;
$form['field_checkout_date']['#weight'] = -9;
$form['calendar'] = [
'#prefix' => '<div class="">',
'#suffix' => '</div>',
......@@ -169,9 +166,15 @@ function fe_booking_form_alter(&$form, FormStateInterface $form_state, $form_id)
'calendar' => [
'#markup' => '<div id="calendar"></div>',
],
'#weight' => 1,
'#weight' => 0,
];
$form['field_bookable_unit']['#weight'] = -50;
$form['calendar']['#weight'] = -49;
$form['field_checkin_date']['#weight'] = -48;
$form['field_checkout_date']['#weight'] = -47;
// kint($form, '$form');
$form_items_to_deaccess = [
'title',
'field_booking_status',
......@@ -230,11 +233,13 @@ function fe_booking_form_alter(&$form, FormStateInterface $form_state, $form_id)
}
// Unneeded actions
$form['status']['#access'] = FALSE;
$form['actions']['unpublish']['#access'] = FALSE;
$form['actions']['preview']['#access'] = FALSE;
$form['actions']['delete']['#access'] = FALSE;
unset($form['actions']['publish']['#dropbutton']);
}
// kint($form, '$form');
}
......
......@@ -18,26 +18,11 @@ class BookPageController extends ControllerBase {
* A renderable array of the page content.
*/
public function viewPage() {
// ** DEV ** Call cron functions
// check_provisional_bookings();
// check_confirmed_bookings();
$content = array();
// $content['calendar'] = [
// '#prefix' => '<div class="half-left">',
// '#suffix' => '</div>',
// '#type' => 'markup',
// 'calendar' => [
// '#markup' => '<div id="calendar"></div>',
// ],
// ];
$content['#attached']['library'][] = 'abookings/abookings';
$content['#attached']['library'][] = 'abookings/fullCalendar';
$content['booking_info_container'] = [
'#prefix' => '<div id="booking_info" class="half-right">',
'#suffix' => '</div>',
......@@ -120,10 +105,11 @@ function get_booking_node_form() {
->getStorage('node')
->create($new_booking_values);
$form_oject = \Drupal::entityTypeManager()
$form_object = \Drupal::entityTypeManager()
->getFormObject('node', 'default')
->setEntity($new_booking);
$booking_node_form = \Drupal::formBuilder()->getForm($form_oject, '/book');
// kint($booking_node_form, '$booking_node_form');
// kint($form_object, '$form_object');
$booking_node_form = \Drupal::formBuilder()->getForm($form_object, '/book');
// kint(array_keys($booking_node_form), '$booking_node_form');
return $booking_node_form;
}
\ No newline at end of file
}
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