| 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-canvas-mode').on('click', '.wpfnl-single-item', function() { |
| 64 |
$('#wpfunnels-canvas-mode .wpfnl-single-item').removeClass('checked'); |
| 65 |
$(this).addClass('checked'); |
| 66 |
}); |
| 67 |
|
| 68 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")) { |
| 69 |
$("#wpfnl-utm").show() |
| 70 |
} else { |
| 71 |
$("#wpfnl-utm").hide() |
| 72 |
} |
| 73 |
$('#utm-enable').on('click', function () { |
| 74 |
if ($("input[name='wpfnl-utm-enable']").prop("checked")) { |
| 75 |
$("#wpfnl-utm").show() |
| 76 |
} else { |
| 77 |
$("#wpfnl-utm").hide() |
| 78 |
} |
| 79 |
}) |
| 80 |
|
| 81 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")) { |
| 82 |
$("#wpfnl-gtm").show() |
| 83 |
} else { |
| 84 |
$("#wpfnl-gtm").hide() |
| 85 |
} |
| 86 |
$('#gtm-enable').on('click', function () { |
| 87 |
if ($("input[name='wpfnl-gtm-enable']").prop("checked")) { |
| 88 |
$("#wpfnl-gtm").show() |
| 89 |
} else { |
| 90 |
$("#wpfnl-gtm").hide() |
| 91 |
} |
| 92 |
}) |
| 93 |
|
| 94 |
|
| 95 |
if ($("input[name='enable-skip-cart']").prop("checked")) { |
| 96 |
$(".wpfnl-skip-cart").show() |
| 97 |
} else { |
| 98 |
$(".wpfnl-skip-cart").hide() |
| 99 |
} |
| 100 |
$('#enable-skip-cart').on('click', function () { |
| 101 |
if ($("input[name='enable-skip-cart']").prop("checked")) { |
| 102 |
$(".wpfnl-skip-cart").show() |
| 103 |
} else { |
| 104 |
$(".wpfnl-skip-cart").hide() |
| 105 |
} |
| 106 |
}) |
| 107 |
|
| 108 |
|
| 109 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) { |
| 110 |
$("#wpfnl-facebook-pixel").show() |
| 111 |
} else { |
| 112 |
$("#wpfnl-facebook-pixel").hide() |
| 113 |
} |
| 114 |
$('#facebook-pixel-enable').on('click', function () { |
| 115 |
if ($("input[name='wpfnl-facebook-pixel-enable']").prop("checked")) { |
| 116 |
$("#wpfnl-facebook-pixel").show() |
| 117 |
} else { |
| 118 |
$("#wpfnl-facebook-pixel").hide() |
| 119 |
} |
| 120 |
}) |
| 121 |
|
| 122 |
enable_disable_recapcha() |
| 123 |
|
| 124 |
$('#recapcha-pixel-enable').on('click', function () { |
| 125 |
enable_disable_recapcha() |
| 126 |
}) |
| 127 |
|
| 128 |
$('.wpfnl-log-view').on('click', function (e) { |
| 129 |
e.preventDefault(); |
| 130 |
var thisElement = $(this); |
| 131 |
show_log(thisElement); |
| 132 |
}) |
| 133 |
|
| 134 |
$('.wpfnl-log-delete').on('click', function (e) { |
| 135 |
e.preventDefault(); |
| 136 |
var thisElement = $(this); |
| 137 |
delete_log(thisElement); |
| 138 |
}) |
| 139 |
|
| 140 |
/** |
| 141 |
* Show WPFunnels log |
| 142 |
*/ |
| 143 |
function show_log(thisElement) { |
| 144 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 145 |
|
| 146 |
var log_key = $('#wpfnl-log option:selected').val(); |
| 147 |
var payload = { |
| 148 |
'logKey': log_key |
| 149 |
}; |
| 150 |
if (!log_key) { |
| 151 |
$('#log-viewer pre').html(''); |
| 152 |
} else { |
| 153 |
wpAjaxHelperRequest('wpfnl-show-log', payload) |
| 154 |
.success(function (response) { |
| 155 |
thisElement.find('.wpfnl-loader').hide(); |
| 156 |
|
| 157 |
if (response.success) { |
| 158 |
$('#log-viewer pre').html(response.content); |
| 159 |
} |
| 160 |
}) |
| 161 |
.error(function (response) { |
| 162 |
}); |
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Show WPFunnels log |
| 169 |
*/ |
| 170 |
function delete_log(thisElement) { |
| 171 |
thisElement.find('.wpfnl-loader').css('display', 'inline-block'); |
| 172 |
localStorage.setItem("buttonClicked", true); |
| 173 |
|
| 174 |
var log_key = $('#wpfnl-log option:selected').val(); |
| 175 |
var payload = { |
| 176 |
'logKey': log_key |
| 177 |
}; |
| 178 |
if (!log_key) { |
| 179 |
$('#log-viewer').html(''); |
| 180 |
} else { |
| 181 |
wpAjaxHelperRequest('wpfnl-delete-log', payload) |
| 182 |
.success(function (response) { |
| 183 |
if (response.success) { |
| 184 |
$('#wpfnl-log option:selected').remove(); |
| 185 |
$('#log-viewer').empty(); |
| 186 |
} |
| 187 |
|
| 188 |
thisElement.find('.wpfnl-loader').hide(); |
| 189 |
|
| 190 |
}) |
| 191 |
.error(function (response) { |
| 192 |
}); |
| 193 |
} |
| 194 |
|
| 195 |
} |
| 196 |
|
| 197 |
var GeneralSettingsHandler = function () { |
| 198 |
$(document.body) |
| 199 |
.on('click', '#wpfnl-update-global-settings', this.updateGeneralSettings) |
| 200 |
.on('click', '#clear-template', this.clearTemplates) |
| 201 |
.on('click', '#clear-transients', this.clearTransients) |
| 202 |
|
| 203 |
/** |
| 204 |
* settings page Permalink Settings permalink |
| 205 |
* change on keyup |
| 206 |
* |
| 207 |
* @since 1.0.0 |
| 208 |
*/ |
| 209 |
$('code.stepbase').text($('input[name="wpfnl-permalink-step-base"]').val()); |
| 210 |
$('code.funnelbase').text($('input[name="wpfnl-permalink-funnel-base"]').val()); |
| 211 |
|
| 212 |
$('input[name="wpfnl-permalink-step-base"]').keyup(function () { |
| 213 |
if ($(this).val() != '') { |
| 214 |
$('code.stepbase').text($(this).val()); |
| 215 |
} else { |
| 216 |
$('code.stepbase').text('wpfunnels'); |
| 217 |
} |
| 218 |
}); |
| 219 |
|
| 220 |
$('input[name="wpfnl-permalink-funnel-base"]').keyup(function () { |
| 221 |
if ($(this).val() != '') { |
| 222 |
$('code.funnelbase').text($(this).val()); |
| 223 |
} else { |
| 224 |
$('code.funnelbase').text('step'); |
| 225 |
} |
| 226 |
}); |
| 227 |
|
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
/** |
| 232 |
* Read the usage-tracking toggle, but only report an actual change. |
| 233 |
* |
| 234 |
* The toggle carries the state it was rendered with in `data-initial` |
| 235 |
* ('yes' or 'no' — a site that has never been asked renders 'no', the |
| 236 |
* same as an explicit opt-out). Returning null for an untouched toggle |
| 237 |
* is what keeps an undecided site undecided. |
| 238 |
* |
| 239 |
* @returns {string|null} 'yes', 'no', or null when nothing changed. |
| 240 |
* @since 3.13.0 |
| 241 |
*/ |
| 242 |
function getTrackingConsentChange() { |
| 243 |
var $toggle = $('#wpfnl-allow-tracking'); |
| 244 |
|
| 245 |
if (!$toggle.length) { |
| 246 |
return null; |
| 247 |
} |
| 248 |
|
| 249 |
var current = $toggle.is(':checked') ? 'yes' : 'no'; |
| 250 |
|
| 251 |
return current === $toggle.data('initial') ? null : current; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/** |
| 256 |
* update general settings |
| 257 |
* |
| 258 |
* @param e |
| 259 |
* @since 1.0.0 |
| 260 |
*/ |
| 261 |
GeneralSettingsHandler.prototype.updateGeneralSettings = function (e) { |
| 262 |
e.preventDefault(); |
| 263 |
var userRole = {}; |
| 264 |
var permittedRole = {}; |
| 265 |
var gtmEvents = {}; |
| 266 |
var fbTrackEvent = {}; |
| 267 |
var advancedSettings = {}; |
| 268 |
$("input[name='analytics-role[]']").map(function () { |
| 269 |
if ($(this).prop("checked")) { |
| 270 |
userRole[$(this).data('role')] = 'true'; |
| 271 |
} |
| 272 |
return $(this).prop("checked") ? 1 : 0; |
| 273 |
}).get(); |
| 274 |
|
| 275 |
$("input[name='permission-role[]']").map(function () { |
| 276 |
if ($(this).prop("checked")) { |
| 277 |
permittedRole[$(this).data('role')] = 'true'; |
| 278 |
} |
| 279 |
return $(this).prop("checked") ? 1 : 0; |
| 280 |
}).get(); |
| 281 |
|
| 282 |
|
| 283 |
$("input[name='wpfnl-gtm-events[]']").map(function () { |
| 284 |
if ($(this).prop("checked")) { |
| 285 |
gtmEvents[$(this).data('role')] = 'true'; |
| 286 |
} |
| 287 |
return $(this).prop("checked") ? 1 : 0; |
| 288 |
}).get(); |
| 289 |
|
| 290 |
$("input[name='wpfnl-facebook_pixel_events[]']").map(function () { |
| 291 |
if ($(this).prop("checked")) { |
| 292 |
fbTrackEvent[$(this).data('role')] = 'true'; |
| 293 |
} |
| 294 |
return $(this).prop("checked") ? 1 : 0; |
| 295 |
}).get(); |
| 296 |
|
| 297 |
|
| 298 |
// get the role management values from settings |
| 299 |
var checkboxes = $('input[name="user_role[]"]'), |
| 300 |
userRoleManagement = window.WPFunnelVars.user_role_manager_data; |
| 301 |
|
| 302 |
checkboxes.each(function(checkbox) { |
| 303 |
var role = $(this).attr('data-role'); |
| 304 |
userRoleManagement[role] = $(this).is(":checked") ? 'yes' : 'no'; |
| 305 |
}); |
| 306 |
|
| 307 |
var payload = { |
| 308 |
'builder': $('#wpfunnels-page-builder .wpfnl-single-item.checked').attr('data-value'), |
| 309 |
'funnel_builder_mode': $('#wpfunnels-canvas-mode .wpfnl-single-item.checked').attr('data-value') || 'vertical', |
| 310 |
'uninstall_cleanup': $('#wpfnl-data-cleanup').is(':checked') ? 'on' : 'off', |
| 311 |
'paypal_reference': $('#wpfunnels-paypal-reference').is(':checked') ? 'on' : 'off', |
| 312 |
'analytics_roles': userRole, |
| 313 |
'permission_role': permittedRole, |
| 314 |
'order_bump': $('#wpfunnels-order-bump').is(':checked') ? 'on' : 'off', |
| 315 |
'ab_testing': $('#wpfunnels-ab-testing').is(':checked') ? 'on' : 'off', |
| 316 |
'permalink_settings': $("input[name='wpfunnels-set-permalink']:checked").val(), |
| 317 |
'permalink_step_base': $('#wpfunnels-permalink-step-base').val(), |
| 318 |
'permalink_funnel_base': $('#wpfunnels-permalink-funnel-base').val(), |
| 319 |
'sender_email': $('#wpfunnels-optin-sender-email').val(), |
| 320 |
'sender_name': $('#wpfunnels-optin-sender-name').val(), |
| 321 |
'email_subject': $('#wpfunnels-optin-email-subject').val(), |
| 322 |
'set_permalink': $('input[name="wpfunnels-set-permalink"]:checked').val(), |
| 323 |
'offer_orders': $('input[name="offer-orders"]:checked').val(), |
| 324 |
'skip_offer_step': $('#wpfnl-skip-offer-step').is(':checked') ? 'on' : 'off', |
| 325 |
'skip_offer_step_for_free': $('#wpfnl-skip-offer-step-for-free').is(':checked') ? 'on' : 'off', |
| 326 |
'skip_offer_for_recurring_buyer': $('#wpfnl-skip-offer-for-recurring-buyer').is(':checked') ? 'on' : 'off', |
| 327 |
'skip_offer_for_recurring_buyer_within_year': $('#wpfnl-skip-offer-for-recurring-buyer-within-year').is(':checked') ? 'on' : 'off', |
| 328 |
'show_supported_payment_gateway': $('#wpfnl-show-supported-payment-gateway').is(':checked') ? 'on' : 'off', |
| 329 |
'gtm_enable': $('input[name="wpfnl-gtm-enable"]:checked').val(), |
| 330 |
'gtm_container_id': $('#wpfnl-gtm-container-id').val(), |
| 331 |
'gtm_events': gtmEvents, |
| 332 |
'enable_fb_pixel': $('input[name="wpfnl-facebook-pixel-enable"]:checked').val(), |
| 333 |
'fb_tracking_code': $('#wpfnl-facebook-tracking-code').val(), |
| 334 |
'fb_tracking_events': fbTrackEvent, |
| 335 |
'utm_enable': $('input[name="wpfnl-utm-enable"]:checked').val(), |
| 336 |
'utm_source': $('#wpfnl-utm-source').val(), |
| 337 |
'utm_medium': $('#wpfnl-utm-medium').val(), |
| 338 |
'utm_campaign': $('#wpfnl-utm-campaign').val(), |
| 339 |
'utm_content': $('#wpfnl-utm-content').val(), |
| 340 |
'disable_theme_style': $('#disable-theme-style').is(':checked') ? 'on' : 'off', |
| 341 |
// Telemetry consent is stored by the Linno SDK, not in general |
| 342 |
// settings. Send it only when the toggle differs from what was |
| 343 |
// rendered so that saving an unrelated field never converts a |
| 344 |
// site that has simply never answered into an explicit "no". |
| 345 |
'allow_tracking': getTrackingConsentChange(), |
| 346 |
'enable_log_status': $('#enable-log-status').is(':checked') ? 'on' : 'off', |
| 347 |
'enable_skip_cart': $('#enable-skip-cart').is(':checked') ? 'on' : 'off', |
| 348 |
'skip_cart_for': $('input[name="skip-cart"]:checked').val(), |
| 349 |
'enable_recaptcha': $('input[name="wpfnl-recapcha-enable"]:checked').val(), |
| 350 |
'recaptcha_site_key': $('#wpfnl-recapcha-site-key').val(), |
| 351 |
'recaptcha_site_secret': $('#wpfnl-recapcha-site-secret').val(), |
| 352 |
'user_role_management': { roles: userRoleManagement }, |
| 353 |
'google_map_api_key' : $('#wpfnl-google-map-api-key').val(), |
| 354 |
'enable_global_thankyou' : $('#wpfnl-enable-global-thankyou').is(':checked') ? 'on' : 'off', |
| 355 |
'lms_provider' : $('#lms-provider-select').val(), |
| 356 |
'enable_revenue_report' : $('#wpfnl-enable-revenue-report').is(':checked') ? 'yes' : 'no', |
| 357 |
'revenue_report_frequency' : $('input[name="wpfnl-revenue-report-frequency"]:checked').val(), |
| 358 |
'revenue_report_recipient' : $('#wpfnl-revenue-report-recipient').val(), |
| 359 |
'revenue_report_subject' : $('#wpfnl-revenue-report-subject').val(), |
| 360 |
'send_time' : $('#wpfnl-send-time').val(), |
| 361 |
|
| 362 |
// AI Assistant and MCP settings are owned entirely by their own |
| 363 |
// Vue apps and REST endpoints now (see admin/src/settings-ai) — |
| 364 |
// each field there saves itself immediately. Do NOT send |
| 365 |
// ai_enabled/ai_provider/ai_*_key/ai_custom_instructions/ |
| 366 |
// mcp_enabled here: those selectors target markup that no |
| 367 |
// longer exists, so they always resolved to falsy/blank and |
| 368 |
// silently overwrote (disabled) whatever the Vue apps had just |
| 369 |
// saved the moment this button was clicked. |
| 370 |
}; |
| 371 |
|
| 372 |
// jQuery.param() serialises null as an empty string, which PHP would |
| 373 |
// read as an explicit "no". Drop the key entirely instead so an |
| 374 |
// untouched toggle sends nothing at all. |
| 375 |
if (null === payload.allow_tracking) { |
| 376 |
delete payload.allow_tracking; |
| 377 |
} |
| 378 |
|
| 379 |
var thisLoader = $(this).find('.wpfnl-loader'); |
| 380 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 381 |
|
| 382 |
thisLoader.fadeIn(); //show loader |
| 383 |
|
| 384 |
wpAjaxHelperRequest("update-general-settings", payload) |
| 385 |
.success(function (response) { |
| 386 |
thisLoader.fadeOut(); |
| 387 |
|
| 388 |
// The page is not reloaded after a save, so re-baseline the |
| 389 |
// consent toggle — otherwise a second change in the same |
| 390 |
// visit would compare against the stale rendered value and |
| 391 |
// never be sent. |
| 392 |
var $trackingToggle = $('#wpfnl-allow-tracking'); |
| 393 |
|
| 394 |
if ($trackingToggle.length) { |
| 395 |
$trackingToggle.data('initial', $trackingToggle.is(':checked') ? 'yes' : 'no'); |
| 396 |
} |
| 397 |
|
| 398 |
$('#wpfnl-toaster-wrapper').addClass('quick-toastify-successful-notification'); |
| 399 |
|
| 400 |
$('#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>'); |
| 401 |
|
| 402 |
$('#wpfnl-toaster-message').html('Saved Successfully') |
| 403 |
$('#wpfnl-toaster-wrapper').show(); |
| 404 |
|
| 405 |
setTimeout(function() { |
| 406 |
$('#wpfnl-toaster-wrapper').removeClass('quick-toastify-successful-notification'); |
| 407 |
$('#wpfnl-toaster-wrapper').hide(); |
| 408 |
}, 2000); |
| 409 |
|
| 410 |
}) |
| 411 |
.error(function (response) { |
| 412 |
thisLoader.fadeOut(); |
| 413 |
$('#wpfnl-toaster-wrapper').addClass('quick-toastify-warn-notification'); |
| 414 |
|
| 415 |
$('#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>'); |
| 416 |
|
| 417 |
$('#wpfnl-toaster-message').html('Erorr occurred') |
| 418 |
$('#wpfnl-toaster-wrapper').show(); |
| 419 |
setTimeout(function() { |
| 420 |
$('#wpfnl-toaster-wrapper').removeClass('quick-toastify-warn-notification'); |
| 421 |
$('#wpfnl-toaster-wrapper').hide(); |
| 422 |
}, 2000); |
| 423 |
}); |
| 424 |
|
| 425 |
}; |
| 426 |
|
| 427 |
|
| 428 |
GeneralSettingsHandler.prototype.clearTemplates = function (e) { |
| 429 |
e.preventDefault(); |
| 430 |
|
| 431 |
var $btn = $(this); |
| 432 |
var sync_icon = $btn.find('.icon-sync'); |
| 433 |
var check_icon = $btn.find('.check-icon'); |
| 434 |
var $textSpan = $btn.find('.sync-btn-text'); |
| 435 |
var thisAlert = $btn.siblings('.wpfnl-alert'); |
| 436 |
|
| 437 |
sync_icon.addClass('sync-icon'); |
| 438 |
|
| 439 |
var payload = {}; |
| 440 |
wpAjaxHelperRequest("clear-templates", payload) |
| 441 |
.success(function (response) { |
| 442 |
sync_icon.hide(); |
| 443 |
check_icon.fadeIn(); |
| 444 |
|
| 445 |
// Change text and add success style |
| 446 |
$textSpan.addClass('success'); |
| 447 |
$textSpan.text('Templates synced successfully'); |
| 448 |
$btn.css({ |
| 449 |
'border-color': '#239654', |
| 450 |
}); |
| 451 |
|
| 452 |
setTimeout(function () { |
| 453 |
sync_icon.removeClass('sync-icon').show(); |
| 454 |
check_icon.hide(); |
| 455 |
|
| 456 |
// Restore original text and style |
| 457 |
$textSpan.text('Sync Templates'); |
| 458 |
$textSpan.removeClass('success'); |
| 459 |
$btn.css({ |
| 460 |
'border-color': '', |
| 461 |
}); |
| 462 |
}, 2000); |
| 463 |
|
| 464 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 465 |
}) |
| 466 |
|
| 467 |
.error(function (response) { |
| 468 |
setTimeout(function () { |
| 469 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 470 |
}, 2000); |
| 471 |
console.log('error'); |
| 472 |
}); |
| 473 |
}; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
/** |
| 478 |
* clear all transients related to wpfunnels |
| 479 |
* |
| 480 |
* @param e |
| 481 |
*/ |
| 482 |
GeneralSettingsHandler.prototype.clearTransients = function (e) { |
| 483 |
e.preventDefault(); |
| 484 |
if (confirm('Are you sure you want to run this tool?')) { |
| 485 |
|
| 486 |
var sync_icon = $(this).find('.sync-icon'); |
| 487 |
var check_icon = $(this).find('.check-icon'); |
| 488 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 489 |
|
| 490 |
sync_icon.show(); |
| 491 |
|
| 492 |
var payload = {}; |
| 493 |
wpAjaxHelperRequest("clear-transient", payload) |
| 494 |
.success(function (response) { |
| 495 |
sync_icon.hide(); |
| 496 |
check_icon.fadeIn(); |
| 497 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 498 |
|
| 499 |
setTimeout(function () { |
| 500 |
check_icon.hide(); |
| 501 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 502 |
}, 4000); |
| 503 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 504 |
}) |
| 505 |
|
| 506 |
.error(function (response) { |
| 507 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 508 |
|
| 509 |
setTimeout(function () { |
| 510 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 511 |
}, 2000); |
| 512 |
console.log('error'); |
| 513 |
}); |
| 514 |
} |
| 515 |
}; |
| 516 |
|
| 517 |
|
| 518 |
GeneralSettingsHandler.prototype.clearTransients = function (e) { |
| 519 |
e.preventDefault(); |
| 520 |
if (confirm('Are you sure you want to run this tool?')) { |
| 521 |
|
| 522 |
var sync_icon = $(this).find('.sync-icon'); |
| 523 |
var check_icon = $(this).find('.check-icon'); |
| 524 |
var thisAlert = $(this).siblings('.wpfnl-alert'); |
| 525 |
|
| 526 |
sync_icon.show(); |
| 527 |
|
| 528 |
var payload = {}; |
| 529 |
wpAjaxHelperRequest("clear-transient", payload) |
| 530 |
.success(function (response) { |
| 531 |
sync_icon.hide(); |
| 532 |
check_icon.fadeIn(); |
| 533 |
thisAlert.text('Successful').addClass('wpfnl-success').fadeIn(); |
| 534 |
|
| 535 |
setTimeout(function () { |
| 536 |
check_icon.hide(); |
| 537 |
thisAlert.fadeOut().text('').removeClass('wpfnl-success'); |
| 538 |
}, 4000); |
| 539 |
$("#wpfnl-update-global-settings").trigger("click"); |
| 540 |
}) |
| 541 |
|
| 542 |
.error(function (response) { |
| 543 |
thisAlert.text('Erorr occurred').addClass('wpfnl-error').fadeIn(); |
| 544 |
|
| 545 |
setTimeout(function () { |
| 546 |
thisAlert.fadeOut().text('').removeClass('wpfnl-error'); |
| 547 |
}, 2000); |
| 548 |
|
| 549 |
console.log('error'); |
| 550 |
}); |
| 551 |
} |
| 552 |
}; |
| 553 |
|
| 554 |
new GeneralSettingsHandler(); |
| 555 |
|
| 556 |
$('.inner-tab').on('click', function () { |
| 557 |
$('.inner-tab').removeClass('active'); |
| 558 |
$('.wpfnl-tab-content').removeClass('active'); |
| 559 |
|
| 560 |
$(this).addClass('active'); |
| 561 |
var tabId = $(this).data('tab'); |
| 562 |
$('#' + tabId).addClass('active'); |
| 563 |
}); |
| 564 |
|
| 565 |
// Send test notification |
| 566 |
$('#wpfnl-send-test-notification').on('click', function(e) { |
| 567 |
e.preventDefault(); |
| 568 |
|
| 569 |
var $button = $(this); |
| 570 |
var $loader = $button.find('.wpfnl-loader'); |
| 571 |
var email = $('#wpfnl-test-notification-email').val(); |
| 572 |
|
| 573 |
if (!email || !isValidEmail(email)) { |
| 574 |
showToaster('error', 'Please enter a valid email address'); |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
$button.prop('disabled', true); |
| 579 |
$loader.fadeIn(); |
| 580 |
|
| 581 |
var payload = { |
| 582 |
'email': email |
| 583 |
}; |
| 584 |
|
| 585 |
wpAjaxHelperRequest('wpfnl-send-test-notification', payload) |
| 586 |
.success(function(response) { |
| 587 |
$loader.fadeOut(); |
| 588 |
$button.prop('disabled', false); |
| 589 |
|
| 590 |
if (response.success) { |
| 591 |
showToaster('success', response.message); |
| 592 |
} else { |
| 593 |
showToaster('error', response.message); |
| 594 |
} |
| 595 |
}) |
| 596 |
.error(function(response) { |
| 597 |
$loader.fadeOut(); |
| 598 |
$button.prop('disabled', false); |
| 599 |
showToaster('error', 'Error occurred while sending test email'); |
| 600 |
}); |
| 601 |
}); |
| 602 |
|
| 603 |
function isValidEmail(email) { |
| 604 |
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; |
| 605 |
return regex.test(email); |
| 606 |
} |
| 607 |
|
| 608 |
function showToaster(type, message) { |
| 609 |
var iconHtml = type === 'success' |
| 610 |
? '<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>' |
| 611 |
: '<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>'; |
| 612 |
|
| 613 |
var notificationClass = type === 'success' ? 'quick-toastify-successful-notification' : 'quick-toastify-warn-notification'; |
| 614 |
|
| 615 |
$('#wpfnl-toaster-wrapper').addClass(notificationClass); |
| 616 |
$('#wpfnl-toaster-icon').html(iconHtml); |
| 617 |
$('#wpfnl-toaster-message').html(message); |
| 618 |
$('#wpfnl-toaster-wrapper').show(); |
| 619 |
|
| 620 |
setTimeout(function() { |
| 621 |
$('#wpfnl-toaster-wrapper').removeClass(notificationClass); |
| 622 |
$('#wpfnl-toaster-wrapper').hide(); |
| 623 |
}, 3000); |
| 624 |
} |
| 625 |
|
| 626 |
}); |
| 627 |
|
| 628 |
}); |
| 629 |
|