document-page.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class DocumentPage {
  2. static InitItemsSection() {
  3. const $table = $("#document-items-section table");
  4. const $checkboxes = $table.find("input[type=checkbox]");
  5. const $allCheckbox = $("#all-items-checkbox");
  6. $allCheckbox.on("change", () => {
  7. const checked = $allCheckbox.prop("checked");
  8. $checkboxes.prop("checked", checked);
  9. });
  10. $table.find(".btn-delete-document-item").on("click", event => {
  11. const documentItemId = $(event.currentTarget).data("document-item-id");
  12. const confirmed = confirm("Are you sure you want to delete this item?");
  13. if(confirmed) {
  14. $.post(window.location + "/delete-item", {
  15. document_item_id: documentItemId
  16. }).then(response => {
  17. toastr.success("Item deleted successfully.");
  18. $("#document-items-section").html(response.html);
  19. DocumentPage.InitItemsSection();
  20. });
  21. }
  22. });
  23. }
  24. static InitPdfActions() {
  25. const $form = $("#document-form");
  26. const action = $form.get(0).action;
  27. const $elements = $(".pdf-action");
  28. $elements.on("click", event => {
  29. event.preventDefault();
  30. const $element = $(event.currentTarget);
  31. const data = $form.serialize();
  32. $.post(action, data).then(() => {
  33. toastr.success("Invoice saved successfully.");
  34. window.open($element.attr("href"));
  35. });
  36. });
  37. }
  38. }
  39. $(() => {
  40. DocumentPage.InitItemsSection();
  41. DocumentPage.InitPdfActions();
  42. });