Files
huntingclubroster/js/addPopover.js
T

92 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-10-18 17:01:36 +00:00
// ===========
// Add Popover
// ===========
$(document).ready(function () {
var $application = $("#APPLICATION_MNEMONIC").val(),
$sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}");
2026-10-18 17:01:36 +00:00
// ----------------------
// Initialize the Editor.
// ----------------------
HcrRichText.create(document.querySelector('#popover_text'));
2026-10-18 17:01:36 +00:00
// -----------
// Save Button
// -----------
$(".btnSave").on("click", async function (e) {
2026-10-18 17:01:36 +00:00
e.preventDefault();
$("#addPopover").submit();
});
// --------------
// Cancel Button.
// --------------
$(".btnCancel").on("click", async function () {
2026-10-18 17:01:36 +00:00
$sessionStorage.action = $sessionStorage.addPopover || "";
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
formSubmit($sessionStorage);
});
// ---------------
// Validate Inputs
// ---------------
$("#addPopover").submit(async function (e) {
e.preventDefault();
2026-10-18 17:01:36 +00:00
var popover_name = $("#popover_name"),
popover_title = $("#popover_title"),
popover_text = $("#popover_text");
clearInputErrors();
popover_name.val(popover_name.val().replace(/\s+/g, " ").trim());
popover_title.val(popover_title.val().replace(/\s+/g, " ").trim());
if (isBlank(popover_name)) {
createInputError(popover_name, "Name is required");
return false;
}
if (await formPost({action: "Popovers.popoverExists", popover_serial: 0, popover_name: popover_name.val()}) === true) {
2026-10-18 17:01:36 +00:00
createInputError(popover_name, "Name already exists");
return false;
}
if (isBlank(popover_title)) {
createInputError(popover_title, "Title is required");
return false;
}
e.preventDefault();
if (!HcrRichText.sync(document.querySelector('#popover_text'))) return;
2026-10-18 17:01:36 +00:00
$.post("./", $(this).serialize())
.done(function () {
$sessionStorage.action = $sessionStorage.addPopover || "";
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
formSubmit($sessionStorage);
});
});
});