| 1 |
// Deactivation Form |
| 2 |
jQuery(document).ready(function () { |
| 3 |
// NOTE: the "requirements" value below intentionally matches the literal |
| 4 |
// value="Plugin doesn\'t meet my requirements" attribute currently rendered |
| 5 |
// in includes/admin.php (the backslash is not a PHP-string escape there — |
| 6 |
// that markup is raw HTML, so it prints as a literal backslash character). |
| 7 |
var COMMENT_REQUIRED_REASONS = [ |
| 8 |
"I found a bug", |
| 9 |
"Plugin suddenly stopped working", |
| 10 |
"Plugin broke my site", |
| 11 |
"Other", |
| 12 |
"Plugin doesn\\'t meet my requirements", |
| 13 |
]; |
| 14 |
|
| 15 |
jQuery(document).on("click", function (e) { |
| 16 |
var popup = document.getElementById("dw-wpmcs-survey-form"); |
| 17 |
var overlay = document.getElementById("dw-wpmcs-survey-form-wrap"); |
| 18 |
var openButton = document.getElementById("deactivate-media-cloud-sync"); |
| 19 |
|
| 20 |
if (e.target.id == "dw-wpmcs-survey-form-wrap") { |
| 21 |
dwWpmcsClosePopup(); |
| 22 |
} |
| 23 |
if (e.target === openButton) { |
| 24 |
e.preventDefault(); |
| 25 |
popup.style.display = "block"; |
| 26 |
overlay.style.display = "block"; |
| 27 |
} |
| 28 |
if (e.target.id == "dw-wpmcs-skip") { |
| 29 |
e.preventDefault(); |
| 30 |
var urlRedirect = document |
| 31 |
.querySelector("a#deactivate-media-cloud-sync") |
| 32 |
.getAttribute("href"); |
| 33 |
window.location = urlRedirect; |
| 34 |
} |
| 35 |
if (e.target.id == "dw-wpmcs-cancel") { |
| 36 |
e.preventDefault(); |
| 37 |
dwWpmcsClosePopup(); |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
function dwWpmcsClosePopup() { |
| 42 |
var popup = document.getElementById("dw-wpmcs-survey-form"); |
| 43 |
var overlay = document.getElementById("dw-wpmcs-survey-form-wrap"); |
| 44 |
popup.style.display = "none"; |
| 45 |
overlay.style.display = "none"; |
| 46 |
jQuery("#dw-wpmcs-survey-form form")[0].reset(); |
| 47 |
jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").hide(); |
| 48 |
jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea").removeClass( |
| 49 |
"has-error" |
| 50 |
); |
| 51 |
dwWpmcsSetError(""); |
| 52 |
} |
| 53 |
|
| 54 |
jQuery("#dw-wpmcs-survey-form form").on("submit", function (e) { |
| 55 |
e.preventDefault(); |
| 56 |
var valid = dwWpmcsValidate(); |
| 57 |
if (valid) { |
| 58 |
var urlRedirect = document |
| 59 |
.querySelector("a#deactivate-media-cloud-sync") |
| 60 |
.getAttribute("href"); |
| 61 |
var form = jQuery(this); |
| 62 |
var formArray = form.serializeArray(); |
| 63 |
var jsonData = {}; |
| 64 |
formArray.forEach(function (item) { |
| 65 |
jsonData[item.name] = item.value; |
| 66 |
}); |
| 67 |
var actionUrl = |
| 68 |
"https://feedbacks.dudlewebs.com/api/submit-feedback.php"; |
| 69 |
jQuery.ajax({ |
| 70 |
type: "post", |
| 71 |
url: actionUrl, |
| 72 |
data: jsonData, |
| 73 |
dataType: "json", |
| 74 |
beforeSend: function () { |
| 75 |
jQuery("#dw-wpmcs-deactivate").prop("disabled", "disabled"); |
| 76 |
}, |
| 77 |
success: function (data) { |
| 78 |
window.location = urlRedirect; |
| 79 |
}, |
| 80 |
error: function (jqXHR, textStatus, errorThrown) { |
| 81 |
window.location = urlRedirect; |
| 82 |
}, |
| 83 |
}); |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea").on( |
| 88 |
"input", |
| 89 |
function () { |
| 90 |
dwWpmcsValidate(); |
| 91 |
} |
| 92 |
); |
| 93 |
|
| 94 |
jQuery("#dw-wpmcs-survey-form form input[type='radio']").on( |
| 95 |
"change", |
| 96 |
function () { |
| 97 |
var val = jQuery(this).val(); |
| 98 |
if (COMMENT_REQUIRED_REASONS.indexOf(val) !== -1) { |
| 99 |
jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").show(); |
| 100 |
} else { |
| 101 |
jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").hide(); |
| 102 |
} |
| 103 |
dwWpmcsValidate(); |
| 104 |
} |
| 105 |
); |
| 106 |
|
| 107 |
function dwWpmcsSetError(message) { |
| 108 |
jQuery("#dw-wpmcs-error-text").text(message); |
| 109 |
jQuery("#dw-wpmcs-error").toggleClass("is-visible", !!message); |
| 110 |
} |
| 111 |
|
| 112 |
function dwWpmcsValidate() { |
| 113 |
var reason = jQuery( |
| 114 |
"#dw-wpmcs-survey-form form input[name='reason']:checked" |
| 115 |
).val(); |
| 116 |
var $textarea = jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea"); |
| 117 |
$textarea.removeClass("has-error"); |
| 118 |
|
| 119 |
if (!reason) { |
| 120 |
dwWpmcsSetError("Please select a reason so we know how to improve"); |
| 121 |
return false; |
| 122 |
} |
| 123 |
|
| 124 |
if ( |
| 125 |
COMMENT_REQUIRED_REASONS.indexOf(reason) !== -1 && |
| 126 |
$textarea.val().trim().length <= 0 |
| 127 |
) { |
| 128 |
dwWpmcsSetError("Please add a few details so we can look into it"); |
| 129 |
$textarea.addClass("has-error"); |
| 130 |
return false; |
| 131 |
} |
| 132 |
|
| 133 |
dwWpmcsSetError(""); |
| 134 |
return true; |
| 135 |
} |
| 136 |
}); |
| 137 |
|