Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions assets/js/admin/form-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Sweetalert modal popup on reset content clicked.
$(document).on("click", ".ur-reset-content-button", function (event) {
event.preventDefault();
var editorIdFromButton = $(this).data("editor");
Swal.fire({
title: "Reset to Default",
text: "Are you sure you want to reset the email content to the default?",
Expand All @@ -31,28 +32,61 @@
var params = new URLSearchParams(window.location.search);
var section = params.get("section");
if (section) {
var selector = section.replace(
var baseSelector = section.replace(
/^ur_settings_/,
"user_registration_"
);
var editor =
typeof tinymce !== "undefined"
? tinymce.get(selector)
: null;
// Resolve the actual editor/textarea id. Prefer the
// data-editor attribute on the button, then fall back
// to the base selector (existing emails), then to the
// base + "_content" (newer emails like prevent
// concurrent login).
var candidates = [];
if (editorIdFromButton) {
candidates.push(editorIdFromButton);
}
candidates.push(baseSelector);
candidates.push(baseSelector + "_content");

var selector = null;
var editor = null;
for (var i = 0; i < candidates.length; i++) {
var candidate = candidates[i];
var candidateEditor =
typeof tinymce !== "undefined"
? tinymce.get(candidate)
: null;
if (candidateEditor) {
selector = candidate;
editor = candidateEditor;
break;
}
if ($("textarea#" + candidate).length) {
selector = candidate;
break;
}
}

if (!selector) {
return;
}

var defaultContent =
user_registration_email_settings &&
user_registration_email_settings[section];
if (typeof defaultContent === "undefined") {
return;
}

if (editor && !editor.isHidden()) {
var content = user_registration_email_settings[
section
]
var content = defaultContent
.replace(/\n\n/g, "<br>")
.replace(/\t/g, "");
editor.setContent(content);
} else {
var $textarea = $("textarea#" + selector);
if ($textarea.length) {
var content = user_registration_email_settings[
section
].replace(/\t/g, "");
$textarea.val(content);
$textarea.val(defaultContent.replace(/\t/g, ""));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/form-modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading