| 1 |
/* global wpchar, wpCookies */ |
| 2 |
// eslint-disable-line no-unused-vars |
| 3 |
|
| 4 |
var CharitableSetup = window.CharitableSetup || (function (document, window, $) { |
| 5 |
|
| 6 |
var s = {}, |
| 7 |
elements = {}; |
| 8 |
|
| 9 |
var app = { |
| 10 |
|
| 11 |
settings: { |
| 12 |
onboarded: false |
| 13 |
}, |
| 14 |
|
| 15 |
/** |
| 16 |
* Start the engine. |
| 17 |
* |
| 18 |
* @since 1.8.1 |
| 19 |
*/ |
| 20 |
init: function () { |
| 21 |
|
| 22 |
s = this.settings; |
| 23 |
|
| 24 |
// Document ready. |
| 25 |
$(app.ready); |
| 26 |
|
| 27 |
}, |
| 28 |
|
| 29 |
/** |
| 30 |
* Document ready. |
| 31 |
* |
| 32 |
* @since 1.8.4 |
| 33 |
* |
| 34 |
*/ |
| 35 |
ready: function () { // check to see if javascript has been defined. |
| 36 |
|
| 37 |
// check to see if charitable_setup has been defined. |
| 38 |
if ( typeof charitable_setup === 'undefined' ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
wpchar.debug('charitable_setup'); |
| 43 |
wpchar.debug(charitable_setup); |
| 44 |
|
| 45 |
s.version = '1.8.4'; |
| 46 |
s.steps = [ 'start', 'meta', 'plugins_installed', 'plugins_activated', 'activate_license', 'features', 'campaign', 'payment_methods', 'almost_complete', 'complete' ]; |
| 47 |
s.setup_step = charitable_setup.setup_step || 'meta'; |
| 48 |
s.plugins = charitable_setup.plugins || []; |
| 49 |
s.plugins_meta = charitable_setup.plugins_meta || []; |
| 50 |
s.features = charitable_setup.features || []; |
| 51 |
s.features_meta = charitable_setup.features_meta || []; |
| 52 |
s.payment_methods = charitable_setup.payment_methods || []; |
| 53 |
s.stripe_connect_url = charitable_setup.stripe_connect_url || ''; |
| 54 |
s.stripe_skip_html = charitable_setup.stripe_skip_html || ''; |
| 55 |
s.stripe_returned = charitable_setup.stripe_returned || false; |
| 56 |
s.campaign_skip = charitable_setup.campaign_skip || false; |
| 57 |
s.checklist_completed = charitable_setup.checklist_completed || false; |
| 58 |
s.key = charitable_setup.key || ''; |
| 59 |
|
| 60 |
s.pro_test = false; // true if we did the test already. |
| 61 |
s.is_pro = false; // true if we're running the pro version. |
| 62 |
s.test_mode = charitable_setup.test_mode || false; |
| 63 |
|
| 64 |
s.feature_issue = false; // true if one or more of the feature addons were not installed or activated. |
| 65 |
s.license_issue = false; // true if the license was not activated. |
| 66 |
|
| 67 |
// Action buttons. |
| 68 |
elements.$progressBar = $( '.charitable-user-onboarding-progress-bar' ); |
| 69 |
elements.$progressBarFill = $( '.charitable-user-onboarding-progress-bar-fill' ); |
| 70 |
elements.$textHeadline = $( '.chartiable-user-onboarding-content h1' ); |
| 71 |
elements.$textSubHeadline = $( '.chartiable-user-onboarding-content p.charitable-subheading' ); |
| 72 |
|
| 73 |
// Bind all actions. |
| 74 |
app.bindUIActions(); |
| 75 |
|
| 76 |
// Setup Triggers. |
| 77 |
app.setupTriggers(); |
| 78 |
|
| 79 |
app.processStart(); |
| 80 |
|
| 81 |
// Check if we are returning from Stripe. |
| 82 |
if ( s.stripe_returned || s.checklist_completed ) { |
| 83 |
|
| 84 |
$(document).trigger( 'charitable_setup_step_complete' ); |
| 85 |
|
| 86 |
} else { |
| 87 |
|
| 88 |
setTimeout( function() { |
| 89 |
app.processMeta(); |
| 90 |
}, 1500 ); |
| 91 |
// Process step. |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
}, |
| 96 |
|
| 97 |
/** |
| 98 |
* Element bindings. |
| 99 |
* |
| 100 |
* @since 1.8.4 |
| 101 |
*/ |
| 102 |
bindUIActions: function () { |
| 103 |
|
| 104 |
}, |
| 105 |
|
| 106 |
setupTriggers: function() { |
| 107 |
|
| 108 |
$(document).on( 'charitable_setup_step_start', app.processStart ); |
| 109 |
|
| 110 |
$(document).on( 'charitable_setup_step_meta', app.processMeta ); |
| 111 |
|
| 112 |
$(document).on( 'charitable_setup_step_plugins_install', app.processPluginsInstall ); |
| 113 |
|
| 114 |
$(document).on( 'charitable_setup_step_plugins_activate', app.processPluginsActivate ); |
| 115 |
|
| 116 |
$(document).on( 'charitable_setup_step_activate_license', app.processActivateLicense ); |
| 117 |
|
| 118 |
$(document).on( 'charitable_setup_step_features', app.processFeatures ); |
| 119 |
|
| 120 |
$(document).on( 'charitable_setup_step_campaign', app.processCampaign ); |
| 121 |
|
| 122 |
$(document).on( 'charitable_setup_step_pm', app.processPM ); |
| 123 |
|
| 124 |
$(document).on( 'charitable_setup_step_almost_complete', app.stepAlmostComplete ); |
| 125 |
|
| 126 |
$(document).on( 'charitable_setup_step_complete', app.stepComplete ); |
| 127 |
|
| 128 |
}, |
| 129 |
|
| 130 |
processStart: function() { |
| 131 |
|
| 132 |
wpchar.debug( 'processStart' ); |
| 133 |
s.setup_step = 'start'; |
| 134 |
|
| 135 |
app.updateHeadline( s.setup_step ); |
| 136 |
// app.updateSubHeadline( s.setup_step ); |
| 137 |
|
| 138 |
// update the progress bar. |
| 139 |
app.updateProgressBar( s.setup_step ); |
| 140 |
|
| 141 |
}, |
| 142 |
|
| 143 |
processMeta: function( step = false ) { |
| 144 |
|
| 145 |
// Step 1. |
| 146 |
// Update email and general settings (should be quick). |
| 147 |
|
| 148 |
var data = { |
| 149 |
action : 'charitable_setup_process_meta', |
| 150 |
step : s.setup_step, |
| 151 |
nonce : charitable_setup.setup_nonce |
| 152 |
}; |
| 153 |
|
| 154 |
$.post( charitable_setup.ajax_url, data, function( response ) { |
| 155 |
|
| 156 |
if ( response.success ) { |
| 157 |
|
| 158 |
wpchar.debug( response ); |
| 159 |
|
| 160 |
// check to see if there's a processed step. |
| 161 |
if ( response.data.processed_step ) { |
| 162 |
|
| 163 |
// update the setup step. |
| 164 |
s.setup_step = response.data.next_step; |
| 165 |
|
| 166 |
// update the progress bar. |
| 167 |
app.updateProgressBar( s.setup_step ); |
| 168 |
|
| 169 |
// update the text. |
| 170 |
app.updateHeadline( s.setup_step ); |
| 171 |
app.updateSubHeadline( s.setup_step ); |
| 172 |
|
| 173 |
// trigger a custom event. |
| 174 |
$(document).trigger( 'charitable_setup_step_plugins_install' ); |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
} else { |
| 179 |
|
| 180 |
wpchar.debug('processMeta error'); |
| 181 |
wpchar.debug( response ); |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
}); |
| 186 |
|
| 187 |
}, |
| 188 |
|
| 189 |
processPluginsInstall: function( step = false ) { |
| 190 |
|
| 191 |
wpchar.debug( 'processPluginsInstall' ); |
| 192 |
|
| 193 |
wpchar.debug( s.plugins ); |
| 194 |
wpchar.debug( s.plugins_meta ); |
| 195 |
|
| 196 |
s.setup_step = 'plugins_installed'; |
| 197 |
|
| 198 |
// if s,plugins is empty or s.plugins.install is empty, then we're done. |
| 199 |
if ( ! s.plugins || ! s.plugins.install || s.plugins.install.length === 0 ) { |
| 200 |
wpchar.debug('installed done'); |
| 201 |
// trigger a custom event. |
| 202 |
// update the progress bar. |
| 203 |
app.updateProgressBar( s.setup_step ); |
| 204 |
$(document).trigger( 'charitable_setup_step_plugins_activate' ); |
| 205 |
return; |
| 206 |
} |
| 207 |
|
| 208 |
// Remove duplicates from s.plugins.install. |
| 209 |
s.plugins.install = s.plugins.install.filter( function( item, index, inputArray ) { |
| 210 |
return inputArray.indexOf(item) == index; |
| 211 |
}); |
| 212 |
|
| 213 |
// Get the next plugin from the list. |
| 214 |
var plugin_slug = s.plugins.install.shift(); |
| 215 |
|
| 216 |
wpchar.debug( plugin_slug ); |
| 217 |
|
| 218 |
var plugin_name = ( 'undefined' !== typeof s.plugins_meta[ plugin_slug ] ) ? s.plugins_meta[ plugin_slug ].name : ''; |
| 219 |
|
| 220 |
if ( '' === plugin_name ) { |
| 221 |
this.return; |
| 222 |
} |
| 223 |
|
| 224 |
var data = { |
| 225 |
action: 'charitable_install_plugin', |
| 226 |
nonce: charitable_admin.nonce, |
| 227 |
slug: plugin_slug |
| 228 |
}; |
| 229 |
|
| 230 |
// Update the "subheadine" text. |
| 231 |
elements.$textSubHeadline.text( 'Installing ' + plugin_name + '...' ); |
| 232 |
|
| 233 |
$.post( charitable_admin.ajax_url, data, function (response) { |
| 234 |
|
| 235 |
if ( response.success ) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 236 |
|
| 237 |
wpchar.debug( 'success') |
| 238 |
wpchar.debug( response ); |
| 239 |
|
| 240 |
app.updateHeadline( s.setup_step ); |
| 241 |
elements.$textSubHeadline.text( 'Installed ' + plugin_name + '.' ); |
| 242 |
|
| 243 |
// update the progress bar. |
| 244 |
app.updateProgressBar( s.setup_step, plugin_slug, s.plugins.install ); |
| 245 |
|
| 246 |
// ad the slug to the plugins activate list. |
| 247 |
s.plugins.activate.push( plugin_slug ); |
| 248 |
|
| 249 |
// is the installed plugins list empty? if so, trigger activate plugins. |
| 250 |
if ( s.plugins.install.length === 0 ) { |
| 251 |
// update the setup step. |
| 252 |
s.setup_step = response.data.next_step; |
| 253 |
$(document).trigger( 'charitable_setup_step_plugins_activate' ); |
| 254 |
} else { |
| 255 |
app.processPluginsInstall(); |
| 256 |
} |
| 257 |
|
| 258 |
} else { |
| 259 |
|
| 260 |
wpchar.debug( 'error' ); |
| 261 |
wpchar.debug( response ); |
| 262 |
|
| 263 |
// don't stop things, keep going. |
| 264 |
|
| 265 |
// update the progress bar. |
| 266 |
app.updateProgressBar( s.setup_step, plugin_slug, s.plugins.install ); |
| 267 |
|
| 268 |
// is the installed plugins list empty? if so, trigger activate plugins. |
| 269 |
if ( s.plugins.install.length === 0 ) { |
| 270 |
// update the setup step. |
| 271 |
s.setup_step = ( 'undefined' === typeof response.data || 'undefined' === typeof response.data.next_step ) ? 'plugins_activated' : response.data.next_step; |
| 272 |
$(document).trigger( 'charitable_setup_step_plugins_activate' ); |
| 273 |
} else { |
| 274 |
app.processPluginsInstall(); |
| 275 |
} |
| 276 |
|
| 277 |
} |
| 278 |
|
| 279 |
}); |
| 280 |
|
| 281 |
}, |
| 282 |
|
| 283 |
processPluginsActivate: function( step = false ) { |
| 284 |
|
| 285 |
wpchar.debug( 'processPluginsActivate' ); |
| 286 |
|
| 287 |
// wpchar.debug( plugin_slug ); |
| 288 |
wpchar.debug( s.plugins ); |
| 289 |
wpchar.debug( s.plugins_meta ); |
| 290 |
|
| 291 |
s.setup_step = 'plugins_activated'; |
| 292 |
|
| 293 |
// if s,plugins is empty or s.plugins.install is empty, then we're done. |
| 294 |
if ( ! s.plugins || ! s.plugins.activate || s.plugins.activate.length === 0 ) { |
| 295 |
wpchar.debug('activated done'); |
| 296 |
// update the progress bar. |
| 297 |
app.updateProgressBar( s.setup_step ); |
| 298 |
|
| 299 |
// do we go on to activate the license or the feature step? |
| 300 |
if ( s.key ) { |
| 301 |
s.setup_step = 'activate_license'; |
| 302 |
$(document).trigger( 'charitable_setup_step_activate_license' ); |
| 303 |
} else { |
| 304 |
s.setup_step = 'features'; |
| 305 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 306 |
} |
| 307 |
return; |
| 308 |
} |
| 309 |
|
| 310 |
// Remove duplicates from s.plugins.activate. |
| 311 |
s.plugins.activate = s.plugins.activate.filter( function( item, index, inputArray ) { |
| 312 |
return inputArray.indexOf(item) == index; |
| 313 |
}); |
| 314 |
|
| 315 |
// Get the next plugin from the list. |
| 316 |
var plugin_slug = s.plugins.activate.shift(); |
| 317 |
|
| 318 |
wpchar.debug( plugin_slug ); |
| 319 |
|
| 320 |
wpchar.debug('s.plugins_meta'); |
| 321 |
wpchar.debug( s.plugins_meta ); |
| 322 |
|
| 323 |
wpchar.debug('s.plugins_meta[ plugin_slug ]'); |
| 324 |
wpchar.debug( s.plugins_meta[ plugin_slug ] ); |
| 325 |
|
| 326 |
wpchar.debug('s.plugins_meta[ plugin_slug ].name'); |
| 327 |
wpchar.debug( s.plugins_meta[ plugin_slug ].name ); |
| 328 |
|
| 329 |
if ( 'undefined' !== typeof s.plugins_meta[ plugin_slug ] && 'undefined' !== typeof s.plugins_meta[ plugin_slug ].name ) { |
| 330 |
|
| 331 |
var plugin_name = s.plugins_meta[ plugin_slug ].name; |
| 332 |
|
| 333 |
var data = { |
| 334 |
action: 'charitable_activate_plugin', |
| 335 |
nonce: charitable_admin.nonce, |
| 336 |
slug: plugin_slug, |
| 337 |
basename: s.plugins_meta[ plugin_slug ].basename || '' |
| 338 |
}; |
| 339 |
|
| 340 |
// Update the "subheadine" text. |
| 341 |
elements.$textSubHeadline.text( 'Activating ' + plugin_name + '...' ); |
| 342 |
|
| 343 |
$.post( charitable_admin.ajax_url, data, function (response) { |
| 344 |
|
| 345 |
if ( response.success ) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 346 |
|
| 347 |
wpchar.debug( 'success') |
| 348 |
wpchar.debug( response ); |
| 349 |
|
| 350 |
app.updateHeadline( s.setup_step ); |
| 351 |
elements.$textSubHeadline.text( 'Activated ' + plugin_name + '.' ); |
| 352 |
|
| 353 |
// update the progress bar. |
| 354 |
app.updateProgressBar( s.setup_step, plugin_slug, s.plugins.activate ); |
| 355 |
|
| 356 |
// is the installed plugins list empty? if so, trigger activate plugins. |
| 357 |
if ( s.plugins.activate.length === 0 ) { |
| 358 |
|
| 359 |
wpchar.debug('activated phase done'); |
| 360 |
wpchar.debug( s.key ); |
| 361 |
|
| 362 |
// do we go on to activate the license or the feature step? |
| 363 |
if ( s.key ) { |
| 364 |
s.setup_step = 'activate_license'; |
| 365 |
$(document).trigger( 'charitable_setup_step_activate_license' ); |
| 366 |
} else { |
| 367 |
s.setup_step = 'features'; |
| 368 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 369 |
} |
| 370 |
return; |
| 371 |
|
| 372 |
} else { |
| 373 |
app.processPluginsActivate(); |
| 374 |
} |
| 375 |
|
| 376 |
} else { |
| 377 |
|
| 378 |
wpchar.debug( 'error' ); |
| 379 |
wpchar.debug( response ); |
| 380 |
} |
| 381 |
|
| 382 |
}); |
| 383 |
|
| 384 |
} else { |
| 385 |
|
| 386 |
if ( s.plugins.activate.length === 0 ) { |
| 387 |
// update the setup step. |
| 388 |
wpchar.debug('activated phase alt done'); |
| 389 |
wpchar.debug( s.key ); |
| 390 |
|
| 391 |
// do we go on to activate the license or the feature step? |
| 392 |
if ( s.key ) { |
| 393 |
s.setup_step = 'activate_license'; |
| 394 |
$(document).trigger( 'charitable_setup_step_activate_license' ); |
| 395 |
} else { |
| 396 |
s.setup_step = 'features'; |
| 397 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 398 |
} |
| 399 |
} else { |
| 400 |
app.processPluginsActivate(); |
| 401 |
} |
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
}, |
| 406 |
|
| 407 |
processActivateLicense: function( step = false ) { |
| 408 |
|
| 409 |
wpchar.debug( 'processActivateLicense' ); |
| 410 |
wpchar.debug( s.key ); |
| 411 |
|
| 412 |
if ( ! s.key ) { |
| 413 |
s.setup_step = 'features'; |
| 414 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 415 |
return; |
| 416 |
} |
| 417 |
|
| 418 |
s.setup_step = 'activate_license'; |
| 419 |
|
| 420 |
// use the ajax charitable_license_check. |
| 421 |
var data = { |
| 422 |
'action' : 'charitable_license_check', |
| 423 |
'license' : s.key, |
| 424 |
'nonce' : charitable_setup.key_nonce, |
| 425 |
'charitable_action' : 'verify', |
| 426 |
'download_pro' : true |
| 427 |
}; |
| 428 |
|
| 429 |
// update the text. |
| 430 |
app.updateHeadline( s.setup_step ); |
| 431 |
app.updateSubHeadline( s.setup_step ); |
| 432 |
|
| 433 |
$.ajax({ |
| 434 |
type: 'POST', |
| 435 |
data: data, |
| 436 |
dataType: 'json', |
| 437 |
url: ajaxurl, |
| 438 |
xhrFields: { |
| 439 |
withCredentials: true |
| 440 |
}, |
| 441 |
success: function (response) { |
| 442 |
wpchar.debug ('success in response'); |
| 443 |
wpchar.debug( response ); |
| 444 |
if ( response.success && response.data.valid ) { |
| 445 |
wpchar.debug ('success in response: license valid'); |
| 446 |
// update the progress bar. |
| 447 |
app.updateProgressBar( s.setup_step ); |
| 448 |
s.setup_step = 'features'; |
| 449 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 450 |
} else { |
| 451 |
wpchar.debug ('success in response: license not valid'); |
| 452 |
wpchar.debug( response ); |
| 453 |
s.license_issue = true; |
| 454 |
// update the progress bar. |
| 455 |
app.updateProgressBar( s.setup_step ); |
| 456 |
s.setup_step = 'features'; |
| 457 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 458 |
} |
| 459 |
} |
| 460 |
}).fail(function (data) { |
| 461 |
if ( window.console && window.wpchar.debug ) { |
| 462 |
wpchar.debug( 'license activation error' ); |
| 463 |
wpchar.debug( data ); |
| 464 |
} |
| 465 |
s.license_issue = true; |
| 466 |
// show much go on. |
| 467 |
// update the progress bar. |
| 468 |
app.updateProgressBar( s.setup_step ); |
| 469 |
s.setup_step = 'features'; |
| 470 |
$(document).trigger( 'charitable_setup_step_features' ); |
| 471 |
}); |
| 472 |
|
| 473 |
}, |
| 474 |
|
| 475 |
processFeatures: function( step = false ) { |
| 476 |
|
| 477 |
wpchar.debug( 'function : processFeatures' ); |
| 478 |
wpchar.debug( s.features ); |
| 479 |
|
| 480 |
s.setup_step = 'features'; |
| 481 |
|
| 482 |
// if s,plugins is empty or s.plugins.install is empty, then we're done. |
| 483 |
if ( ! s.features || ! s.features.length === 0 ) { |
| 484 |
wpchar.debug('features done'); |
| 485 |
// update the progress bar. |
| 486 |
app.updateProgressBar( s.setup_step ); |
| 487 |
$(document).trigger( 'charitable_setup_step_campaign' ); |
| 488 |
return; |
| 489 |
} |
| 490 |
|
| 491 |
if ( s.pro_test && ! s.is_pro ) { |
| 492 |
wpchar.debug('features not possible'); |
| 493 |
// update the progress bar. |
| 494 |
app.updateProgressBar( s.setup_step ); |
| 495 |
$(document).trigger( 'charitable_setup_step_campaign' ); |
| 496 |
return; |
| 497 |
} |
| 498 |
|
| 499 |
// Remove duplicates from s.plugins.activate. |
| 500 |
s.features = s.features.filter( function( item, index, inputArray ) { |
| 501 |
return inputArray.indexOf(item) == index; |
| 502 |
}); |
| 503 |
|
| 504 |
// Get the next feature from the list. |
| 505 |
var feature_slug = s.features.shift(); |
| 506 |
|
| 507 |
if ( 'undefined' === typeof s.features_meta[ feature_slug ] ) { |
| 508 |
wpchar.debug('s.features_meta[ feature_slug ] not found'); |
| 509 |
app.updateProgressBar( s.setup_step ); |
| 510 |
$(document).trigger( 'charitable_setup_step_campaign' ); |
| 511 |
return; |
| 512 |
} |
| 513 |
|
| 514 |
wpchar.debug( feature_slug ); |
| 515 |
wpchar.debug( s.features_meta ); |
| 516 |
|
| 517 |
var feature_name = s.features_meta[ feature_slug ].name; |
| 518 |
|
| 519 |
var data = { |
| 520 |
action: 'charitable_activate_feature', |
| 521 |
nonce: charitable_admin.nonce, |
| 522 |
slug: feature_slug, |
| 523 |
}; |
| 524 |
|
| 525 |
if ( ! s.pro_test ) { |
| 526 |
// Update the "subheadine" text. |
| 527 |
elements.$textSubHeadline.text( 'Checking license and account information...' ); |
| 528 |
} else { |
| 529 |
// Update the "subheadine" text. |
| 530 |
elements.$textSubHeadline.text( 'Installing ' + feature_name + '...' ); |
| 531 |
} |
| 532 |
|
| 533 |
$.post( charitable_admin.ajax_url, data, function (response) { |
| 534 |
|
| 535 |
if ( response.success ) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 536 |
|
| 537 |
wpchar.debug( 'process features: success') |
| 538 |
wpchar.debug( response ); |
| 539 |
|
| 540 |
app.updateHeadline( s.setup_step ); |
| 541 |
elements.$textSubHeadline.text( 'Activated ' + feature_name + '.' ); |
| 542 |
wpchar.debug( 'Activated ' + feature_name + '.' ); |
| 543 |
|
| 544 |
// update the progress bar. |
| 545 |
app.updateProgressBar( s.setup_step ); |
| 546 |
|
| 547 |
$('#charitable-user-onboarding-notice-featured-not-required').removeClass('charitable-hidden'); |
| 548 |
|
| 549 |
// is the installed plugins list empty? if so, trigger activate plugins. |
| 550 |
if ( s.features.length === 0 ) { |
| 551 |
|
| 552 |
setTimeout( function() { |
| 553 |
$('#charitable-user-onboarding-notice-featured-not-required').addClass('charitable-hidden'); |
| 554 |
$('p.charitable-subheading').removeClass('charitable-hidden'); |
| 555 |
$(document).trigger( 'charitable_setup_step_campaign' ); |
| 556 |
}, 2500 ); |
| 557 |
|
| 558 |
|
| 559 |
} else { |
| 560 |
|
| 561 |
setTimeout( function() { |
| 562 |
app.processFeatures(); |
| 563 |
}, 2500 ); |
| 564 |
} |
| 565 |
|
| 566 |
} else { |
| 567 |
|
| 568 |
wpchar.debug( 'process features: error' ); |
| 569 |
wpchar.debug( response ); |
| 570 |
wpchar.debug( s.setup_step ); |
| 571 |
|
| 572 |
s.feature_issue = true; |
| 573 |
|
| 574 |
if ( s.features.length === 0 ) { |
| 575 |
|
| 576 |
$('p.charitable-subheading').addClass('charitable-hidden'); |
| 577 |
$('#charitable-user-onboarding-notice-featured-required').removeClass('charitable-hidden'); |
| 578 |
|
| 579 |
app.updateProgressBar( s.setup_step ); |
| 580 |
app.updateHeadline( s.setup_step ); |
| 581 |
app.updateSubHeadline( s.setup_step ); |
| 582 |
|
| 583 |
// wait a couple of seconds and then trigger the next step. |
| 584 |
setTimeout( function() { |
| 585 |
$('#charitable-user-onboarding-notice-featured-required').addClass('charitable-hidden'); |
| 586 |
$('p.charitable-subheading').removeClass('charitable-hidden'); |
| 587 |
$(document).trigger( 'charitable_setup_step_campaign' ); |
| 588 |
}, 2500 ); |
| 589 |
|
| 590 |
|
| 591 |
} else { |
| 592 |
|
| 593 |
setTimeout( function() { |
| 594 |
app.processFeatures(); |
| 595 |
}, 2500 ); |
| 596 |
|
| 597 |
} |
| 598 |
|
| 599 |
// $('p.charitable-subheading').addClass('charitable-hidden'); |
| 600 |
// $('#charitable-user-onboarding-notice-featured-required').removeClass('charitable-hidden'); |
| 601 |
|
| 602 |
// app.updateProgressBar( s.setup_step ); |
| 603 |
// app.updateHeadline( s.setup_step ); |
| 604 |
// app.updateSubHeadline( s.setup_step ); |
| 605 |
|
| 606 |
// // wait a couple of seconds and then trigger the next step. |
| 607 |
// setTimeout( function() { |
| 608 |
// $('#charitable-user-onboarding-notice-featured-required').addClass('charitable-hidden'); |
| 609 |
// $('p.charitable-subheading').removeClass('charitable-hidden'); |
| 610 |
// // $(document).trigger( 'charitable_setup_step_campaign' ); |
| 611 |
// $(document).trigger( 'charitable_setup_step_campaign' ); |
| 612 |
// }, 2500 ); |
| 613 |
} |
| 614 |
|
| 615 |
}); |
| 616 |
|
| 617 |
}, |
| 618 |
|
| 619 |
processCampaign: function( step = false ) { |
| 620 |
|
| 621 |
wpchar.debug( 'processCampaign' ); |
| 622 |
|
| 623 |
// we need to determine if the user has created a campaign or skipped that option. |
| 624 |
if ( s.campaign_skip ) { |
| 625 |
s.setup_step = 'campaign'; |
| 626 |
// update the progress bar. |
| 627 |
app.updateProgressBar( s.setup_step ); |
| 628 |
$(document).trigger( 'charitable_setup_step_pm' ); |
| 629 |
return; |
| 630 |
} |
| 631 |
|
| 632 |
var data = { |
| 633 |
action : 'charitable_setup_process_campaign', |
| 634 |
step : s.setup_step, |
| 635 |
nonce : charitable_setup.setup_nonce |
| 636 |
}; |
| 637 |
|
| 638 |
$.post( charitable_setup.ajax_url, data, function( response ) { |
| 639 |
|
| 640 |
if ( response.success ) { |
| 641 |
|
| 642 |
if ( ( 'undefined' !== ( typeof response.data.status ) && response.data.status === 'campaign-created' ) ) { |
| 643 |
|
| 644 |
s.setup_step = 'campaign'; |
| 645 |
app.updateHeadline( s.setup_step ); |
| 646 |
app.updateSubHeadline( s.setup_step ); |
| 647 |
|
| 648 |
wpchar.debug( response ); |
| 649 |
|
| 650 |
// update the progress bar. |
| 651 |
app.updateProgressBar( s.setup_step ); |
| 652 |
|
| 653 |
setTimeout( function() { |
| 654 |
$(document).trigger( 'charitable_setup_step_pm' ); |
| 655 |
}, 2500 ); |
| 656 |
|
| 657 |
} else { |
| 658 |
// likely the user skipped building the campaign. |
| 659 |
$(document).trigger( 'charitable_setup_step_pm' ); |
| 660 |
} |
| 661 |
|
| 662 |
} else { |
| 663 |
|
| 664 |
wpchar.debug('create campaign error'); |
| 665 |
|
| 666 |
wpchar.debug( response ); |
| 667 |
|
| 668 |
// show must go on. |
| 669 |
// $(document).trigger( 'charitable_setup_step_pm' ); |
| 670 |
|
| 671 |
} |
| 672 |
|
| 673 |
}); |
| 674 |
|
| 675 |
}, |
| 676 |
|
| 677 |
processPM: function( step = false ) { |
| 678 |
|
| 679 |
wpchar.debug( 'processPM' ); |
| 680 |
|
| 681 |
// wpchar.debug( plugin_slug ); |
| 682 |
s.setup_step = 'payment_methods'; |
| 683 |
app.updateHeadline( s.setup_step ); |
| 684 |
app.updateSubHeadline( s.setup_step ); |
| 685 |
|
| 686 |
// update the progress bar. |
| 687 |
app.updateProgressBar( s.setup_step ); |
| 688 |
|
| 689 |
$(document).trigger( 'charitable_setup_step_almost_complete' ); |
| 690 |
}, |
| 691 |
|
| 692 |
stepAlmostComplete: function( step = false ) { |
| 693 |
|
| 694 |
wpchar.debug( 'almostComplete' ); |
| 695 |
|
| 696 |
s.setup_step = 'almost_complete'; |
| 697 |
app.updateHeadline( s.setup_step ); |
| 698 |
app.updateSubHeadline( s.setup_step ); |
| 699 |
|
| 700 |
// at this point the gateways have been enabled, but if the user selected Stripe |
| 701 |
// we want the last "step" to be the Stripe Connect to keep the flow. |
| 702 |
|
| 703 |
var stripe_index = s.payment_methods.indexOf( 'stripe' ); |
| 704 |
// check also for the connect url (if there's no connect url then something is wrong or it's already connected). |
| 705 |
if ( stripe_index !== -1 && s.stripe_connect_url !== '' ) { |
| 706 |
app.updateSubHeadline( 'almost_complete_stripe' ); |
| 707 |
// adjust the warning message at the bottom they can actually skip this if they must. |
| 708 |
$('.charitable-go-back').html( s.stripe_skip_html ); |
| 709 |
// show the Stripe connect field in the setup template. |
| 710 |
$('#charitable-user-onboarding-stripe-connect').removeClass('charitable-hidden'); |
| 711 |
} else { |
| 712 |
// update the progress bar. |
| 713 |
app.updateProgressBar( s.setup_step ); |
| 714 |
$(document).trigger( 'charitable_setup_step_complete' ); |
| 715 |
} |
| 716 |
|
| 717 |
}, |
| 718 |
|
| 719 |
stepComplete: function( step = false ) { |
| 720 |
|
| 721 |
wpchar.debug( 'Complete' ); |
| 722 |
|
| 723 |
s.setup_step = 'complete'; |
| 724 |
|
| 725 |
var data = { |
| 726 |
action : 'charitable_setup_process_complete', |
| 727 |
step : s.setup_step, |
| 728 |
nonce : charitable_setup.setup_nonce |
| 729 |
}; |
| 730 |
|
| 731 |
$.post( charitable_setup.ajax_url, data, function( response ) { |
| 732 |
|
| 733 |
if ( response.success ) { |
| 734 |
|
| 735 |
app.updateHeadline( s.setup_step ); |
| 736 |
app.updateSubHeadline( s.setup_step ); |
| 737 |
|
| 738 |
// update the progress bar. |
| 739 |
app.updateProgressBar( s.setup_step ); |
| 740 |
|
| 741 |
app.fireConfetti(); |
| 742 |
|
| 743 |
if ( s.license_issue === true ) { |
| 744 |
// remove the hidden class from the license issue notice. |
| 745 |
$('#charitable-user-onboarding-notice-license-failed').removeClass('charitable-hidden'); |
| 746 |
$("#charitable-user-onboarding-notice-license-not-required").addClass('charitable-hidden'); |
| 747 |
} else if ( s.feature_issue === true ) { |
| 748 |
// remove the hidden class from the feature issue notice. |
| 749 |
$('#charitable-user-onboarding-notice-featured-failed').removeClass('charitable-hidden'); |
| 750 |
$("#charitable-user-onboarding-notice-featured-not-required").addClass('charitable-hidden'); |
| 751 |
} |
| 752 |
|
| 753 |
$('#charitable-user-onboarding-complete-buttons').removeClass('charitable-hidden'); |
| 754 |
|
| 755 |
if ( s.checklist_completed ) { |
| 756 |
$('#charitable-user-onboarding-complete-buttons .charitable-view-checklist').addClass('charitable-hidden'); |
| 757 |
} |
| 758 |
|
| 759 |
} else { |
| 760 |
|
| 761 |
// show must go on. |
| 762 |
|
| 763 |
app.updateHeadline( s.setup_step ); |
| 764 |
app.updateSubHeadline( s.setup_step ); |
| 765 |
|
| 766 |
// update the progress bar. |
| 767 |
app.updateProgressBar( s.setup_step ); |
| 768 |
|
| 769 |
app.fireConfetti(); |
| 770 |
|
| 771 |
$('#charitable-user-onboarding-complete-buttons').removeClass('charitable-hidden'); |
| 772 |
|
| 773 |
} |
| 774 |
|
| 775 |
}); |
| 776 |
|
| 777 |
}, |
| 778 |
|
| 779 |
fireConfetti: function() { |
| 780 |
|
| 781 |
if ( typeof confetti === 'function') { |
| 782 |
confetti({ |
| 783 |
spread: 150, |
| 784 |
particleCount: 250, |
| 785 |
zIndex: 9999999999, |
| 786 |
origin: { y: 0.55 }, |
| 787 |
}); |
| 788 |
} |
| 789 |
|
| 790 |
}, |
| 791 |
|
| 792 |
updateHeadline: function( step = '' ) { |
| 793 |
|
| 794 |
var headline = charitable_setup.headlines[ step ]; |
| 795 |
|
| 796 |
elements.$textHeadline.text( headline ); |
| 797 |
|
| 798 |
}, |
| 799 |
|
| 800 |
updateSubHeadline: function( step = '' ) { |
| 801 |
|
| 802 |
var subHeadline = charitable_setup.text[ step ]; |
| 803 |
|
| 804 |
elements.$textSubHeadline.text( subHeadline ); |
| 805 |
|
| 806 |
}, |
| 807 |
|
| 808 |
/** |
| 809 |
* Update the progress bar. |
| 810 |
* |
| 811 |
* @since 1.8.1 |
| 812 |
*/ |
| 813 |
updateProgressBar: function( step = '', plugin_slug = '', plugin_slug_list = [] ) { |
| 814 |
|
| 815 |
wpchar.debug( 'updateProgressBar' ); |
| 816 |
wpchar.debug( step ); |
| 817 |
|
| 818 |
var $progressBar = elements.$progressBar, |
| 819 |
$progressBarFill = elements.$progressBarFill, |
| 820 |
position = s.steps.indexOf( step ) + 1; |
| 821 |
total_size = s.steps.length, |
| 822 |
percent = Math.round( ( position / total_size ) * 100 ); |
| 823 |
|
| 824 |
// if we have a plugin_slug, then determine percentage wise where that slug is in the plugin_slug_list and override precent to add. |
| 825 |
if ( plugin_slug && plugin_slug_list.length > 0 ) { |
| 826 |
perecent = percent + 3; |
| 827 |
} |
| 828 |
|
| 829 |
if ( step === 'start' ) { |
| 830 |
percent = 0; |
| 831 |
} |
| 832 |
|
| 833 |
wpchar.debug( 'percent' ); |
| 834 |
wpchar.debug( percent ); |
| 835 |
|
| 836 |
$progressBarFill.css( 'width', percent + '%' ); |
| 837 |
|
| 838 |
} |
| 839 |
|
| 840 |
}; |
| 841 |
|
| 842 |
return app; |
| 843 |
|
| 844 |
}(document, window, jQuery)); // eslint-disable-line no-undef |
| 845 |
|
| 846 |
CharitableSetup.init(); |
| 847 |
|