{"version":3,"file":"simple_form_controller-4OC_fCpo.js","sources":["../../../app/javascript/controllers/property/simple_form_controller.js"],"sourcesContent":["import PropertyController from \"../contact/property_controller\"\nimport { get } from \"@rails/request.js\";\n\nimport { useBatchUpdateNotifiers } from '../mixins/useBatchUpdateNotifiers'\n\nexport default class extends PropertyController {\n static values = {\n kind: String,\n searchUrl: String\n }\n\n static targets = [\"deleteButton\", \"menu\", \"batchUpdateClearAllCheckbox\"]\n\n initialize() {\n super.initialize()\n this.search = this.search.bind(this)\n }\n\n connect() {\n super.connect();\n this.propertyValue = this.element.dataset.propertyValue\n\n useBatchUpdateNotifiers(this, {\n onBatchUpdateCancellation: () => {\n if(this.blockedAnchor) {\n return this.blockedAnchor.click()\n }\n\n this.inputTarget.focus()\n },\n onBatchUpdateAbortion: () => {\n this.clearDebounce()\n this.blur()\n }\n })\n }\n\n saveChanges(e) {\n const { target } = e\n\n if(this.containerTarget.classList.contains(\"hidden\")\n || this.containerTarget.contains(target)\n || target === this.buttonTarget\n || this.buttonTarget.contains(target)\n || target === this.inputTarget\n || target.getAttribute('data-audience--contact-target') === 'checkbox'\n || target.closest('dialog')\n || this.isBlockedAnchor(e)\n ) return\n\n if(this.inBatchUpdateMode()) {\n if(this.inputTarget.value.trim().length > 0 || (this.hasOverrideCheckboxTarget && this.overrideCheckboxTarget.checked)) {\n return this.blockAnchorClickAndRequestBatchUpdateConfirmation(e)\n }\n }\n\n if(this.hasError) {\n return this.restore()\n }\n\n this.clearDebounce()\n\n if(this.propertyValue === this.inputTarget.value) {\n this.blur()\n } else if(!this.inputTarget.value) {\n this.formTarget.querySelector(\"input[name='_method']\").value = \"delete\"\n }\n\n if(this.inBatchUpdateMode()) {\n if(this.inputTarget.value.trim().length) {\n this.blockAnchorClickAndRequestBatchUpdateConfirmation(e)\n }\n\n return\n }\n\n this.formTarget.requestSubmit()\n }\n\n submit() {\n this.clearDebounce()\n\n if(this.element.closest('[data-mode=\"batch_update\"]') || (this.hasOverrideCheckbox && this.overrideCheckboxTarget.checked)) {\n return this.requestBatchUpdateConfirmation({\n property: this.element.dataset.property,\n value: this.inputTarget.value,\n })\n }\n\n if(this.inputTarget.value.trim().length === 0) {\n if(this.persistedValue && this.hasDeleteButtonTarget) {\n this.deleteButtonTarget.click()\n }\n } else {\n this.formTarget.requestSubmit()\n }\n }\n\n debounceSearch() {\n if(this.hasOverrideCheckboxTarget) {\n this.overrideCheckboxTarget.checked = this.inputTarget.value.trim().length > 0\n }\n\n if(this.inputTarget.value.trim().length === 0) {\n this.clearDebounce()\n\n if(this.hasMenuTarget) {\n this.menuTarget.classList.add(\"hidden\")\n }\n\n return\n }\n\n this.debounce(this.search)\n }\n\n blockAnchorClickAndRequestBatchUpdateConfirmation(e) {\n if(e.target.tagName === 'A' || e.target.closest('a')) {\n e.preventDefault()\n e.stopPropagation()\n\n this.blockedAnchor = e.target.closest('a') || e.target\n }\n\n this.requestBatchUpdateConfirmation()\n }\n\n async search() {\n await get(this.searchUrlValue, {\n responseKind: \"turbo-stream\",\n query: {\n search: this.inputTarget.value\n }\n })\n }\n\n set({ currentTarget }) {\n this.inputTarget.value = currentTarget.dataset.value\n this.submit()\n }\n\n unsetError() {\n super.unsetError()\n\n if(this.hasMenuTarget) {\n this.menuTarget.classList.replace(\"top-16\", \"top-12\")\n }\n }\n\n onOverrideCheckboxChange({ target }) {\n this.shouldOverride = target.checked\n this.focus()\n }\n\n onSubmitEnd() {\n super.onSubmitEnd()\n this.inputTarget.focus()\n }\n\n getValueForBatch() {\n return this.inputTarget.value\n }\n}\n"],"names":["simple_form_controller","PropertyController","useBatchUpdateNotifiers","e","target","get","currentTarget","__publicField"],"mappings":"4TAKe,MAAKA,UAASC,CAAmB,CAQ9C,YAAa,CACX,MAAM,WAAU,EAChB,KAAK,OAAS,KAAK,OAAO,KAAK,IAAI,CACvC,CAEE,SAAU,CACR,MAAM,QAAS,EACf,KAAK,cAAgB,KAAK,QAAQ,QAAQ,cAE1CC,EAAwB,KAAM,CAC5B,0B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