| 1 |
jQuery(function ($) { |
| 2 |
|
| 3 |
'use strict'; |
| 4 |
$(document).ready(function ($) { |
| 5 |
/** |
| 6 |
* toggle password functionality on settings page |
| 7 |
*/ |
| 8 |
$(".toggle-eye-icon").click(function() { |
| 9 |
$('.toggle-eye-icon').removeClass('hide-eye-icon'); |
| 10 |
$(this).addClass('hide-eye-icon'); |
| 11 |
let input = $('#wpfnl-google-map-api-key'); |
| 12 |
if ( "password" === input.attr("type") ) { |
| 13 |
input.attr("type", "text"); |
| 14 |
} else { |
| 15 |
input.attr("type", "password"); |
| 16 |
} |
| 17 |
}); |
| 18 |
|
| 19 |
function toggleLogOptions() { |
| 20 |
const $checkbox = $('#enable-log-status'); |
| 21 |
const $logOptionsWrapper = $('.log-options-wrapper'); |
| 22 |
|
| 23 |
if (!$checkbox.length || !$logOptionsWrapper.length) return; |
| 24 |
|
| 25 |
$checkbox.on('change', function () { |
| 26 |
if ($(this).is(':checked')) { |
| 27 |
$logOptionsWrapper.show(); |
| 28 |
} else { |
| 29 |
$logOptionsWrapper.hide(); |
| 30 |
} |
| 31 |
}); |
| 32 |
} |
| 33 |
toggleLogOptions(); |
| 34 |
|
| 35 |
function enable_disable_recapcha() { |
| 36 |
if ($("input[name='wpfnl-recapcha-enable']").prop("checked")) { |
| 37 |
$("#wpfnl-recapcha").show() |
| 38 |
} else { |
| 39 |
$("#wpfnl-recapcha").hide() |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
// Toggle revenue report settings |
| 44 |
function toggleRevenueReportSettings() { |
| 45 |
if ($("#wpfnl-enable-revenue-report").is(':checked')) { |
| 46 |
$("#wpfnl-revenue-report-settings").show(); |
| 47 |
} else { |
| 48 |
$("#wpfnl-revenue-report-settings").hide(); |
| 49 |
} |
| 50 |
} |
| 51 |
toggleRevenueReportSettings(); |
| 52 |
|
| 53 |
$("#wpfnl-enable-revenue-report").on('change', function() { |
| 54 |
toggleRevenueReportSettings(); |
| 55 |
}); |
| 56 |
|
| 57 |
$('#wpfunnels-page-builder').on('click', '.wpfnl-single-item', function() { |
| 58 |
$('#wpfunnels-page-builder .wpfnl-single-item').removeClass('checked'); |
| 59 |
$(this).addClass('checked'); |
| 60 |
$('#clear-template').trigger('click'); |
| 61 |
}); |
| 62 |
|
| 63 |
$('#wpfunnels-funnel-type').on('click', '.wpfnl-single-item', function() { |
| 64 |
$('#wpfunnels-funnel-type .wpfnl-single-item').removeClass('checked'); |
| 65 |
$(this).addClass('checked'); |
| 66 |
$('#clear-template').trigger('click'); |
| 67 |
}); |
| 68 |
|
| 69 |
$('#wpfunnels-canvas-mode').on('click', '.wpfnl-single-item', function() { |
| 70 |
$('#wpfunnels-canvas-mode .wpfnl-single-item').removeClass('checked'); |
| 71 |
$(this).addClass('checked'); |
| 72 |
}); |
| 73 |
|
| 74 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")) { |
| 75 |
$("#wpfnl-utm").show() |
| 76 |
} else { |
| 77 |
$("#wpfnl-utm").hide() |
| 78 |
} |
| 79 |
$('#utm-enable').on('click', function () { |
| 80 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")) { |
| 81 |
$("#wpfnl-utm").show() |
| 82 |
} else { |
| 83 |
$("#wpfnl-utm").hide() |
| 84 |
} |
| 85 |
}) |
| 86 |
|
| 87 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")) { |
| 88 |
$("#wpfnl-gtm").show() |
| 89 |
} else { |
| 90 |
$("#wpfnl-gtm").hide() |
| 91 |
} |
| 92 |
$('#gtm-enable').on('click', function () { |
| 93 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")) { |
| 94 |
$("#wpfnl-gtm").show() |
| 95 |
} else { |
| 96 |
$("#wpfnl-gtm").hide() |
| 97 |
} |
| 98 |
}) |
| 99 |
|
| 100 |
|
| 101 |
if ($("input[name='enable-skip-cart']").prop("checked")) { |
| 102 |
$(".wpfnl-skip-cart").show() |
| 103 |
} else { |
| 104 |
$(".wpfnl-skip-cart").hide() |
| 105 |
} |
| 106 |
$('#enable-skip-cart').on('click', function () { |
| 107 |
if ($("input[name='enable-skip-cart']").prop("checked")) { |
| 108 |
$(".wpfnl-skip-cart").show() |
| 109 |
} else { |
| 110 |
$(".wpfnl-skip-cart").hide() |
| 111 |
} |
| 112 |
}) |
| 113 |
|
| 114 |
|
| 115 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) { |
| 116 |
$("#wpfnl-facebook-pixel").show() |
| 117 |
} else { |
| 118 |
$("#wpfnl-facebook-pixel").hide() |
| 119 |
} |
| 120 |
$('#facebook-pixel-enable').on('click', function () { |
| 121 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) { |
| 122 |
$("#wpfnl-facebook-pixel").show() |
| 123 |
} else { |
| 124 |
$("#wpfnl-facebook-pixel").hide() |
| 125 |
} |
| 126 |
}) |
| 127 |
|
| 128 |
enable_disable_recapcha() |
| 129 |
|
| 130 |
$('#recapcha-pixel-enable').on('click', function () { |
| 131 |
enable_disable_recapcha() |
| 132 |
}) |
| 133 |
|
| 134 |
$('.wpfnl-log-view').on('click', function (e) { |
| 135 |
e.preventDefault(); |
| 136 |
var thisElement = $(this); |
| 137 |
show_log(thisElement); |
| 138 |
}) |
| 139 |
|
| 140 |
$('.wpfnl-log-delete').on('click', function (e) { |
| 141 |
e.preventDefault(); |
| 142 |
var thisElement = $(this); |
| 143 |
delete_log(thisElement); |
| 144 |
}) |
| 145 |
|
| 146 |
/** |
| 147 |
* Show WPFunnels log |
| 148 |
*/ |
| 149 |
function show_log(thisElement) { |
| 150 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 151 |
|
| 152 |
var log_key = $('#wpfnl-log option:selected').val(); |
| 153 |
var payload = { |
| 154 |
'logKey': log_key |
| 155 |
}; |
| 156 |
if (!log_key) { |
| 157 |
$('#log-viewer pre').html(''); |
| 158 |
} else { |
| 159 |
wpAjaxHelperRequest('wpfnl-show-log', payload) |
| 160 |
.success(function (response) { |
| 161 |
thisElement.find('.wpfnl-loader').hide(); |
| 162 |
|
| 163 |
if (response.success) { |
| 164 |
$('#log-viewer pre').html(response.content); |
| 165 |
} |
| 166 |
}) |
| 167 |
.error(function (response) { |
| 168 |
}); |
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Show WPFunnels log |
| 175 |
*/ |
| 176 |
function delete_log(thisElement) { |
| 177 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 178 |
localStorage.setItem("buttonClicked", true); |
| 179 |
|
| 180 |
var log_key = $('#wpfnl-log option:selected').val(); |
| 181 |
var payload = { |
| 182 |
'logKey': log_key |
| 183 |
}; |
| 184 |
if (!log_key) { |
| 185 |
$('#log-viewer').html(''); |
| 186 |
} else { |
| 187 |
wpAjaxHelperRequest('wpfnl-delete-log', payload) |
| 188 |
.success(function (response) { |
| 189 |
if (response.success) { |
| 190 |
$('#wpfnl-log option:selected').remove(); |
| 191 |
$('#log-viewer').empty(); |
| 192 |
} |
| 193 |
|
| 194 |
thisElement.find('.wpfnl-loader').hide(); |
| 195 |
|
| 196 |
}) |
| 197 |
.error(function (response) { |
| 198 |
}); |
| 199 |
} |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
var GeneralSettingsHandler = function () { |
| 204 |
$(document.body) |
| 205 |
.on('click', '#wpfnl-update-global-settings', this.updateGeneralSettings) |
| 206 |
.on('click', '#clear-template', this.clearTemplates) |
| 207 |
.on('click', '#clear-transients', this.clearTransients) |
| 208 |
|
| 209 |
/** |
| 210 |
* settings page Permalink Settings permalink |
| 211 |
* change on keyup |
| 212 |
* |
| 213 |
* @since 1.0.0 |
| 214 |
*/ |
| 215 |
$('code.stepbase').text($('input[name="wpfnl-permalink-step-base"]').val()); |
| 216 |
$('code.funnelbase').text($('input[name="wpfnl-permalink-funnel-base"]').val()); |
| 217 |
|
| 218 |
$('input[name="wpfnl-permalink-step-base"]').keyup(function () { |
| 219 |
if ($(this).val() != '') { |
| 220 |
$('code.stepbase').text($(this).val()); |
| 221 |
} else { |
| 222 |
$('code.stepbase').text('wpfunnels'); |
| 223 |
} |
| 224 |
}); |
| 225 |
|
| 226 |
$('input[name="wpfnl-permalink-funnel-base"]').keyup(function () { |
| 227 |
if ($(this).val() != '') { |
| 228 |
$('code.funnelbase').text($(this).val()); |
| 229 |
} else { |
| 230 |
$('code.funnelbase').text('step'); |
| 231 |
} |
| 232 |
}); |
| 233 |
|
| 234 |
}; |
| 235 |
|
| 236 |
|
| 237 |
/** |
| 238 |
* update general settings |
| 239 |
* |
| 240 |
* @param e |
| 241 |
* @since 1.0.0 |
| 242 |
*/ |
| 243 |
GeneralSettingsHandler.prototype.updateGeneralSettings = function (e) { |
| 244 |
e.preventDefault(); |
| 245 |
var userRole = {}; |
| 246 |
var permittedRole = {}; |
| 247 |
var gtmEvents = {}; |
| 248 |
var fbTrackEvent = {}; |
| 249 |
var advancedSettings = {}; |
| 250 |
$("input[name='analytics-role[]']").map(function () { |
| 251 |
if ($(this).prop("checked")) { |
| 252 |
userRole[$(this).data('role')] = 'true'; |
| 253 |
} |
| 254 |
return $(this).prop("checked") ? 1 : 0; |
| 255 |
}).get(); |
| 256 |
|
| 257 |
$("input[name='permission-role[]']").map(function () { |
| 258 |
if ($(this).prop("checked")) { |
| 259 |
permittedRole[$(this).data('role')] = 'true'; |
| 260 |
} |
| 261 |
return $(this).prop("checked") ? 1 : 0; |
| 262 |
}).get(); |
| 263 |
|
| 264 |
|
| 265 |
$("input[name='wpfnl-gtm-events[]']").map(function () { |
| 266 |
if ($(this).prop("checked")) { |
| 267 |
gtmEvents[$(this).data('role')] = 'true'; |
| 268 |
} |
| 269 |
return $(this).prop("checked") ? 1 : 0; |
| 270 |
}).get(); |
| 271 |
|
| 272 |
$("input[name='wpfnl-facebook_pixel_events[]']").map(function () { |
| 273 |
if ($(this).prop("checked")) { |
| 274 |
fbTrackEvent[$(this).data('role')] = 'true'; |
| 275 |
} |
| 276 |
return $(this).prop("checked") ? 1 : 0; |
| 277 |
}).get(); |
| 278 |
|
| 279 |
|
| 280 |
// get the role management values from settings |
| 281 |
var checkboxes = $('input[name="user_role[]"]'), |
| 282 |
userRoleManagement = window.WPFunnelVars.user_role_manager_data; |
| 283 |
|
| 284 |
checkboxes.each(function(checkbox) { |
| 285 |
var role = $(this).attr('data-role'); |
| 286 |
userRoleManagement[role] = $(this).is(":checked") ? 'yes' : 'no'; |
| 287 |
}); |
| 288 |
|
| 289 |
var payload = { |
| 290 |
'funnel_type': $('#wpfunnels-funnel-type .wpfnl-single-item.checked').attr('data-value'), |
| 291 |
'builder': $('#wpfunnels-page-builder .wpfnl-single-item.checked').attr('data-value'), |
| 292 |
'funnel_builder_mode': $('#wpfunnels-canvas-mode .wpfnl-single-item.checked').attr('data-value') || 'horizontal', |
| 293 |
'uninstall_cleanup': $('#wpfnl-data-cleanup').is(':checked') ? 'on' : 'off', |
| 294 |
'paypal_reference': $('#wpfunnels-paypal-reference').is(':checked') ? 'on' : 'off', |
| 295 |
'analytics_roles': userRole, |
| 296 |
'permission_role': permittedRole, |
| 297 |
'order_bump': $('#wpfunnels-order-bump').is(':checked') ? 'on' : 'off', |
| 298 |
'ab_testing': $('#wpfunnels-ab-testing').is(':checked') ? 'on' : 'off', |
| 299 |
'permalink_settings': $("input[name='wpfunnels-set-permalink']:checked").val(), |
| 300 |
'permalink_step_base': $('#wpfunnels-permalink-step-base').val(), |
| 301 |
'permalink_funnel_base': $('#wpfunnels-permalink-funnel-base').val(), |
| 302 |
'sender_email': $('#wpfunnels-optin-sender-email').val(), |
| 303 |
'sender_name': $('#wpfunnels-optin-sender-name').val(), |
| 304 |
'email_subject': $('#wpfunnels-optin-email-subject').val(), |
| 305 |
'set_permalink': $('input[name="wpfunnels-set-permalink"]:checked').val(), |
| 306 |
'offer_orders': $('input[name="offer-orders"]:checked').val(), |
| 307 |
'skip_offer_step': $('#wpfnl-skip-offer-step').is(':checked') ? 'on' : 'off', |
| 308 |
'skip_offer_step_for_free': $('#wpfnl-skip-offer-step-for-free').is(':checked') ? 'on' : 'off', |
| 309 |
'skip_offer_for_recurring_buyer': $('#wpfnl-skip-offer-for-recurring-buyer').is(':checked') ? 'on' : 'off', |
| 310 |
'skip_offer_for_recurring_buyer_within_year': $('#wpfnl-skip-offer-for-recurring-buyer-within-year').is(':checked') ? 'on' : 'off', |
| 311 |
'show_supported_payment_gateway': $('#wpfnl-show-supported-payment-gateway').is(':checked') ? 'on' : 'off', |
| 312 |
'gtm_enable': $('input[name="wpfnl-gtm-enable"]:checked').val(), |
| 313 |
'gtm_container_id': $('#wpfnl-gtm-container-id').val(), |
| 314 |
'gtm_events': gtmEvents, |
| 315 |
'enable_fb_pixel': $('input[name="wpfnl-facebook-pixel-enable"]:checked').val(), |
| 316 |
'fb_tracking_code': $('#wpfnl-facebook-tracking-code').val(), |
| 317 |
'fb_tracking_events': fbTrackEvent, |
| 318 |
'utm_enable': $('input[name="wpfnl-utm-enable"]:checked').val(), |
| 319 |
'utm_source': $('#wpfnl-utm-source').val(), |
| 320 |
'utm_medium': $('#wpfnl-utm-medium').val(), |
| 321 |
'utm_campaign': $('#wpfnl-utm-campaign').val(), |
| 322 |
'utm_content': $('#wpfnl-utm-content').val(), |
| 323 |
'disable_theme_style': $('#disable-theme-style').is(':checked') ? 'on' : 'off', |
| 324 |
'enable_log_status': $('#enable-log-status').is(':checked') ? 'on' : 'off', |
| 325 |
'enable_skip_cart': $('#enable-skip-cart').is(':checked') ? 'on' : 'off', |
| 326 |
'skip_cart_for': $('input[name="skip-cart"]:checked').val(), |
| 327 |
'enable_recaptcha': $('input[name="wpfnl-recapcha-enable"]:checked').val(), |
| 328 |
'recaptcha_site_key': $('#wpfnl-recapcha-site-key').val(), |
| 329 |
'recaptcha_site_secret': $('#wpfnl-recapcha-site-secret').val(), |
| 330 |
'user_role_management': { roles: userRoleManagement }, |
| 331 |
'google_map_api_key' : $('#wpfnl-google-map-api-key').val(), |
| 332 |
'enable_global_thankyou' : $('#wpfnl-enable-global-thankyou').is(':checked') ? 'on' : 'off', |
| 333 |
'lms_provider' : $('#lms-provider-select').val(), |
| 334 |
'enable_revenue_report' : $('#wpfnl-enable-revenue-report').is(':checked') ? 'yes' : 'no', |
| 335 |
'revenue_report_frequency' : $('input[name="wpfnl-revenue-report-frequency"]:checked').val(), |
| 336 |
'revenue_report_recipient' : $('#wpfnl-revenue-report-recipient').val(), |
| 337 |
'revenue_report_subject' : $('#wpfnl-revenue-report-subject').val(), |
| 338 |
'send_time' : $('#wpfnl-send-time').val(), |
| 339 |
}; |
| 340 |
|
| 341 |
var thisLoader = $(this).find('.wpfnl-loader'); |
| 342 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 343 |
|
| 344 |
thisLoader.fadeIn(); //show loader |
| 345 |
|
| 346 |
wpAjaxHelperRequest("update-general-settings", payload) |
| 347 |
.success(function (response) { |
| 348 |
thisLoader.fadeOut(); |
| 349 |
$('#wpfnl-toaster-wrapper').addClass('quick-toastify-successful-notification'); |
| 350 |
|
| 351 |
$('#wpfnl-toaster-icon').html('<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#4BAE4F" fill-rule="evenodd" d="M13 0C5.83 0 0 5.83 0 13s5.83 13 13 13 13-5.83 13-13S20.17 0 13 0z" clip-rule="evenodd"/><path fill="#fff" fill-rule="evenodd" d="M19.287 8.618a.815.815 0 010 1.148l-7.617 7.617a.812.812 0 01-1.148 0l-3.808-3.809a.815.815 0 010-1.147.815.815 0 011.147 0l3.235 3.234 7.044-7.043a.806.806 0 011.147 0z" clip-rule="evenodd"/></svg>'); |
| 352 |
|
| 353 |
$('#wpfnl-toaster-message').html('Saved Successfully') |
| 354 |
$('#wpfnl-toaster-wrapper').show(); |
| 355 |
|
| 356 |
setTimeout(function() { |
| 357 |
$('#wpfnl-toaster-wrapper').removeClass('quick-toastify-successful-notification'); |
| 358 |
$('#wpfnl-toaster-wrapper').hide(); |
| 359 |
}, 2000); |
| 360 |
|
| 361 |
}) |
| 362 |
.error(function (response) { |
| 363 |
thisLoader.fadeOut(); |
| 364 |
$('#wpfnl-toaster-wrapper').addClass('quick-toastify-warn-notification'); |
| 365 |
|
| 366 |
$('#wpfnl-toaster-icon').html('<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#EC5956" fill-rule="evenodd" d="M26 13c0 7.18-5.82 13-13 13S0 20.18 0 13 5.82 0 13 0s13 5.82 13 13zm-11.375 6.5a1.625 1.625 0 11-3.25 0 1.625 1.625 0 013.25 0zM13 4.875c-.898 0-1.625.728-1.625 1.625V13a1.625 1.625 0 103.25 0V6.5c0-.897-.727-1.625-1.625-1.625z" clip-rule="evenodd"/></svg>'); |
| 367 |
|
| 368 |
$('#wpfnl-toaster-message').html('Erorr occurred') |
| 369 |
$('#wpfnl-toaster-wrapper').show(); |
| 370 |
setTimeout(function() { |
| 371 |
$('#wpfnl-toaster-wrapper').removeClass('quick-toastify-warn-notification'); |
| 372 |
$('#wpfnl-toaster-wrapper').hide(); |
| 373 |
}, 2000); |
| 374 |
}); |
| 375 |
|
| 376 |
}; |
| 377 |
|
| 378 |
|
| 379 |
GeneralSettingsHandler.prototype.clearTemplates = function (e) { |
| 380 |
e.preventDefault(); |
| 381 |
|
| 382 |
var $btn = $(this); |
| 383 |
var sync_icon = $btn.find('.icon-sync'); |
| 384 |
var check_icon = $btn.find('.check-icon'); |
| 385 |
var $textSpan = $btn.find('.sync-btn-text'); |
| 386 |
var thisAlert = $btn.siblings('.wpfnl-alert'); |
| 387 |
|
| 388 |
sync_icon.addClass('sync-icon'); |
| 389 |
|
| 390 |
var payload = {}; |
| 391 |
wpAjaxHelperRequest("clear-templates", payload) |
| 392 |
.success(function (response) { |
| 393 |
sync_icon.hide(); |
| 394 |
check_icon.fadeIn(); |
| 395 |
|
| 396 |
// Change text and add success style |
| 397 |
$textSpan.addClass('success'); |
| 398 |
$textSpan.text('Templates synced successfully'); |
| 399 |
$btn.css({ |
| 400 |
'border-color': '#239654', |
| 401 |
}); |
| 402 |
|
| 403 |
setTimeout(function () { |
| 404 |
sync_icon.removeClass('sync-icon').show(); |
| 405 |
check_icon.hide(); |
| 406 |
|
| 407 |
// Restore original text and style |
| 408 |
$textSpan.text('Sync Templates'); |
| 409 |
$textSpan.removeClass('success'); |
| 410 |
$btn.css({ |
| 411 |
'border-color': '', |
| 412 |
}); |
| 413 |
}, 2000); |
| 414 |
|
| 415 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 416 |
}) |
| 417 |
|
| 418 |
.error(function (response) { |
| 419 |
setTimeout(function () { |
| 420 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 421 |
}, 2000); |
| 422 |
console.log('error'); |
| 423 |
}); |
| 424 |
}; |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
/** |
| 429 |
* clear all transients related to wpfunnels |
| 430 |
* |
| 431 |
* @param e |
| 432 |
*/ |
| 433 |
GeneralSettingsHandler.prototype.clearTransients = function (e) { |
| 434 |
e.preventDefault(); |
| 435 |
if (confirm('Are you sure you want to run this tool?')) { |
| 436 |
|
| 437 |
var sync_icon = $(this).find('.sync-icon'); |
| 438 |
var check_icon = $(this).find('.check-icon'); |
| 439 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 440 |
|
| 441 |
sync_icon.show(); |
| 442 |
|
| 443 |
var payload = {}; |
| 444 |
wpAjaxHelperRequest("clear-transient", payload) |
| 445 |
.success(function (response) { |
| 446 |
sync_icon.hide(); |
| 447 |
check_icon.fadeIn(); |
| 448 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 449 |
|
| 450 |
setTimeout(function () { |
| 451 |
check_icon.hide(); |
| 452 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 453 |
}, 4000); |
| 454 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 455 |
}) |
| 456 |
|
| 457 |
.error(function (response) { |
| 458 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 459 |
|
| 460 |
setTimeout(function () { |
| 461 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 462 |
}, 2000); |
| 463 |
console.log('error'); |
| 464 |
}); |
| 465 |
} |
| 466 |
}; |
| 467 |
|
| 468 |
|
| 469 |
GeneralSettingsHandler.prototype.clearTransients = function (e) { |
| 470 |
e.preventDefault(); |
| 471 |
if (confirm('Are you sure you want to run this tool?')) { |
| 472 |
|
| 473 |
var sync_icon = $(this).find('.sync-icon'); |
| 474 |
var check_icon = $(this).find('.check-icon'); |
| 475 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 476 |
|
| 477 |
sync_icon.show(); |
| 478 |
|
| 479 |
var payload = {}; |
| 480 |
wpAjaxHelperRequest("clear-transient", payload) |
| 481 |
.success(function (response) { |
| 482 |
sync_icon.hide(); |
| 483 |
check_icon.fadeIn(); |
| 484 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 485 |
|
| 486 |
setTimeout(function () { |
| 487 |
check_icon.hide(); |
| 488 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 489 |
}, 4000); |
| 490 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 491 |
}) |
| 492 |
|
| 493 |
.error(function (response) { |
| 494 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 495 |
|
| 496 |
setTimeout(function () { |
| 497 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 498 |
}, 2000); |
| 499 |
|
| 500 |
console.log('error'); |
| 501 |
}); |
| 502 |
} |
| 503 |
}; |
| 504 |
|
| 505 |
new GeneralSettingsHandler(); |
| 506 |
|
| 507 |
$('.inner-tab').on('click', function () { |
| 508 |
$('.inner-tab').removeClass('active'); |
| 509 |
$('.wpfnl-tab-content').removeClass('active'); |
| 510 |
|
| 511 |
$(this).addClass('active'); |
| 512 |
var tabId = $(this).data('tab'); |
| 513 |
$('#' + tabId).addClass('active'); |
| 514 |
}); |
| 515 |
|
| 516 |
// Send test notification |
| 517 |
$('#wpfnl-send-test-notification').on('click', function(e) { |
| 518 |
e.preventDefault(); |
| 519 |
|
| 520 |
var $button = $(this); |
| 521 |
var $loader = $button.find('.wpfnl-loader'); |
| 522 |
var email = $('#wpfnl-test-notification-email').val(); |
| 523 |
|
| 524 |
if (!email || !isValidEmail(email)) { |
| 525 |
showToaster('error', 'Please enter a valid email address'); |
| 526 |
return; |
| 527 |
} |
| 528 |
|
| 529 |
$button.prop('disabled', true); |
| 530 |
$loader.fadeIn(); |
| 531 |
|
| 532 |
var payload = { |
| 533 |
'email': email |
| 534 |
}; |
| 535 |
|
| 536 |
wpAjaxHelperRequest('wpfnl-send-test-notification', payload) |
| 537 |
.success(function(response) { |
| 538 |
$loader.fadeOut(); |
| 539 |
$button.prop('disabled', false); |
| 540 |
|
| 541 |
if (response.success) { |
| 542 |
showToaster('success', response.message); |
| 543 |
} else { |
| 544 |
showToaster('error', response.message); |
| 545 |
} |
| 546 |
}) |
| 547 |
.error(function(response) { |
| 548 |
$loader.fadeOut(); |
| 549 |
$button.prop('disabled', false); |
| 550 |
showToaster('error', 'Error occurred while sending test email'); |
| 551 |
}); |
| 552 |
}); |
| 553 |
|
| 554 |
function isValidEmail(email) { |
| 555 |
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; |
| 556 |
return regex.test(email); |
| 557 |
} |
| 558 |
|
| 559 |
function showToaster(type, message) { |
| 560 |
var iconHtml = type === 'success' |
| 561 |
? '<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#4BAE4F" fill-rule="evenodd" d="M13 0C5.83 0 0 5.83 0 13s5.83 13 13 13 13-5.83 13-13S20.17 0 13 0z" clip-rule="evenodd"/><path fill="#fff" fill-rule="evenodd" d="M19.287 8.618a.815.815 0 010 1.148l-7.617 7.617a.812.812 0 01-1.148 0l-3.808-3.809a.815.815 0 010-1.147.815.815 0 011.147 0l3.235 3.234 7.044-7.043a.806.806 0 011.147 0z" clip-rule="evenodd"/></svg>' |
| 562 |
: '<svg width="26" height="26" fill="none" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg"><path fill="#EC5956" fill-rule="evenodd" d="M26 13c0 7.18-5.82 13-13 13S0 20.18 0 13 5.82 0 13 0s13 5.82 13 13zm-11.375 6.5a1.625 1.625 0 11-3.25 0 1.625 1.625 0 013.25 0zM13 4.875c-.898 0-1.625.728-1.625 1.625V13a1.625 1.625 0 103.25 0V6.5c0-.897-.727-1.625-1.625-1.625z" clip-rule="evenodd"/></svg>'; |
| 563 |
|
| 564 |
var notificationClass = type === 'success' ? 'quick-toastify-successful-notification' : 'quick-toastify-warn-notification'; |
| 565 |
|
| 566 |
$('#wpfnl-toaster-wrapper').addClass(notificationClass); |
| 567 |
$('#wpfnl-toaster-icon').html(iconHtml); |
| 568 |
$('#wpfnl-toaster-message').html(message); |
| 569 |
$('#wpfnl-toaster-wrapper').show(); |
| 570 |
|
| 571 |
setTimeout(function() { |
| 572 |
$('#wpfnl-toaster-wrapper').removeClass(notificationClass); |
| 573 |
$('#wpfnl-toaster-wrapper').hide(); |
| 574 |
}, 3000); |
| 575 |
} |
| 576 |
|
| 577 |
}); |
| 578 |
|
| 579 |
}); |
| 580 |
|