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