| 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': 'optional_other_settings', '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': 'optional_other_settings', '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 params_arr = _wpbc_settings.get_all_params__setup_wizard().steps |
| 113 |
var steps_finished = 1 |
| 114 |
_.each( params_arr, function ( p_val, p_key, p_data ) { |
| 115 |
if ( p_val.is_done ){ |
| 116 |
steps_finished++; |
| 117 |
} |
| 118 |
} ); |
| 119 |
return steps_finished; |
| 120 |
} |
| 121 |
|
| 122 |
function wpbc_setup_wizard_page__update_steps_status( steps_is_done_arr ){ |
| 123 |
|
| 124 |
var params_arr = _wpbc_settings.get_all_params__setup_wizard().steps |
| 125 |
|
| 126 |
_.each( steps_is_done_arr, function ( p_val, p_key, p_data ) { |
| 127 |
if ( "undefined" !== typeof ( params_arr[ p_key ] ) ) { |
| 128 |
params_arr[ p_key ].is_done = (true === steps_is_done_arr[ p_key ]); |
| 129 |
} |
| 130 |
} ); |
| 131 |
|
| 132 |
return params_arr; |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
function wpbc_setup_wizard_page__is_all_steps_completed(){ |
| 138 |
|
| 139 |
var params_arr = _wpbc_settings.get_all_params__setup_wizard().steps |
| 140 |
var status = true; |
| 141 |
|
| 142 |
_.each( params_arr, function ( p_val, p_key, p_data ) { |
| 143 |
if ( ! p_val.is_done ){ |
| 144 |
status = false; |
| 145 |
} |
| 146 |
} ); |
| 147 |
|
| 148 |
return status; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
/** |
| 153 |
* Define UI hooks for elements, after showing in Ajax. |
| 154 |
* |
| 155 |
* Because each time, when we show content in Ajax, all Hooks needs re-defined. |
| 156 |
*/ |
| 157 |
function wpbc_setup_wizard_page__define_ui_hooks(){ |
| 158 |
|
| 159 |
// ----------------------------------------------------------------------------------------------------------------- |
| 160 |
// Tooltips |
| 161 |
if ( 'function' === typeof( wpbc_define_tippy_tooltips ) ) { |
| 162 |
var parent_css_class = _wpbc_settings.get_param__other( 'container__main_content' ) + ' ' |
| 163 |
wpbc_define_tippy_tooltips( parent_css_class ); |
| 164 |
} |
| 165 |
|
| 166 |
// ----------------------------------------------------------------------------------------------------------------- |
| 167 |
// Change Radio Containers |
| 168 |
jQuery( '.wpbc_ui_radio_choice_input' ).on( 'change', function( event ){ |
| 169 |
|
| 170 |
wpbc_ui_el__radio_container_selection( this ); |
| 171 |
|
| 172 |
//wpbc_ajx__setup_wizard_page__send_request_with_params( { 'page_items_count': jQuery( this ).val(), 'page_num': 1 } ); |
| 173 |
} ); |
| 174 |
|
| 175 |
jQuery( '.wpbc_ui_radio_choice_input' ).each(function (index ){ |
| 176 |
wpbc_ui_el__radio_container_selection( this ); |
| 177 |
}); |
| 178 |
|
| 179 |
// Define ability to click on Radio Containers (not only radio-buttons) |
| 180 |
jQuery( '.wpbc_ui_radio_container' ).on( 'click', function( event ){ |
| 181 |
wpbc_ui_el__radio_container_click( this ); |
| 182 |
} ); |
| 183 |
|
| 184 |
// ----------------------------------------------------------------------------------------------------------------- |
| 185 |
|
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
// --------------------------------------------------------------------------------------------------------------------- |
| 191 |
// == M e s s a g e == |
| 192 |
// --------------------------------------------------------------------------------------------------------------------- |
| 193 |
|
| 194 |
/** |
| 195 |
* Show message in content |
| 196 |
* |
| 197 |
* @param message Message HTML |
| 198 |
* @param params = { |
| 199 |
* ['type'] 'warning' | 'info' | 'error' | 'success' default: 'warning' |
| 200 |
* ['container'] '.wpbc_ajx_cstm__section_left' default: _wpbc_settings.get_param__other( 'container__main_content') |
| 201 |
* ['is_append'] true | false default: true |
| 202 |
* } |
| 203 |
* Example: |
| 204 |
* var html_id = wpbc_setup_wizard_page__show_message( 'You can test days selection in calendar', 'info', '.wpbc_ajx_cstm__section_left', true ); |
| 205 |
* |
| 206 |
* |
| 207 |
* @returns string - HTML ID |
| 208 |
*/ |
| 209 |
function wpbc_setup_wizard_page__show_message( message, params = {} ){ |
| 210 |
|
| 211 |
var params_default = { |
| 212 |
'type' : 'warning', |
| 213 |
'container': _wpbc_settings.get_param__other( 'container__main_content'), |
| 214 |
'is_append': true, |
| 215 |
'style' : 'text-align:left;', |
| 216 |
'delay' : 0 |
| 217 |
}; |
| 218 |
_.each( params, function ( p_val, p_key, p_data ){ |
| 219 |
params_default[ p_key ] = p_val; |
| 220 |
} ); |
| 221 |
params = params_default; |
| 222 |
|
| 223 |
var unique_div_id = new Date(); |
| 224 |
unique_div_id = 'wpbc_notice_' + unique_div_id.getTime(); |
| 225 |
|
| 226 |
var alert_class = 'notice '; |
| 227 |
if ( params['type'] == 'error' ){ |
| 228 |
alert_class += 'notice-error '; |
| 229 |
message = '<i style="margin-right: 0.5em;color: #d63638;" class="menu_icon icon-1x wpbc_icn_report_gmailerrorred"></i>' + message; |
| 230 |
} |
| 231 |
if ( params['type'] == 'warning' ){ |
| 232 |
alert_class += 'notice-warning '; |
| 233 |
message = '<i style="margin-right: 0.5em;color: #e9aa04;" class="menu_icon icon-1x wpbc_icn_warning"></i>' + message; |
| 234 |
} |
| 235 |
if ( params['type'] == 'info' ){ |
| 236 |
alert_class += 'notice-info '; |
| 237 |
} |
| 238 |
if ( params['type'] == 'success' ){ |
| 239 |
alert_class += 'notice-info alert-success updated '; |
| 240 |
message = '<i style="margin-right: 0.5em;color: #64aa45;" class="menu_icon icon-1x wpbc_icn_done_outline"></i>' + message; |
| 241 |
} |
| 242 |
|
| 243 |
message = '<div id="' + unique_div_id + '" class="wpbc-settings-notice ' + alert_class + '" style="' + params[ 'style' ] + '">' + message + '</div>'; |
| 244 |
|
| 245 |
if ( params['is_append'] ){ |
| 246 |
jQuery( params['container'] ).append( message ); |
| 247 |
} else { |
| 248 |
jQuery( params['container'] ).html( message ); |
| 249 |
} |
| 250 |
|
| 251 |
params['delay'] = parseInt( params['delay'] ); |
| 252 |
if ( params['delay'] > 0 ){ |
| 253 |
|
| 254 |
var closed_timer = setTimeout( function (){ |
| 255 |
jQuery( '#' + unique_div_id ).fadeOut( 1500 ); |
| 256 |
} |
| 257 |
, params[ 'delay' ] |
| 258 |
); |
| 259 |
} |
| 260 |
return unique_div_id; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
// --------------------------------------------------------------------------------------------------------------------- |
| 265 |
// == Support Functions - Spin Icon in Top Bar Menu -> ' Initial Setup' == |
| 266 |
// --------------------------------------------------------------------------------------------------------------------- |
| 267 |
|
| 268 |
/** |
| 269 |
* Spin button in Filter toolbar - Start |
| 270 |
*/ |
| 271 |
function wpbc_setup_wizard_page_reload_button__spin_start(){ |
| 272 |
return false; // Currently disabled, maybe activate it for some other element. |
| 273 |
jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin').removeClass( 'wpbc_animation_pause' ); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Spin button in Filter toolbar - Pause |
| 278 |
*/ |
| 279 |
function wpbc_setup_wizard_page_reload_button__spin_pause(){ |
| 280 |
jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin' ).addClass( 'wpbc_animation_pause' ); |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* Spin button in Filter toolbar - is Spinning ? |
| 285 |
* |
| 286 |
* @returns {boolean} |
| 287 |
*/ |
| 288 |
function wpbc_setup_wizard_page_reload_button__is_spin(){ |
| 289 |
if ( jQuery( '#wpbc_initial_setup_top_menu_item .menu_icon.wpbc_spin' ).hasClass( 'wpbc_animation_pause' ) ){ |
| 290 |
return true; |
| 291 |
} else { |
| 292 |
return false; |
| 293 |
} |
| 294 |
} |
| 295 |
|