| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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");
- const confirmed = confirm("Are you sure you want to delete this item?");
- if(confirmed) {
- $.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"));
- });
- });
- }
- static SaveForm() {
- const $form = $("#document-form");
- const action = $form.get(0).action;
- const data = $form.serialize();
- const $submitElements = $form.find("[type=submit]");
- $submitElements.prop("disabled", true);
- return $.post(action, data).always(() => {
- $submitElements.prop("disabled", false);
- }).then(() => {
- toastr.success("Invoice saved successfully.");
- });
- }
- }
- $(() => {
- DocumentPage.InitForm();
- DocumentPage.InitItemsSection();
- DocumentPage.InitPdfActions();
- });
|