PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
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 10.10.2, at includes/page-setup/_src/setup_ajax.js

134 lines 6.1 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 // -> Progress line at "Left Main Menu"
71 wpbc_setup_wizard_page__update_plugin_menu_progress( response_data[ 'ajx_data' ]['plugin_menu__setup_progress'] );
72
73 // -------------------------------------------------------------------------------------------------
74 // Show Main Content
75 // -------------------------------------------------------------------------------------------------
76 wpbc_setup_wizard_page__show_content();
77
78 // -------------------------------------------------------------------------------------------------
79 // Redefine Hooks, because we show new DOM elements
80 // -------------------------------------------------------------------------------------------------
81 wpbc_setup_wizard_page__define_ui_hooks();
82
83 // Show Messages
84 if ( '' !== response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ){
85 wpbc_admin_show_message(
86 response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" )
87 , ( '1' == response_data[ 'ajx_data' ][ 'ajx_after_action_result' ] ) ? 'success' : 'error'
88 , 10000
89 );
90 }
91
92 // It can STOP 'icon spinning' on top menu bar at 'active menu item'
93 wpbc_setup_wizard_page_reload_button__spin_pause();
94
95 // Remove spin from "button with icon", that was clicked and Enable this button.
96 wpbc_button__remove_spin( response_data[ 'ajx_cleaned_params' ][ 'ui_clicked_element_id' ] )
97
98 jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page
99 }
100 ).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
101
102 var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ;
103 if ( jqXHR.status ){
104 error_message += ' (<b>' + jqXHR.status + '</b>)';
105 if (403 == jqXHR.status ){
106 error_message += ' Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.';
107 }
108 }
109 if ( jqXHR.responseText ){
110 error_message += ' ' + jqXHR.responseText;
111 }
112 error_message = error_message.replace( /\n/g, "<br />" );
113
114 // Hide Content
115 wpbc_setup_wizard_page__hide_content();
116
117 // Show Error Message
118 wpbc_setup_wizard_page__show_message( error_message );
119 })
120 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
121 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
122 ; // End Ajax
123
124 }
125
126
127 /**
128 * Clean some parameters, does not required for request
129 */
130 function wpbc_ajx__setup_wizard_page__do_request_clean() {
131 // We donot require the 'calendar_force_load' parameter with all html and scripts content at server side. This content generated at server side.
132 // It is also can be the reason of blocking request, because of script tags.
133 _wpbc_settings.set_param__setup_wizard('calendar_force_load', '');
134 }