class DocumentPage { static InitForm() { const $form = $("#document-form"); $form.on("submit", event => { event.preventDefault(); DocumentPage.SaveForm(); }) } static InitItemsSection() { const $table = $("#document-items-section table"); const $checkboxes = $table.find("input[type=checkbox]"); const $allCheckbox = $("#all-items-checkbox"); const $batchActions = $(".batch-action"); $allCheckbox.on("change", () => { const checked = $allCheckbox.prop("checked"); $checkboxes.prop("checked", checked); }); $checkboxes.on("change", () => { let batchActionsEnabled = $checkboxes.filter(":checked").length > 0; $batchActions.prop("disabled", !batchActionsEnabled); }); $table.find(".btn-delete-document-item").on("click", event => { const documentItemId = $(event.currentTarget).data("document-item-id"); swal.fire({ icon: "question", title: "Deleting Item", text: "Are you sure you want to delete this item?", confirmButtonText: "Delete", showCancelButton: true }).then(result => { if(result.isConfirmed) { $.post(window.location + "/delete-item", { document_item_id: documentItemId }).then(response => { toastr.success("Item deleted successfully."); $("#document-items-section").html(response.html); DocumentPage.InitItemsSection(); }); } }); }); } static InitPdfActions() { const $elements = $(".pdf-action"); $elements.on("click", event => { event.preventDefault(); const $element = $(event.currentTarget); DocumentPage.SaveForm().then(() => { window.open($element.attr("href")); }); }); const $emailActions = $(".email-pdf-action"); $emailActions.on("click", event => { const $element = $(event.currentTarget); const { variant } = $element.data(); DocumentPage.SaveForm().then(() => { const showErrorAlert = (error) => { swal.fire("Error", error, "error"); }; const contactName = $("#contact-name").val(); if(!contactName) { showErrorAlert("Contact Name must be set.") return; } const contactEmail = $("#contact-email").val(); if(!contactEmail) { showErrorAlert("Contact Email must be set.") return; } const $p1 = $("
").text("Are you sure you want to email the PDF to:"); const $p2 = $("