// ============ // Edit Popover // ============ $(document).ready(function () { var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}"); // ---------------------- // Initialize the Editor. // ---------------------- HcrRichText.create(document.querySelector('#popover_text')); // ----------- // Save Button // ----------- $(".btnSave").on("click", async function (e) { e.preventDefault(); $("#editPopover").submit(); }); // -------------- // Cancel Button. // -------------- $(".btnCancel").on("click", async function () { $sessionStorage.action = $sessionStorage.editPopover; sessionStorage.setItem($application, JSON.stringify($sessionStorage)); formSubmit($sessionStorage); }); // ------------- // Delete Button // ------------- $(".btnDelete").on("click", async function () { $("#confirm-dialog").removeClass().addClass("modal confirm-delete-popover") .find(".modal-title").html("Confirm Delete Popover").end() .find(".modal-body").html("Are you sure you wish to delete this Popover?").end() .modal("show"); }); $("body").on("click", ".confirm-delete-popover .btnConfirmDialogConfirm", async function () { $.post("./", {action: "Popovers.deletePopover", popover_serial: $sessionStorage.popover_serial}) .done(function () { $sessionStorage.action = $sessionStorage.editPopover || ""; sessionStorage.setItem($application, JSON.stringify($sessionStorage)); formSubmit($sessionStorage); }); }); // --------------- // Validate Inputs // --------------- $("#editPopover").submit(async function (e) { e.preventDefault(); var popover_serial = $("#popover_serial"), 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: popover_serial.val(), popover_name: popover_name.val()}) === true) { 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; $.post("./", $(this).serialize()) .done(function () { $sessionStorage.action = $sessionStorage.editPopover; sessionStorage.setItem($application, JSON.stringify($sessionStorage)); formSubmit($sessionStorage); }); }); });