{"version":3,"file":"date_controller-BCmiEi7u.js","sources":["../../../app/javascript/controllers/property/date_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nimport { KeyboardKey } from \"../compose/models\";\nimport { useLineNotifiers } from '../mixins/useLineNotifiers'\nimport { useBatchUpdateNotifiers } from '../mixins/useBatchUpdateNotifiers'\n\nexport default class extends ApplicationController {\n static values = {\n day: String,\n month: String,\n year: String,\n data: Object,\n }\n\n static targets = [\n \"day\",\n \"month\",\n \"year\",\n \"deleteButton\",\n \"displayError\",\n \"inputGroup\",\n \"form\",\n \"button\",\n \"container\",\n \"overrideCheckbox\",\n ]\n\n connect() {\n super.connect();\n\n this.dayValue = this.dayTarget.value\n this.monthValue = this.monthTarget.value\n this.yearValue = this.yearTarget.value\n\n useLineNotifiers(this)\n useBatchUpdateNotifiers(this, {\n onBatchUpdateCancellation: () => {\n if(this.blockedAnchor) {\n return this.blockedAnchor.click()\n }\n\n this.focus()\n },\n onBatchUpdateAbortion: () => this.restore()\n })\n }\n\n focus() {\n this.buttonTarget.classList.add(\"hidden\")\n this.containerTarget.classList.remove(\"hidden\")\n\n this.dayTarget.focus()\n this.nextTick(() => this.moveLineToThisElement())\n }\n\n blur() {\n this.buttonTarget.classList.remove(\"hidden\")\n this.containerTarget.classList.add(\"hidden\")\n this.blurLine()\n\n this.unsetError()\n\n this.overrideCheckboxTargets.forEach(checkbox => checkbox.checked = false)\n }\n\n onDayChange(e) {\n if(this.dayTarget.value.length === 2 || parseInt(this.dayTarget.value.charAt(0)) > 3) {\n this.monthTarget.focus()\n }\n\n if(this.dayTarget.nextElementSibling) {\n this.dayTarget.nextElementSibling.checked = this.dayTarget.value.length > 0\n }\n }\n\n onDayKeydown(e) {\n const key = KeyboardKey.fromKeyboardEvent(e)\n\n if(key.isRightArrow && (this.dayTarget.value.length === 2 || parseInt(this.dayTarget.value.charAt(0)) > 3)) {\n e.preventDefault()\n super.focus(this.monthTarget, { moveCursorToStart: true })\n }\n }\n\n onMonthKeydown(e) {\n const key = KeyboardKey.fromKeyboardEvent(e)\n\n if(key.isBackspace && this.monthTarget.value.length === 0) {\n this.dayTarget.focus()\n }\n\n if(key.isLeftArrow && this.monthTarget.selectionStart === 0) {\n e.preventDefault()\n this.dayTarget.focus()\n }\n\n if(key.isRightArrow && this.monthTarget.selectionStart === 2) {\n e.preventDefault()\n super.focus(this.yearTarget, { moveCursorToStart: true })\n }\n }\n\n onMonthChange() {\n if(this.monthTarget.value.length === 2 || parseInt(this.monthTarget.value.charAt(0)) > 1) {\n this.yearTarget.focus()\n }\n\n if(this.monthTarget.nextElementSibling) {\n this.monthTarget.nextElementSibling.checked = this.monthTarget.value.length > 0\n }\n }\n\n onYearChange() {\n if(this.yearTarget.nextElementSibling) {\n this.yearTarget.nextElementSibling.checked = this.yearTarget.value.length > 0\n }\n }\n\n onYearKeydown(e) {\n const key = KeyboardKey.fromKeyboardEvent(e)\n\n if(key.isBackspace && this.yearTarget.value.length === 0) {\n this.monthTarget.focus()\n }\n\n if(key.isLeftArrow && this.yearTarget.value.length === 0) {\n e.preventDefault()\n this.monthTarget.focus()\n }\n }\n\n moveCursor({ currentTarget, key }) {\n if(currentTarget.value.length === 0 && currentTarget === this.yearTarget && key === \"Backspace\") {\n this.moveSelectionToEndOfInput(this.monthTarget)\n this.monthTarget.focus()\n }\n\n if(currentTarget.value.length === 0 && currentTarget === this.monthTarget && key === \"Backspace\") {\n this.moveSelectionToEndOfInput(this.dayTarget)\n this.dayTarget.focus()\n }\n }\n\n saveChanges(e) {\n if(\n this.containerTarget.classList.contains(\"hidden\")\n || this.hasFocus\n || e.target.getAttribute('data-audience--contact-target') === 'checkbox'\n || this.containerTarget.contains(e.target)\n || this.isBlockedAnchor(e)\n ) return\n\n if(this.inBatchUpdateMode() && 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.submit()\n }\n\n submit() {\n if(this.inBatchUpdateMode() && this.dirty) {\n return this.requestBatchUpdateConfirmation()\n }\n\n if(!this.dirty) {\n return this.blur()\n }\n\n if(this.element.contains(document.activeElement)) {\n document.activeElement.blur()\n }\n\n this.inputGroupTarget.classList.add(\"readonly\")\n\n if(this.empty) {\n this.deleteButtonTarget.click()\n } else {\n this.formTarget.requestSubmit()\n }\n }\n\n restore() {\n this.blur()\n\n this.dayTarget.value = this.dataValue.day || \"\"\n this.monthTarget.value = this.dataValue.month || \"\"\n this.yearTarget.value = this.dataValue.year || \"\"\n\n this.unsetError()\n\n window.blockedAnchor = null\n }\n\n validatePastedContent(e) {\n const parsedClipboardData = parseInt(e.clipboardData.getData('text/plain'))\n\n if(isNaN(parsedClipboardData)) {\n this.showToast({\n message: this.translations.activerecord.errors.models['property/date'].attributes.invalid_pasted_content,\n type: 'error',\n autoHide: true\n })\n } else {\n e.target.value = parsedClipboardData\n }\n }\n\n onSubmitEnd() {\n this.inputGroupTarget.classList.remove(\"readonly\")\n this.dayTarget.focus()\n }\n\n onOverrideCheckboxChange({ target }) {\n target.previousElementSibling.focus()\n }\n\n // private\n\n unsetError() {\n this.element.querySelector('[data-error]')?.remove()\n }\n\n get dirty() {\n return (this.dayValue !== this.dayTarget.value)\n || (this.monthValue !== this.monthTarget.value)\n || (this.yearValue !== this.yearTarget.value)\n || this.overrideCheckboxTargets.some(checkbox => checkbox.checked)\n }\n\n get hasFocus() {\n return document.activeElement === this.dayTarget\n || document.activeElement === this.monthTarget\n || document.activeElement === this.yearTarget\n }\n\n get empty() {\n return this.dayTarget.value.trim().length === 0\n && this.monthTarget.value.trim().length === 0\n && this.yearTarget.value.trim().length === 0\n }\n\n get hasError() {\n return this.displayErrorTarget.classList.contains(\"hidden\")\n }\n\n getValueForBatch() {\n const object = {}\n\n if(this.dayTarget.value.length > 0 || this.dayTarget.nextElementSibling.checked) {\n object.day = this.dayTarget.value\n }\n\n if(this.monthTarget.value.length > 0 || this.monthTarget.nextElementSibling.checked) {\n object.month = this.monthTarget.value\n }\n\n if(this.yearTarget.value.length > 0 || this.yearTarget.nextElementSibling.checked) {\n object.year = this.yearTarget.value\n }\n\n return object\n }\n}\n"],"names":["DateController","ApplicationController","useLineNotifiers","useBatchUpdateNotifiers","checkbox","e","KeyboardKey","key","currentTarget","parsedClipboardData","target","_a","object","__publicField"],"mappings":"gXAMe,MAAKA,UAASC,CAAsB,CAqBjD,SAAU,CACR,MAAM,QAAS,EAEf,KAAK,SAAW,KAAK,UAAU,MAC/B,KAAK,WAAa,KAAK,YAAY,MACnC,KAAK,UAAY,KAAK,WAAW,MAEjCC,EAAiB,IAAI,EACrBC,EAAwB,KAAM,CAC5B,0BAA2B,IAAM,CAC/B,GAAG,KAAK,cACN,OAAO,KAAK,cAAc,MAAK,EAGjC,KAAK,MAAK,CACX,EACD,sBAAuB,IAAM,KAAK,QAAO,CAC1C,CAAA,CACL,CAEE,OAAQ,CACN,KAAK,aAAa,UAAU,IAAI,QAAQ,EACxC,KAAK,gBAAgB,UAAU,OAAO,QAAQ,EAE9C,KAAK,UAAU,MAAK,EACpB,KAAK,SAAS,IAAM,KAAK,sBAAuB,CAAA,CACpD,CAEE,MAAO,CACL,KAAK,aAAa,UAAU,OAAO,QAAQ,EAC3C,KAAK,gBAAgB,UAAU,IAAI,QAAQ,EAC3C,KAAK,SAAQ,EAEb,KAAK,WAAU,EAEf,KAAK,wBAAwB,QAAQC,GAAYA,EAAS,QAAU,EAAK,CAC7E,CAEE,YAAYC,EAAG,EACV,KAAK,UAAU,MAAM,SAAW,GAAK,SAAS,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,EAAI,IACjF,KAAK,YAAY,MAAK,EAGrB,KAAK,UAAU,qBAChB,KAAK,UAAU,mBAAmB,QAAU,KAAK,UAAU,MAAM,OAAS,EAEhF,CAEE,aAAaA,EAAG,CACFC,EAAY,kBAAkBD,CAAC,EAEpC,eAAiB,KAAK,UAAU,MAAM,SAAW,GAAK,SAAS,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,EAA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