new-sale-modal.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class NewSaleModal {
  2. constructor() {
  3. this.$modal = $("#new-sale-modal");
  4. this.modal = bootstrap.Modal.getInstance(this.$modal.get(0));
  5. this.$modal.on("show.bs.modal", event => this.onShow(event));
  6. this.$modal.on("shown.bs.modal", () => this.onShown());
  7. this.$modal.on("hidden.bs.modal", () => this.onHidden());
  8. this.$title = this.$modal.find(".modal-title");
  9. this.$form = this.$modal.find("form");
  10. this.$form.on("submit", event => this.onSubmit(event));
  11. this.$companyDropdown = this.getField("company_id");
  12. this.$locationDropdown = this.getField("location_id");
  13. this.$locationDropdown.select2({
  14. theme: "bootstrap-5",
  15. dropdownParent: this.$locationDropdown.closest("div")
  16. });
  17. }
  18. getField(name) {
  19. return this.$form.find(`[name=${name}]`);
  20. }
  21. // Modal lifecycle
  22. onShow(event) {
  23. const $element = $(event.relatedTarget);
  24. const data = $element.data();
  25. }
  26. onShown() {
  27. this.$companyDropdown.trigger("focus");
  28. }
  29. onHidden() {
  30. this.$form.get(0).reset();
  31. }
  32. onSubmit(event) {
  33. }
  34. }
  35. $(() => new NewSaleModal());