PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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 10.11 10.11.2 All 203 releases
booking / includes / page-setup / _src / setup_ajax.js

setup_ajax.js in Booking Calendar 11.1, at includes/page-setup/_src/setup_ajax.js

144 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 // =====================================================================================================================
3 // == Ajax ==
4 // =====================================================================================================================
5
6 function wpbc_ajx__setup_wizard_page__send_request(){
7
8 console.groupCollapsed( 'WPBC_AJX_SETUP_WIZARD_PAGE' ); console.log( ' == Before Ajax Send - search_get_all_params() == ' , _wpbc_settings.get_all_params__setup_wizard() );
9
10 // It can start 'icon spinning' on top menu bar at 'active menu item'.
11 wpbc_setup_wizard_page_reload_button__spin_start();
12
13 // Clear some parameters, which can make issue with blocking requests.
14 wpbc_ajx__setup_wizard_page__do_request_clean();
15
16 // Start Ajax
17 jQuery.post( wpbc_url_ajax,
18 {
19 action : 'WPBC_AJX_SETUP_WIZARD_PAGE',
20 wpbc_ajx_user_id: _wpbc_settings.get_param__secure( 'user_id' ),
21 nonce : _wpbc_settings.get_param__secure( 'nonce' ),
22 wpbc_ajx_locale : _wpbc_settings.get_param__secure( 'locale' ),
23
24 all_ajx_params : _wpbc_settings.get_all_params__setup_wizard()
25 },
26 /**
27 * S u c c e s s
28 *
29 * @param response_data - its object returned from Ajax - class-live-searcg.php
30 * @param textStatus - 'success'
31 * @param jqXHR - Object
32 */
33 function ( response_data, textStatus, jqXHR ) {
34
35 console.log( ' == Response WPBC_AJX_SETUP_WIZARD_PAGE == ', response_data ); console.groupEnd();
36
37 // -------------------------------------------------------------------------------------------------
38 // Probably Error
39 // -------------------------------------------------------------------------------------------------
40 if ( (typeof response_data !== 'object') || (response_data === null) ){
41
42 wpbc_setup_wizard_page__hide_content();
43 wpbc_setup_wizard_page__show_message( response_data );
44
45 return;
46 }
47
48 // -------------------------------------------------------------------------------------------------
49 // Reset Done - Reload page, after filter toolbar has been reset
50 // -------------------------------------------------------------------------------------------------
51 if ( ( undefined != response_data[ 'ajx_cleaned_params' ] ) && ( 'reset_done' === response_data[ 'ajx_cleaned_params' ][ 'do_action' ] ) ){
52 location.reload();
53 return;
54 }
55
56 // Define Front-End side JS vars from Ajax
57 _wpbc_settings.set_params_arr__setup_wizard( response_data[ 'ajx_data' ] );
58
59 // Update Menu statuses: Top Black UI and in Left Main menu
60 wpbc_setup_wizard_page__update_steps_status( response_data[ 'ajx_data' ]['steps_is_done'] );
61
62 if ( wpbc_setup_wizard_page__is_all_steps_completed() ) {
63 if (undefined != response_data[ 'ajx_data' ][ 'redirect_url' ]){
64 window.location.href = response_data[ 'ajx_data' ][ 'redirect_url' ];
65 return;
66 }
67 }
68
69 // -------------------------------------------------------------------------------------------------
70 // Auto redirect to new BFB builder - templates section.
71 // -------------------------------------------------------------------------------------------------
72 if ( ( undefined != response_data[ 'ajx_cleaned_params' ] ) && ( 'auto_open_template' === response_data[ 'ajx_cleaned_params' ][ 'do_action' ] ) ){
73 if (undefined != response_data[ 'ajx_data' ][ 'redirect_url' ]){
74 window.location.href = response_data[ 'ajx_data' ][ 'redirect_url' ];
75 return;
76 }
77 }
78
79
80 // -> Progress line at "Left Main Menu"
81 wpbc_setup_wizard_page__update_plugin_menu_progress( response_data[ 'ajx_data' ]['plugin_menu__setup_progress'] );
82
83 // -------------------------------------------------------------------------------------------------
84 // Show Main Content
85 // -------------------------------------------------------------------------------------------------
86 wpbc_setup_wizard_page__show_content();
87
88 // -------------------------------------------------------------------------------------------------
89 // Redefine Hooks, because we show new DOM elements
90 // -------------------------------------------------------------------------------------------------
91 wpbc_setup_wizard_page__define_ui_hooks();
92
93 // Show Messages
94 if ( '' !== response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ){
95 wpbc_admin_show_message(
96 response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" )
97 , ( '1' == response_data[ 'ajx_data' ][ 'ajx_after_action_result' ] ) ? 'success' : 'error'
98 , 10000
99 );
100 }
101
102 // It can STOP 'icon spinning' on top menu bar at 'active menu item'
103 wpbc_setup_wizard_page_reload_button__spin_pause();
104
105 // Remove spin from "button with icon", that was clicked and Enable this button.
106 wpbc_button__remove_spin( response_data[ 'ajx_cleaned_params' ][ 'ui_clicked_element_id' ] )
107
108 jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page
109 }
110 ).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
111
112 var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ;
113 if ( jqXHR.status ){
114 error_message += ' (<b>' + jqXHR.status + '</b>)';
115 if (403 == jqXHR.status ){
116 error_message += ' Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.';
117 }
118 }
119 if ( jqXHR.responseText ){
120 error_message += ' ' + jqXHR.responseText;
121 }
122 error_message = error_message.replace( /\n/g, "<br />" );
123
124 // Hide Content
125 wpbc_setup_wizard_page__hide_content();
126
127 // Show Error Message
128 wpbc_setup_wizard_page__show_message( error_message );
129 })
130 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
131 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
132 ; // End Ajax
133
134 }
135
136
137 /**
138 * Clean some parameters, does not required for request
139 */
140 function wpbc_ajx__setup_wizard_page__do_request_clean() {
141 // We donot require the 'calendar_force_load' parameter with all html and scripts content at server side. This content generated at server side.
142 // It is also can be the reason of blocking request, because of script tags.
143 _wpbc_settings.set_param__setup_wizard('calendar_force_load', '');
144 }