PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
← All changes | js/wpbc_times.js +119 -13 10.15.7 → 11.9 View file →
@@ -1,7 +1,79 @@
1 1 var start_time_checking_index;
2 2
3 3 /**
4 + * Check if the date has only Working Time limits, without real bookings or manually blocked time slots.
5 + *
6 + * Working Time intervals still have to stay in the booking data for validation and tooltips,
7 + * but they should not produce the small dots inside calendar day cells.
8 + *
9 + * @param {Object} date_bookings_obj
10 + * @param {Array} child_resources_arr
11 + * @returns {boolean}
12 + */
13 +function wpbc_is_date_has_only_working_time_limits_for_dots( date_bookings_obj, child_resources_arr ) {
14 +
15 + var has_working_time_limits = false;
16 + var has_real_time_limits = false;
17 + var resource_day_obj;
18 + var time_details_obj;
19 + var time_details;
20 + var source_type;
21 +
22 + if ( ( ! date_bookings_obj ) || ( null === child_resources_arr ) ) {
23 + return false;
24 + }
25 +
26 + if (
27 + ( date_bookings_obj[ 'summary' ] )
28 + && ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ] )
29 + && ( '' !== date_bookings_obj[ 'summary' ][ 'status_for_bookings' ] )
30 + ) {
31 + return false;
32 + }
33 +
34 + for ( var i = 0; i < child_resources_arr.length; i++ ) {
35 +
36 + resource_day_obj = date_bookings_obj[ child_resources_arr[ i ] ];
37 +
38 + if ( ! resource_day_obj ) {
39 + continue;
40 + }
41 +
42 + time_details_obj = resource_day_obj[ '__booked__times__details' ];
43 +
44 + if ( ! time_details_obj ) {
45 + if (
46 + ( resource_day_obj.booked_time_slots )
47 + && ( resource_day_obj.booked_time_slots.merged_seconds )
48 + && ( resource_day_obj.booked_time_slots.merged_seconds.length > 0 )
49 + ) {
50 + has_real_time_limits = true;
51 + }
52 + continue;
53 + }
54 +
55 + for ( var time_key in time_details_obj ) {
56 +
57 + if ( ! time_details_obj.hasOwnProperty( time_key ) ) {
58 + continue;
59 + }
60 +
61 + time_details = time_details_obj[ time_key ];
62 + source_type = ( time_details && ( 'undefined' !== typeof( time_details[ 'source_type' ] ) ) ) ? time_details[ 'source_type' ] : 'booking';
63 +
64 + if ( 'working_time' === source_type ) {
65 + has_working_time_limits = true;
66 + } else {
67 + has_real_time_limits = true;
68 + }
69 + }
70 + }
71 +
72 + return ( has_working_time_limits && ! has_real_time_limits );
73 +}
74 +
75 +/**
4 76 * Get dots for partially booked dates.
5 77 * For parent booking resources with specific capacity,
6 78 * System do not show partially booked dates, if at least one child booking resource fully available
7 79 * Otherwise it show maximum number of time-slot in one specific child booking resource
@@ -24,9 +96,14 @@
24 96 var child_resources_arr = wpbc_clone_obj(_wpbc.booking__get_param_value(resource_id, 'resources_id_arr__in_dates'));
25 97
26 98 // '2023-08-21'
27 99 var sql_date = wpbc__get__sql_class_date(new Date(my_thisDateTime));
100 + var date_bookings_obj = _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date);
28 101
102 + if ( wpbc_is_date_has_only_working_time_limits_for_dots( date_bookings_obj, child_resources_arr ) ) {
103 + return '';
104 + }
105 +
29 106 var child_resource_id;
30 107 var merged_seconds;
31 108 var dots_count = 0;
32 109
@@ -38,10 +115,10 @@
38 115
39 116 // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_seconds = [ "07:00:11 - 07:30:02", "10:00:11 - 00:00:00" ]
40 117 // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_seconds = [ [ 25211, 27002 ], [ 36011, 86400 ] ]
41 118
42 - if (false !== _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)) {
43 - merged_seconds = _wpbc.bookings_in_calendar__get_for_date(resource_id, sql_date)[child_resource_id].booked_time_slots.merged_seconds; // [ [ 25211, 27002 ], [ 36011, 86400 ] ]
119 + if (false !== date_bookings_obj) {
120 + merged_seconds = date_bookings_obj[child_resource_id].booked_time_slots.merged_seconds; // [ [ 25211, 27002 ], [ 36011, 86400 ] ]
44 121 } else {
45 122 merged_seconds = [];
46 123 }
47 124
@@ -219,9 +296,21 @@
219 296
220 297 return false;
221 298 }
222 299
300 +function wpbc_is_change_over_enabled_for_resource( resource_id ) {
223 301
302 + if ( ( 'undefined' !== typeof resource_id ) && ( null !== resource_id ) ) {
303 + var resource_change_over = _wpbc.calendar__get_param_value( resource_id, 'is_enabled_change_over' );
304 + if ( '' !== resource_change_over ) {
305 + return ( true === resource_change_over ) || ( 'true' === resource_change_over );
306 + }
307 + }
308 +
309 + return true === _wpbc.get_other_param( 'is_enabled_change_over' );
310 +}
311 +
312 +
224 313 /**
225 314 * Check if the selected date/time is already in the past compared to "today_arr".
226 315 *
227 316 * Behavior notes:
@@ -233,12 +322,25 @@
233 322 * @param {string} myTime Time string in "HH:MM" format.
234 323 * @param {Array<Array<string|number>>} sort_date_array Array of date arrays; first element is used as date to check.
235 324 * @returns {boolean} True if selected date/time is in the past, otherwise false.
236 325 */
237 -function wpbc_is_time_in_the_past_for_today(myTime, sort_date_array) {
326 +function wpbc_is_time_in_the_past_for_today(myTime, sort_date_array, resource_id) {
238 327
328 + var allow_past_context = _wpbc.get_other_param( 'this_page_allow_past' );
329 + var edit_booking_hash_context = _wpbc.get_other_param( 'this_page_booking_hash' );
330 + if (
331 + ( '1' === String( allow_past_context ) )
332 + || ( 1 === allow_past_context )
333 + || ( true === allow_past_context )
334 + || ( '' !== String( edit_booking_hash_context || '' ) )
335 + || ( location.href.indexOf( 'booking_hash' ) > -1 )
336 + || ( location.href.indexOf( 'allow_past' ) > -1 )
337 + ) {
338 + return false;
339 + }
340 +
239 341 // FixIn: 10.14.10.2.
240 - if ( true === _wpbc.get_other_param( 'is_enabled_change_over' ) ) {
342 + if ( true === wpbc_is_change_over_enabled_for_resource( resource_id ) ) {
241 343 return false;
242 344 }
243 345 var date_to_check = sort_date_array[0];
244 346 if ( parseInt( date_to_check[0] ) < parseInt( _wpbc.get_other_param( 'today_arr' )[0] ) ) {
@@ -339,9 +441,9 @@
339 441 //PS: This function from personal.js
340 442 function wpbc_is_this_time_selection_not_available( resource_id, form_elements ){
341 443
342 444 // Skip this checking if we are in the Admin panel at Add booking page
343 - if ( location.href.indexOf( 'page=wpbc-new' ) > 0 ) {
445 + if ( ( location.href.indexOf( 'page=wpbc' ) > 0 ) && ( location.href.indexOf( 'tab=add-booking' ) > 0 ) ) {
344 446 return false;
345 447 }
346 448
347 449 var count = form_elements.length;
@@ -365,8 +467,12 @@
365 467 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ){ // FixIn: 7.1.2.14.
366 468 continue;
367 469 }
368 470
471 + if ( '1' === String( jQuery( element ).attr( 'data-wpbc-booking-submit-ignore' ) || '' ) ) {
472 + continue;
473 + }
474 +
369 475 if (
370 476 ( element.name != undefined )
371 477 && ( element.name.indexOf( 'hint' ) === -1 ) //FixIn: 9.5.5.2 // FixIn: 9.6.3.9.
372 478 ){
@@ -372,9 +478,9 @@
372 478 ){
373 479 var my_element = element.name; //.toString();
374 480 if ( my_element.indexOf( 'rangetime' ) !== -1 ){ // Range Time
375 481 if ( element.value == '' ){ //FixIn: 7.0.Beta.19
376 - var notice_message_id = wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required' ) );
482 + var notice_message_id = wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required' ), 'text' );
377 483 return true;
378 484 }
379 485 var my_rangetime = element.value.split( '-' );
380 486 if ( my_rangetime.length > 1 ){
@@ -453,15 +559,15 @@
453 559 }
454 560
455 561 if ( valid_time !== true ){
456 562 //return false; // do not show warning for setting pending days selectable, if making booking for time-slot // FixIn: 7.0.1.23.
457 - if ( (_wpbc.get_other_param( 'is_enabled_change_over' )) && (element_start !== false) && (element_end !== false) ){ // FixIn: 6.1.1.1.
458 - wpbc_front_end__show_message__warning_under_element( '#date_booking' + resource_id, _wpbc.get_message( 'message_check_no_selected_dates' ) );
563 + if ( ( wpbc_is_change_over_enabled_for_resource( resource_id ) ) && (element_start !== false) && (element_end !== false) ){ // FixIn: 6.1.1.1.
564 + wpbc_front_end__show_message__warning( '#booking_form_div' + resource_id + ' .bk_calendar_frame', _wpbc.get_message( 'message_check_no_selected_dates' ), 'text' );
459 565 }
460 - if ( element_rangetime !== false ){ wpbc_front_end__show_message__warning_under_element( element_rangetime, _wpbc.get_message( 'message_error_range_time' ) ); }
461 - if ( element_duration !== false ){ wpbc_front_end__show_message__warning_under_element( element_duration, _wpbc.get_message( 'message_error_duration_time' ) ); }
462 - if ( element_start !== false ){ wpbc_front_end__show_message__warning_under_element( element_start, _wpbc.get_message( 'message_error_start_time' ) ); }
463 - if ( element_end !== false ){ wpbc_front_end__show_message__warning_under_element( element_end, _wpbc.get_message( 'message_error_end_time' ) ); }
566 + if ( element_rangetime !== false ){ wpbc_front_end__show_message__warning_under_element( element_rangetime, _wpbc.get_message( 'message_error_range_time' ), 'text' ); }
567 + if ( element_duration !== false ){ wpbc_front_end__show_message__warning_under_element( element_duration, _wpbc.get_message( 'message_error_duration_time' ), 'text' ); }
568 + if ( element_start !== false ){ wpbc_front_end__show_message__warning_under_element( element_start, _wpbc.get_message( 'message_error_start_time' ), 'text' ); }
569 + if ( element_end !== false ){ wpbc_front_end__show_message__warning_under_element( element_end, _wpbc.get_message( 'message_error_end_time' ), 'text' ); }
464 570
465 571 return true;
466 572
467 573 } else {
@@ -538,9 +644,9 @@
538 644 sort_date_array[ i ] = [ parseInt( sort_date_array[ i ][ 0 ] * 1 ), parseInt( sort_date_array[ i ][ 1 ] * 1 ), parseInt( sort_date_array[ i ][ 2 ] * 1 ) ]; // [2009,7,1],...
539 645 }
540 646
541 647 if ( is_start_time ) {
542 - if ( wpbc_is_time_in_the_past_for_today( mytime, sort_date_array ) ) {
648 + if ( wpbc_is_time_in_the_past_for_today( mytime, sort_date_array, bk_type ) ) {
543 649 return false;
544 650 }
545 651 }
546 652