generated from jric11/baseProject
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
|
|
// ===========
|
|
// Add 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();
|
|
|
|
$("#addPopover").submit();
|
|
|
|
});
|
|
|
|
// --------------
|
|
// Cancel Button.
|
|
// --------------
|
|
|
|
$(".btnCancel").on("click", async function () {
|
|
|
|
$sessionStorage.action = $sessionStorage.addPopover || "";
|
|
|
|
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
|
|
|
|
formSubmit($sessionStorage);
|
|
|
|
});
|
|
|
|
// ---------------
|
|
// Validate Inputs
|
|
// ---------------
|
|
|
|
$("#addPopover").submit(async function (e) {
|
|
e.preventDefault();
|
|
|
|
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) {
|
|
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.addPopover || "";
|
|
|
|
sessionStorage.setItem($application, JSON.stringify($sessionStorage));
|
|
|
|
formSubmit($sessionStorage);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}); |