class TicketModal { constructor() { this.$modal = $("#ticket-modal"); this.modal = bootstrap.Modal.getInstance(this.$modal.get(0)); this.$modal.on("show.bs.modal", event => this.onShow(event)); this.$modal.on("shown.bs.modal", () => this.onShown()); this.$modal.on("hidden.bs.modal", () => this.onHidden()); this.$title = this.$modal.find(".modal-title"); this.$form = this.$modal.find("form"); this.$form.on("submit", event => this.onSubmit(event)); this.$subjectField = this.getField("subject"); this.$locationRow = $("#location-row"); this.$locationDropdown = this.getField("location_id"); this.$saleNumberField = this.getField("sale_number"); this.$aruNumberField = this.getField("aru_number"); this.$noLocationAction = $("#no-location-action"); this.$noLocationAction.on("click", event => { event.preventDefault(); this.onNoLocation(); }); this.$noLocationRow = $("#no-location-row"); this.$locationDropdown.select2({ theme: "bootstrap-5", dropdownParent: this.$locationDropdown.closest("div") }); } getField(name) { return this.$form.find(`[name=${name}]`); } // Modal lifecycle onShow(event) { const $element = $(event.relatedTarget); const data = $element.data(); const { locationId, saleNumber } = data; this.locationId = locationId; if(saleNumber) { this.$saleNumberField.val(saleNumber); } } onShown() { this.$subjectField.trigger("focus"); fetch("/locations/get-options").then(body => { return body.json() }).then(response => { const $options = response.options.map(option => { const $option = $(`