sale-page.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. class SalePage {
  2. static InitSaleItemSection() {
  3. const $table = $("#sale-items-section table");
  4. const $checkboxes = $table.find("tbody input[type=checkbox]");
  5. const $allCheckbox = $("#sale-items-all-checkbox");
  6. const $batchActions = $(".batch-action");
  7. $allCheckbox.on("change", () => {
  8. const checked = $allCheckbox.prop("checked");
  9. $checkboxes.prop("checked", checked).trigger("change");
  10. });
  11. $checkboxes.on("change", () => {
  12. let batchActionsEnabled = $checkboxes.filter(":checked").length > 0;
  13. $batchActions.prop("disabled", !batchActionsEnabled);
  14. });
  15. $table.find(".btn-delete-sale-item").on("click", event => {
  16. const saleItemId = $(event.currentTarget).data("sale-item-id");
  17. const confirmed = confirm("Are you sure you want to delete this sale item?");
  18. if(confirmed) {
  19. $.post(window.location + "/delete-item", {
  20. sale_item_id: saleItemId
  21. }).then(response => {
  22. toastr.success("Sale item deleted successfully.");
  23. $("#sale-items-section").html(response.html);
  24. SalePage.InitSaleItemSection();
  25. });
  26. }
  27. });
  28. }
  29. }
  30. $(() => {
  31. SalePage.InitSaleItemSection();
  32. });