| 1 |
jQuery(document).ready(function ($) { |
| 2 |
var dialog = $("#wpf_deactivation_dialog_wrap"); |
| 3 |
|
| 4 |
var deactivateUrl = ''; |
| 5 |
|
| 6 |
$(document).on('click', '#the-list tr[data-plugin="wpforo/wpforo.php"] .deactivate a, #the-list tr[data-plugin="wpforo/wpforo.php"] a.wpforo-uninstall', function (e) { |
| 7 |
e.preventDefault(); |
| 8 |
dialog.fadeIn( 400, "linear" ); |
| 9 |
$('body').addClass('wpf-no-scroll'); |
| 10 |
deactivateUrl = $(this).attr('href'); |
| 11 |
return false; |
| 12 |
}); |
| 13 |
|
| 14 |
$(document).on("click", "#wpf_deactivation_dialog_wrap #wpf_deactivation_dialog_close", function () { |
| 15 |
if( dialog.is(':visible') ){ |
| 16 |
$('body').removeClass('wpf-no-scroll'); |
| 17 |
dialog.fadeOut( 50, "linear" ); |
| 18 |
} |
| 19 |
}); |
| 20 |
|
| 21 |
$(document).on("keydown", dialog, function (e) { |
| 22 |
if( dialog.is(':visible') ) { |
| 23 |
var keycode = e.code; |
| 24 |
if (keycode === 'Escape'){ |
| 25 |
$('body').removeClass('wpf-no-scroll'); |
| 26 |
dialog.fadeOut(50, "linear"); |
| 27 |
} |
| 28 |
} |
| 29 |
}); |
| 30 |
|
| 31 |
var parentItem = $('.wpf-deactivation-reason:checked').parents('.wpf-deactivation-reason-item'); |
| 32 |
$('.wpf-deactivation-reason-more-info').slideUp(500); |
| 33 |
$('.wpf-deactivation-reason-more-info', parentItem).slideDown(500); |
| 34 |
|
| 35 |
$(document).on('change', '.wpf-deactivation-reason', function (e) { |
| 36 |
$('.wpf-deactivation-reason-more-info').slideUp(500); |
| 37 |
var parentItem = $(this).parents('.wpf-deactivation-reason-item'); |
| 38 |
$('.wpf-deactivation-reason-more-info', parentItem).slideDown(500); |
| 39 |
}); |
| 40 |
|
| 41 |
$(document).on('click', '.wpf-deactivate', function (e) { |
| 42 |
if (isChecked($(this))) { |
| 43 |
var formData = ''; |
| 44 |
if ($(this).hasClass('wpf-submit')) { |
| 45 |
var checkedItem = $('.wpf-deactivation-reason:checked'); |
| 46 |
var parentItem = checkedItem.parents('.wpf-deactivation-reason-item'); |
| 47 |
var reasonDesc = $('textarea[name="wpforo_deactivation_reason_desc"]', parentItem); |
| 48 |
var reasonFeedback = $('input[name="wpforo_deactivation_feedback"]', parentItem); |
| 49 |
var reasonFeedbackEmail = $('input[name="wpforo_deactivation_feedback_email"]', parentItem); |
| 50 |
var reasonFeedbackEmailVal = ''; |
| 51 |
if( reasonFeedbackEmail.length ) reasonFeedbackEmailVal = reasonFeedbackEmail.val().trim(); |
| 52 |
var isValid = true; |
| 53 |
|
| 54 |
if (reasonDesc.length && reasonDesc.is(':visible')) { |
| 55 |
var attr = reasonDesc.attr('required'); |
| 56 |
if (typeof attr !== typeof undefined && attr !== false) { |
| 57 |
if (reasonDesc.val().length === 0) { |
| 58 |
isValid = false; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
if (isValid) { |
| 64 |
formData = 'deactivation_reason=' + checkedItem.val(); |
| 65 |
if (reasonDesc.length && reasonDesc.val().length > 0) { |
| 66 |
formData += '&deactivation_reason_desc=' + reasonDesc.val(); |
| 67 |
} |
| 68 |
$('.wpf-loading', this).toggleClass('wpforo-hidden'); |
| 69 |
} else { |
| 70 |
alert(wpforo_deactivation_obj.msgReasonDescRequired); |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
if( reasonFeedbackEmailVal.length !== 0 && !reasonFeedback.is(':checked') ){ |
| 75 |
alert( wpforo_deactivation_obj.msgFeedbackHasEmailNoCheckbox ); |
| 76 |
return false; |
| 77 |
} |
| 78 |
if( reasonFeedback.is(':checked') ){ |
| 79 |
if( reasonFeedbackEmailVal.length === 0 ){ |
| 80 |
alert( wpforo_deactivation_obj.msgFeedbackHasCheckboxNoEmail ); |
| 81 |
return false; |
| 82 |
}else{ |
| 83 |
if( isValidEmail( reasonFeedbackEmailVal ) ){ |
| 84 |
formData += '&deactivation_feedback_email=' + reasonFeedbackEmailVal; |
| 85 |
}else{ |
| 86 |
alert( wpforo_deactivation_obj.msgFeedbackNotValidEmail ); |
| 87 |
return false; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
} else { |
| 93 |
formData = 'never_show=1'; |
| 94 |
} |
| 95 |
|
| 96 |
if (formData) { |
| 97 |
$.ajax({ |
| 98 |
type: 'POST', |
| 99 |
url: ajaxurl, |
| 100 |
data: { |
| 101 |
action: 'wpforo_deactivate', |
| 102 |
deactivateData: formData |
| 103 |
} |
| 104 |
}).done(function (response) { |
| 105 |
try { |
| 106 |
var r = JSON.parse(response); |
| 107 |
var patt = new RegExp("https?\:\/\/"); |
| 108 |
var locHref = deactivateUrl ? ( patt.test(deactivateUrl) ? deactivateUrl : wpforo_deactivation_obj.adminUrl + deactivateUrl ) : location.href; |
| 109 |
if (r.code === 'dismiss_and_deactivate') { |
| 110 |
setTimeout(function () { |
| 111 |
location.href = locHref; |
| 112 |
}, 100); |
| 113 |
} else if (r.code === 'send_and_deactivate') { |
| 114 |
$('.wpf-deactivation-reason-form, .wpforo-thankyou').toggleClass('wpforo-hidden'); |
| 115 |
setTimeout(function () { |
| 116 |
location.href = locHref; |
| 117 |
}, 1000); |
| 118 |
} |
| 119 |
} catch (e) { |
| 120 |
console.log(e); |
| 121 |
} |
| 122 |
}); |
| 123 |
} |
| 124 |
} else { |
| 125 |
alert(wpforo_deactivation_obj.msgReasonRequired); |
| 126 |
} |
| 127 |
}); |
| 128 |
|
| 129 |
function isChecked(btn) { |
| 130 |
if (btn.hasClass('wpf-submit')) { |
| 131 |
var elem = $('.wpf-deactivation-reason-form input[name="wpforo_deactivation_reason"]'); |
| 132 |
for (var i = 0; i < elem.length; i++) { |
| 133 |
if (elem[i].type === 'radio' && elem[i].checked) { |
| 134 |
return true; |
| 135 |
} |
| 136 |
} |
| 137 |
return false; |
| 138 |
} |
| 139 |
return true; |
| 140 |
} |
| 141 |
|
| 142 |
function isValid() { |
| 143 |
if ($('.wpf_dr_more_info').is(':visible')) { |
| 144 |
return $('.wpf_dr_more_info:visible').length; |
| 145 |
} else { |
| 146 |
return true; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
function isValidEmail(email) { |
| 151 |
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| 152 |
return re.test(email); |
| 153 |
} |
| 154 |
|
| 155 |
}); |
| 156 |
|