| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- class DocumentPage {
- static InitItemsSection() {
- const $table = $("#document-items-section table");
- const $checkboxes = $table.find("input[type=checkbox]");
- const $allCheckbox = $("#all-items-checkbox");
- $allCheckbox.on("change", () => {
- const checked = $allCheckbox.prop("checked");
- $checkboxes.prop("checked", checked);
- });
- $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 $form = $("#document-form");
- const action = $form.get(0).action;
- const $elements = $(".pdf-action");
- $elements.on("click", event => {
- event.preventDefault();
- const $element = $(event.currentTarget);
- const data = $form.serialize();
- $.post(action, data).then(() => {
- toastr.success("Invoice saved successfully.");
- window.open($element.attr("href"));
- });
- });
- }
- }
- $(() => {
- DocumentPage.InitItemsSection();
- DocumentPage.InitPdfActions();
- });
|