PluginProbe
Booking Calendar / 11.8.2
Booking Calendar v11.8.2
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 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / page-setup / _src / setup_show.js

setup_show.js in Booking Calendar 11.8.2, at includes/page-setup/_src/setup_show.js

414 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 /**
4 * Parameters usually defined in Ajax Response or Front-End for == _wpbc_settings.get_all_params__setup_wizard():
5 *
6 * In Front-End side as JavaScript :: wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step': 'date_availability', 'do_action': 'none', 'ui_clicked_element_id': 'btn__toolbar__buttons_prior' } );
7 *
8 * After Ajax response in setup_ajax.js as :: _wpbc_settings.set_params_arr__setup_wizard( response_data[ 'ajx_data' ] );
9 *
10 */
11
12 // =====================================================================================================================
13 // == Set Request for Ajax ==
14 // =====================================================================================================================
15 /**
16 * Send Ajax Request after Updating Request Parameters
17 *
18 * @param params_arr
19 *
20 * Example 1:
21 *
22 * wpbc_ajx__setup_wizard_page__send_request_with_params( {
23 * 'page_num': page_number
24 * } );
25 * Example 2:
26 *
27 * wpbc_ajx__setup_wizard_page__send_request_with_params( {
28 * 'current_step': '{{data.steps[ data.current_step ].prior}}',
29 * 'do_action': 'none',
30 * 'ui_clicked_element_id': 'btn__toolbar__buttons_prior'
31 * } );
32 *
33 */
34 function wpbc_ajx__setup_wizard_page__send_request_with_params ( params_arr ){
35
36 // Define Params Array to Request
37 _wpbc_settings.set_params_arr__setup_wizard( params_arr );
38
39 // Send Ajax Request
40 wpbc_ajx__setup_wizard_page__send_request();
41 }
42 // Example 1: wpbc_ajx__setup_wizard_page__send_request_with_params( { 'page_num': page_number } );
43 // Example 2: wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step': 'date_availability', 'do_action': 'none', 'ui_clicked_element_id': 'btn__toolbar__buttons_prior' } );
44
45
46 // =====================================================================================================================
47 // == Show / Hide Content ==
48 // =====================================================================================================================
49 /**
50 * Show Main Content ... _wpbc_settings.get_all_params__setup_wizard() - must be defined!
51 */
52 function wpbc_setup_wizard_page__show_content() {
53
54 var wpbc_template__stp_wiz__main_content = wp.template( 'wpbc_template__stp_wiz__main_content' );
55
56 jQuery( _wpbc_settings.get_param__other( 'container__main_content' ) ).html( wpbc_template__stp_wiz__main_content( _wpbc_settings.get_all_params__setup_wizard() ) );
57
58 // Hide 'Processing' Notice
59 jQuery( '.wpbc_processing.wpbc_spin').parent().parent().parent().parent( '[id^="wpbc_notice_"]' ).hide();
60
61 //var header_menu_text = ' Step ' + wpbc_setup_wizard_page__get_actual_step_number() + ' / ' + wpbc_setup_wizard_page__get_steps_count();
62 //jQuery( '.wpbc_header_menu_tabs .nav-tab-active .nav-tab-text').html( header_menu_text );
63 //
64 //jQuery( '.wpbc_navigation_menu_left_item ' ).removeClass( 'wpbc_active' );
65 //jQuery( '#' + _wpbc_settings.get_param__setup_wizard( 'current_step' ) ).addClass( 'wpbc_active' );
66
67 // Recheck Full Screen mode, by removing top tab
68 wpbc_check_full_screen_mode();
69
70 // Scroll to top
71 // wpbc_scroll_to( '.wpbc_page_top__header_tabs' );
72 wpbc_scroll_to( '.wpbc__container_place__steps_for_timeline' );
73 }
74
75 /**
76 * Hide Main Content
77 */
78 function wpbc_setup_wizard_page__hide_content(){
79
80 jQuery( _wpbc_settings.get_param__other( 'container__main_content' ) ).html( '' );
81 }
82
83
84 /**
85 * Update Plugin menu progress -> Progress line at "Left Main Menu"
86 */
87 function wpbc_setup_wizard_page__update_plugin_menu_progress( plugin_menu__setup_progress__html ){
88 if ( 'undefined' != typeof (plugin_menu__setup_progress__html) ){
89 jQuery( '.setup_wizard_page_container' ).parent().html( plugin_menu__setup_progress__html );
90 }
91 }
92
93 // ---------------------------------------------------------------------------------------------------------------------
94 // == Steps Number Functions ==
95 // Gets data in _wpbc_settings.get_all_params__setup_wizard().steps
96 // which defined in setup_ajax.php Ajax
97 // as $data_arr ['steps'] = new WPBC_SETUP_WIZARD_STEPS(); $this->get_steps_arr(); from setup_steps.php structure.
98 // ---------------------------------------------------------------------------------------------------------------------
99
100 function wpbc_setup_wizard_page__get_steps_count() {
101
102 var params_arr = _wpbc_settings.get_all_params__setup_wizard().steps
103 var steps_count = 0
104 _.each( params_arr, function ( p_val, p_key, p_data ) {
105 steps_count++;
106 } );
107 return steps_count;
108 }
109
110 function wpbc_setup_wizard_page__get_actual_step_number() {
111
112 var setup_params = _wpbc_settings.get_all_params__setup_wizard();
113 var params_arr = setup_params.steps;
114 var current_step = setup_params.current_step;
115 var step_number = 1;
116 var found_step = false;
117
118 _.each( params_arr, function ( p_val, p_key, p_data ) {
119 if ( p_key === current_step ) {
120 found_step = true;
121 return false;
122 }
123 step_number++;
124 } );
125
126 return found_step ? step_number : 1;
127 }
128
129 function wpbc_setup_wizard_page__update_steps_status( steps_is_done_arr ){
130
131 var params_arr = _wpbc_settings.get_all_params__setup_wizard().steps
132
133 _.each( steps_is_done_arr, function ( p_val, p_key, p_data ) {
134 if ( "undefined" !== typeof ( params_arr[ p_key ] ) ) {
135 params_arr[ p_key ].is_done = (true === steps_is_done_arr[ p_key ]);
136 }
137 } );
138
139 return params_arr;
140
141 }
142
143
144 function wpbc_setup_wizard_page__is_all_steps_completed(){
145
146 var params_arr = _wpbc_settings.get_all_params__setup_wizard().steps
147 var status = true;
148
149 _.each( params_arr, function ( p_val, p_key, p_data ) {
150 if ( ! p_val.is_done ){
151 status = false;
152 }
153 } );
154
155 return status;
156 }
157
158 /**
159 * Show the configuration controls belonging to the selected booking behavior.
160 *
161 * @return {void}
162 */
163 function wpbc_setup_wizard_page__refresh_booking_type_details() {
164
165 var booking_type = jQuery( '[name="wpbc_swp_booking_types"]:checked' ).val() || '';
166 var fixed_appointment_type = jQuery( '[name="wpbc_swp_booking_mode"]:checked' )
167 .closest( '.wpbc_setup_mode_choice' )
168 .attr( 'data-wpbc-setup-fixed-appointment-type' ) || '';
169 var is_fixed_appointment_mode = 'durationtime' === fixed_appointment_type;
170 var $canonical_times_picker = jQuery( '[name="wpbc_swp_booking_timeslot_picker"]' );
171 var $appointment_times_picker = jQuery( '[name="wpbc_swp_booking_timeslot_picker_appointment"]' );
172
173 jQuery( '.wpbc_in_radio_container_selectbox' ).hide();
174 jQuery( '.wpbc_setup_appointment_mode_configuration' ).hide();
175
176 if ( is_fixed_appointment_mode ) {
177 if ( $canonical_times_picker.length && $appointment_times_picker.length ) {
178 $appointment_times_picker.val( $canonical_times_picker.val() );
179 }
180 jQuery( '.wpbc_setup_appointment_mode_configuration' ).show();
181 } else if ( 'time_slots_appointments' === booking_type ) {
182 jQuery( '.wpbc_ui_booking_timeslot_picker__get_on_off__div' ).show();
183 } else if ( 'changeover_multi_dates_bookings' === booking_type ) {
184 jQuery( '.wpbc_ui_booking_change_over__get_on_off__div' ).show();
185 }
186 }
187
188 /**
189 * Apply the selected presentation mode to the Step 4 behavior choices.
190 *
191 * The presentation mode and booking behavior are intentionally independent
192 * values. This function limits the visible behaviors to valid combinations
193 * without coupling mode switching to any QuickStart content mutation.
194 *
195 * @return {void}
196 */
197 function wpbc_setup_wizard_page__refresh_booking_mode_choices() {
198
199 var $mode_input = jQuery( '[name="wpbc_swp_booking_mode"]:checked' ).first();
200 var $mode_choice;
201 var allowed_booking_types;
202 var default_booking_type;
203 var fixed_appointment_type;
204 var is_fixed_appointment_mode;
205 var $selected_booking_type;
206
207 if ( ! $mode_input.length ) {
208 $mode_input = jQuery( '[name="wpbc_swp_booking_mode"]' ).first().prop( 'checked', true );
209 }
210
211 $mode_choice = $mode_input.closest( '.wpbc_setup_mode_choice' );
212 if ( ! $mode_choice.length ) {
213 wpbc_setup_wizard_page__refresh_booking_type_details();
214 return;
215 }
216
217 allowed_booking_types = String( $mode_choice.attr( 'data-wpbc-setup-booking-types' ) || '' ).split( ',' );
218 default_booking_type = String( $mode_choice.attr( 'data-wpbc-setup-default-booking-type' ) || '' );
219 fixed_appointment_type = String( $mode_choice.attr( 'data-wpbc-setup-fixed-appointment-type' ) || '' );
220 is_fixed_appointment_mode = 'durationtime' === fixed_appointment_type;
221
222 jQuery( '.wpbc_setup_preferences_heading' ).text( $mode_choice.attr( 'data-wpbc-setup-preference-title' ) || '' );
223 jQuery( '.wpbc_setup_booking_type_choice' ).each( function() {
224 var booking_type = String( jQuery( this ).attr( 'data-wpbc-setup-booking-type' ) || '' );
225 jQuery( this ).toggle( -1 !== jQuery.inArray( booking_type, allowed_booking_types ) );
226 } );
227
228 $selected_booking_type = jQuery( '[name="wpbc_swp_booking_types"]:checked' );
229 if (
230 ! $selected_booking_type.length
231 || -1 === jQuery.inArray( String( $selected_booking_type.val() || '' ), allowed_booking_types )
232 || $selected_booking_type.is( ':disabled' )
233 ) {
234 $selected_booking_type = jQuery( '[name="wpbc_swp_booking_types"][value="' + default_booking_type + '"]:not(:disabled)' ).first();
235 if ( ! $selected_booking_type.length ) {
236 $selected_booking_type = jQuery( '.wpbc_setup_booking_type_choice:visible [name="wpbc_swp_booking_types"]:not(:disabled)' ).first();
237 }
238 $selected_booking_type.prop( 'checked', true );
239 }
240
241 if ( is_fixed_appointment_mode ) {
242 jQuery( '[name="wpbc_swp_booking_appointments_type"][value="' + fixed_appointment_type + '"]' ).prop( 'checked', true );
243 }
244
245 jQuery( '.wpbc_setup_preferences_heading_row' ).toggle( ! is_fixed_appointment_mode );
246 jQuery( '.wpbc_setup_booking_type_choices' ).toggle( ! is_fixed_appointment_mode );
247
248 jQuery( '[name="wpbc_swp_booking_mode"], [name="wpbc_swp_booking_types"]' ).each( function() {
249 wpbc_ui_el__radio_container_selection( this );
250 } );
251
252 wpbc_setup_wizard_page__refresh_booking_type_details();
253 }
254
255
256 /**
257 * Define UI hooks for elements, after showing in Ajax.
258 *
259 * Because each time, when we show content in Ajax, all Hooks needs re-defined.
260 */
261 function wpbc_setup_wizard_page__define_ui_hooks(){
262
263 // -----------------------------------------------------------------------------------------------------------------
264 // Tooltips
265 if ( 'function' === typeof( wpbc_define_tippy_tooltips ) ) {
266 var parent_css_class = _wpbc_settings.get_param__other( 'container__main_content' ) + ' '
267 wpbc_define_tippy_tooltips( parent_css_class );
268 }
269
270 // -----------------------------------------------------------------------------------------------------------------
271 // Change Radio Containers
272 jQuery( '.wpbc_ui_radio_choice_input' ).on( 'change', function( event ){
273
274 wpbc_ui_el__radio_container_selection( this );
275
276 //wpbc_ajx__setup_wizard_page__send_request_with_params( { 'page_items_count': jQuery( this ).val(), 'page_num': 1 } );
277 } );
278
279 jQuery( '.wpbc_ui_radio_choice_input' ).each(function (index ){
280 wpbc_ui_el__radio_container_selection( this );
281 });
282
283 // Define ability to click on Radio Containers (not only radio-buttons)
284 jQuery( '.wpbc_ui_radio_container' ).on( 'click', function( event ){
285 wpbc_ui_el__radio_container_click( this );
286 } );
287
288 jQuery( '[name="wpbc_swp_booking_mode"]' ).on( 'change', function() {
289 wpbc_setup_wizard_page__refresh_booking_mode_choices();
290 } );
291
292 jQuery( '[name="wpbc_swp_booking_types"]' ).on( 'change', function() {
293 wpbc_setup_wizard_page__refresh_booking_type_details();
294 } );
295
296 // Save the Appointment-only presentation control through the historical canonical field.
297 jQuery( '[name="wpbc_swp_booking_timeslot_picker_appointment"]' ).on( 'change', function() {
298 jQuery( '[name="wpbc_swp_booking_timeslot_picker"]' ).val( jQuery( this ).val() );
299 } );
300
301 wpbc_setup_wizard_page__refresh_booking_mode_choices();
302
303 // -----------------------------------------------------------------------------------------------------------------
304
305
306 }
307
308
309 // ---------------------------------------------------------------------------------------------------------------------
310 // == M e s s a g e ==
311 // ---------------------------------------------------------------------------------------------------------------------
312
313 /**
314 * Show message in content
315 *
316 * @param message Message HTML
317 * @param params = {
318 * ['type'] 'warning' | 'info' | 'error' | 'success' default: 'warning'
319 * ['container'] '.wpbc_ajx_cstm__section_left' default: _wpbc_settings.get_param__other( 'container__main_content')
320 * ['is_append'] true | false default: true
321 * }
322 * Example:
323 * var html_id = wpbc_setup_wizard_page__show_message( 'You can test days selection in calendar', 'info', '.wpbc_ajx_cstm__section_left', true );
324 *
325 *
326 * @returns string - HTML ID
327 */
328 function wpbc_setup_wizard_page__show_message( message, params = {} ){
329
330 var params_default = {
331 'type' : 'warning',
332 'container': _wpbc_settings.get_param__other( 'container__main_content'),
333 'is_append': true,
334 'style' : 'text-align:left;',
335 'delay' : 0
336 };
337 _.each( params, function ( p_val, p_key, p_data ){
338 params_default[ p_key ] = p_val;
339 } );
340 params = params_default;
341
342 var unique_div_id = new Date();
343 unique_div_id = 'wpbc_notice_' + unique_div_id.getTime();
344
345 var alert_class = 'notice ';
346 if ( params['type'] == 'error' ){
347 alert_class += 'notice-error ';
348 message = '<i style="margin-right: 0.5em;color: #d63638;" class="menu_icon icon-1x wpbc_icn_report_gmailerrorred"></i>' + message;
349 }
350 if ( params['type'] == 'warning' ){
351 alert_class += 'notice-warning ';
352 message = '<i style="margin-right: 0.5em;color: #e9aa04;" class="menu_icon icon-1x wpbc_icn_warning"></i>' + message;
353 }
354 if ( params['type'] == 'info' ){
355 alert_class += 'notice-info ';
356 }
357 if ( params['type'] == 'success' ){
358 alert_class += 'notice-info alert-success updated ';
359 message = '<i style="margin-right: 0.5em;color: #64aa45;" class="menu_icon icon-1x wpbc_icn_done_outline"></i>' + message;
360 }
361
362 message = '<div id="' + unique_div_id + '" class="wpbc-settings-notice ' + alert_class + '" style="' + params[ 'style' ] + '">' + message + '</div>';
363
364 if ( params['is_append'] ){
365 jQuery( params['container'] ).append( message );
366 } else {
367 jQuery( params['container'] ).html( message );
368 }
369
370 params['delay'] = parseInt( params['delay'] );
371 if ( params['delay'] > 0 ){
372
373 var closed_timer = setTimeout( function (){
374 jQuery( '#' + unique_div_id ).fadeOut( 1500 );
375 }
376 , params[ 'delay' ]
377 );
378 }
379 return unique_div_id;
380 }
381
382
383 // ---------------------------------------------------------------------------------------------------------------------
384 // == Support Functions - Spin Icon in Top Bar Menu -> ' Initial Setup' ==
385 // ---------------------------------------------------------------------------------------------------------------------
386
387 /**
388 * Spin button in Filter toolbar - Start
389 */
390 function wpbc_setup_wizard_page_reload_button__spin_start(){
391 return false; // Currently disabled, maybe activate it for some other element.
392 jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin').removeClass( 'wpbc_animation_pause' );
393 }
394
395 /**
396 * Spin button in Filter toolbar - Pause
397 */
398 function wpbc_setup_wizard_page_reload_button__spin_pause(){
399 jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin' ).addClass( 'wpbc_animation_pause' );
400 }
401
402 /**
403 * Spin button in Filter toolbar - is Spinning ?
404 *
405 * @returns {boolean}
406 */
407 function wpbc_setup_wizard_page_reload_button__is_spin(){
408 if ( jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin' ).hasClass( 'wpbc_animation_pause' ) ){
409 return true;
410 } else {
411 return false;
412 }
413 }
414