sale-page.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. class SalePage {
  2. static InitForm() {
  3. const $form = $("#sale-form");
  4. $form.on("submit", event => {
  5. event.preventDefault();
  6. SalePage.SaveForm();
  7. })
  8. }
  9. static InitSaleItemSection() {
  10. const $table = $("#sale-items-section table");
  11. const $checkboxes = $table.find("tbody input[type=checkbox]");
  12. const $allCheckbox = $("#sale-items-all-checkbox");
  13. const $batchActions = $(".batch-action");
  14. $allCheckbox.on("change", () => {
  15. const checked = $allCheckbox.prop("checked");
  16. $checkboxes.prop("checked", checked).trigger("change");
  17. });
  18. $checkboxes.on("change", () => {
  19. let batchActionsEnabled = $checkboxes.filter(":checked").length > 0;
  20. $batchActions.prop("disabled", !batchActionsEnabled);
  21. });
  22. $table.find(".btn-delete-sale-item").on("click", event => {
  23. const saleItemId = $(event.currentTarget).data("sale-item-id");
  24. swal.fire({
  25. icon: "question",
  26. title: "Deleting Item",
  27. text: "Are you sure you want to delete this lead item?",
  28. confirmButtonText: "Delete",
  29. showCancelButton: true
  30. }).then(result => {
  31. if(result.isConfirmed) {
  32. $.post(window.location + "/delete-item", {
  33. sale_item_id: saleItemId
  34. }).then(response => {
  35. toastr.success("Lead item deleted successfully.");
  36. $("#sale-items-section").html(response.html);
  37. SalePage.InitSaleItemSection();
  38. });
  39. }
  40. });
  41. });
  42. }
  43. static SaveForm() {
  44. const $form = $("#sale-form");
  45. const action = $form.get(0).action;
  46. const data = $form.serialize();
  47. const $submitElements = $form.find("[type=submit]");
  48. $submitElements.prop("disabled", true);
  49. return $.post(action, data).always(() => {
  50. $submitElements.prop("disabled", false);
  51. }).then(() => {
  52. toastr.success("Lead saved successfully.");
  53. });
  54. }
  55. }
  56. $(() => {
  57. SalePage.InitSaleItemSection();
  58. SalePage.InitForm();
  59. });