{"version":3,"sources":["webpack:///./app/javascript/helpers/form.ts","webpack:///./app/javascript/schedules/elements/patient_checkin_element.ts"],"names":["createHiddenInput","name","value","input","document","createElement","type","PatientCheckinElement","registerElement","property","Boolean","Array","target","handleDropdownShown","bind","handleDropdownHidden","$","this","on","active","button","disabled","off","dropdown","emit","appendPatientIds","checkinForm","clearForm","removePatientIds","form","selectedPatientIds","id","hiddenInput","patientIdsName","append","from","querySelectorAll","forEach","remove","ImpulseElement"],"mappings":"2FAEO,SAASA,EAAkBC,EAAcC,GAC9C,IAAMC,EAAQC,SAASC,cAAc,SAIrC,OAHAF,EAAMG,KAAO,SACbH,EAAMF,KAAOA,EACbE,EAAMD,MAAQA,EACPC,EAPT,mC,m4FCIqBI,G,EADpBC,YAAgB,mB,EAKdC,YAAS,CAAEH,KAAMI,U,EAKjBD,YAAS,CAAEH,KAAMK,Q,EAKjBF,c,EAEAG,c,EACAA,c,EACAA,c,+TAED,aAAe,IAAD,S,4FAAA,WACZ,eADY,sJAEZ,EAAKC,oBAAsB,EAAKA,oBAAoBC,KAAzB,MAC3B,EAAKC,qBAAuB,EAAKA,qBAAqBD,KAA1B,MAHhB,E,sCASd,WACEE,EAAEC,MAAMC,GAAG,oBAAqBD,KAAKJ,qBACrCG,EAAEC,MAAMC,GAAG,qBAAsBD,KAAKF,sBAClCE,KAAKE,SACPF,KAAKG,OAAOC,UAAW,K,0BAO3B,WACEL,EAAEC,MAAMK,IAAI,oBAAqBL,KAAKJ,qBACtCG,EAAEC,MAAMK,IAAI,qBAAsBL,KAAKF,wB,2BAMzC,SAAcI,GACZF,KAAKG,OAAOC,UAAYF,I,qBAM1B,WACEH,EAAEC,MAAMM,SAAS,QACjBN,KAAKO,KAAK,a,iCAGZ,WACEP,KAAKQ,iBAAiBR,KAAKS,aAC3BT,KAAKQ,iBAAiBR,KAAKU,a,kCAG7B,WACEV,KAAKW,qB,8BAGP,SAAyBC,GAAwB,IAAD,MAC7BZ,KAAKa,oBADwB,IAC9C,2BAA0C,CAAC,IAAhCC,EAA+B,QAClCC,EAAchC,YAAkBiB,KAAKgB,eAAgBF,GAC3DF,EAAKK,OAAOF,IAHgC,iC,8BAOhD,WACuBrB,MAAMwB,KAAKlB,KAAKmB,iBAAL,iBAAgCnB,KAAKgB,eAArC,QACnBI,SAAQ,SAAClC,GAAD,OAAWA,EAAMmC,iB,iFA9ESC,K,sGAIX,K,iHAKoB,M","file":"js/68-a1716a5872cb187a2b48.chunk.js","sourcesContent":["/* eslint-disable import/prefer-default-export */\n\nexport function createHiddenInput(name: string, value: string) {\n const input = document.createElement('input');\n input.type = 'hidden';\n input.name = name;\n input.value = value;\n return input;\n}\n","import { ImpulseElement, property, registerElement, target } from '@ambiki/impulse';\nimport { createHiddenInput } from 'helpers/form';\n\n@registerElement('patient-checkin')\nexport default class PatientCheckinElement extends ImpulseElement {\n /**\n * Whether the element is active or not. If active, then attendance can be marked.\n */\n @property({ type: Boolean }) active = false;\n\n /**\n * An array of patient ids that were selected from the checkboxes.\n */\n @property({ type: Array }) selectedPatientIds: string[] = [];\n\n /**\n * The form name of the patient ids.\n */\n @property() patientIdsName: string;\n\n @target() button: HTMLButtonElement;\n @target() checkinForm: HTMLFormElement;\n @target() clearForm: HTMLFormElement;\n\n constructor() {\n super();\n this.handleDropdownShown = this.handleDropdownShown.bind(this);\n this.handleDropdownHidden = this.handleDropdownHidden.bind(this);\n }\n\n /**\n * Called when the element is added to the DOM.\n */\n connected() {\n $(this).on('shown.bs.dropdown', this.handleDropdownShown);\n $(this).on('hidden.bs.dropdown', this.handleDropdownHidden);\n if (this.active) {\n this.button.disabled = false;\n }\n }\n\n /**\n * Called when the element is removed from the DOM.\n */\n disconnected() {\n $(this).off('shown.bs.dropdown', this.handleDropdownShown);\n $(this).off('hidden.bs.dropdown', this.handleDropdownHidden);\n }\n\n /**\n * Called when the `active` property changes it's state.\n */\n activeChanged(active: boolean) {\n this.button.disabled = !active;\n }\n\n /**\n * Called when the patient has been checkedin successfully.\n */\n checked() {\n $(this).dropdown('hide');\n this.emit('checked');\n }\n\n private handleDropdownShown() {\n this.appendPatientIds(this.checkinForm);\n this.appendPatientIds(this.clearForm);\n }\n\n private handleDropdownHidden() {\n this.removePatientIds();\n }\n\n private appendPatientIds(form: HTMLFormElement) {\n for (const id of this.selectedPatientIds) {\n const hiddenInput = createHiddenInput(this.patientIdsName, id);\n form.append(hiddenInput);\n }\n }\n\n private removePatientIds() {\n const hiddenInputs = Array.from(this.querySelectorAll(`[name=\"${this.patientIdsName}\"]`));\n hiddenInputs.forEach((input) => input.remove());\n }\n}\n"],"sourceRoot":""}