{"version":3,"sources":["webpack:///./node_modules/core-js/modules/es.regexp.to-string.js","webpack:///./node_modules/core-js/modules/es.array.slice.js","webpack:///./src/js/modules/rif-partial.js"],"names":["anObject","fails","flags","DESCRIPTORS","nativeToString","NOT_GENERIC","call","source","INCORRECT_NAME","name","RegExp","prototype","R","this","concat","undefined","unsafe","isObject","isArray","toAbsoluteIndex","toLength","toIndexedObject","createProperty","SPECIES","nativeSlice","slice","max","Math","SPECIES_SUPPORT","target","proto","forced","start","end","Constructor","result","n","O","length","k","fin","constructor","Array","RifPartial","dom","$location","el","querySelector","$locationSelect","$programSelect","$form","$rif","document","selectText","innerHTML","styleSelect","getData","addEventListener","onSubmit","updatePrograms","defaultOptions","itemSelectText","searchEnabled","shouldSort","locationChoices","Choices","containerOuter","element","setAttribute","dataset","location","programChoices","program","locations","newLocation","newProgram","setChoices","map","value","label","customProperties","programs","enable","find","String","setChoiceByValue","setValue","url","rifEndpoint","currentLocation","currentProgram","axios","get","data","setLocationAndProgram","e","detail","choice","preventDefault","getFormObject","errors","createStep1ValidationSchema","validate","updateFormState","event","CustomEvent","window","dispatchEvent","rifPageUrl","form","count","resetFormStatus","forEach","err","field","path","error","classList","add","message","querySelectorAll","remove","obj","Schema","type","required","getErrorMessage","use","isPlaceholder","val","getAttribute","Component"],"mappings":"2FACA,IAAIA,EAAW,EAAQ,GACnBC,EAAQ,EAAQ,GAChBC,EAAQ,EAAQ,IAChBC,EAAc,EAAQ,GAEtBC,EAAiB,IAAa,SAE9BC,EAAcJ,GAAM,WAAc,MAA2D,QAApDG,EAAeE,KAAK,CAAEC,OAAQ,IAAKL,MAAO,SAEnFM,EALY,YAKKJ,EAAeK,MAIhCJ,GAAeG,IACjB,EAAQ,GAAR,CAAiCE,OAAOC,UAV1B,YAUgD,WAC5D,IAAIC,EAAIZ,EAASa,MACjB,MAAO,IAAIC,OAAOF,EAAEL,OAAQ,IAC1B,UAAWK,EAAIA,EAAEV,OAASC,GAAeS,aAAaF,OAASR,EAAMI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,IAAIC,EAAQ,EAmBZ,OAjBAjG,KAAKkG,gBAAgBF,GAErBT,EAAOY,SAAQ,SAAAC,GACb,IAAMC,EAAQL,EAAK9D,cAAL,sBAAkCkE,EAAIE,KAAtC,MACd,GAAID,EAAO,CACT,IAAME,EAAQF,EAAMnE,cAAc,uBAClCmE,EAAMG,UAAUC,IAAI,SACpBF,EAAM9D,UAAN,4IAGU2D,EAAIM,QAHd,iCAMAT,GAAgB,MAIbA,I,6BAGT,SAAgBD,GACdA,EAAKW,iBAAiB,uBAAuBR,SAAQ,SAAAlE,GACnD,IAAMsE,EAAQtE,EAAGC,cAAc,uBAC/BD,EAAGuE,UAAUI,OAAO,SACpBL,EAAM9D,UAAY,Q,2BAItB,SAAcuD,GACZ,IAAMa,EAAM,GAKZ,OAJAb,EAAKW,iBAAiB,uBAAuBR,SAAQ,SAAAlE,GACnD,IAAQoE,EAAUpE,EAAGuB,QAAb6C,MACRQ,EAAIR,GAASpE,EAAGC,cAAc,eAAe+B,SAExC4C,I,yCAGT,WAEE,OAAO,IAAIC,IAAO,CAChB,mBAAoB,CAClBC,KAAMxC,OACNyC,UAAU,EACVN,QAAS,CACPM,SAAUhH,KAAKiH,gBAAgB,mBAAoB,cAGvD,kBAAmB,CACjBF,KAAMxC,OACNyC,UAAU,EACVE,IAAK,CAAEC,cAZW,SAAAC,GAAG,MAAY,WAARA,IAazBV,QAAS,CACPM,SAAUhH,KAAKiH,gBAAgB,kBAAmB,YAClDC,IAAKlH,KAAKiH,gBAAgB,kBAAmB,kB,6BAMrD,SAAgBZ,EAAOU,GACrB,OAAO/G,KAAKiC,GAAGC,cAAR,sBAAqCmE,EAArC,MAA+CnE,cAAc,eAAemF,aAA5E,mBAAqGN,S,8BArKvFO,aAyKVxF","file":"25.d0e1653f8e4242466d5b.js","sourcesContent":["'use strict';\nvar anObject = require('../internals/an-object');\nvar fails = require('../internals/fails');\nvar flags = require('../internals/regexp-flags');\nvar DESCRIPTORS = require('../internals/descriptors');\nvar TO_STRING = 'toString';\nvar nativeToString = /./[TO_STRING];\n\nvar NOT_GENERIC = fails(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; });\n// FF44- RegExp#toString has a wrong name\nvar INCORRECT_NAME = nativeToString.name != TO_STRING;\n\n// `RegExp.prototype.toString` method\n// https://tc39.github.io/ecma262/#sec-regexp.prototype.tostring\nif (NOT_GENERIC || INCORRECT_NAME) {\n require('../internals/redefine')(RegExp.prototype, TO_STRING, function toString() {\n var R = anObject(this);\n return '/'.concat(R.source, '/',\n 'flags' in R ? R.flags : !DESCRIPTORS && R instanceof RegExp ? flags.call(R) : undefined);\n }, { unsafe: true });\n}\n","'use strict';\nvar isObject = require('../internals/is-object');\nvar isArray = require('../internals/is-array');\nvar toAbsoluteIndex = require('../internals/to-absolute-index');\nvar toLength = require('../internals/to-length');\nvar toIndexedObject = require('../internals/to-indexed-object');\nvar createProperty = require('../internals/create-property');\nvar SPECIES = require('../internals/well-known-symbol')('species');\nvar nativeSlice = [].slice;\nvar max = Math.max;\n\nvar SPECIES_SUPPORT = require('../internals/array-method-has-species-support')('slice');\n\n// `Array.prototype.slice` method\n// https://tc39.github.io/ecma262/#sec-array.prototype.slice\n// fallback for not array-like ES3 strings and DOM objects\nrequire('../internals/export')({ target: 'Array', proto: true, forced: !SPECIES_SUPPORT }, {\n slice: function slice(start, end) {\n var O = toIndexedObject(this);\n var length = toLength(O.length);\n var k = toAbsoluteIndex(start, length);\n var fin = toAbsoluteIndex(end === undefined ? length : end, length);\n // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible\n var Constructor, result, n;\n if (isArray(O)) {\n Constructor = O.constructor;\n // cross-realm fallback\n if (typeof Constructor == 'function' && (Constructor === Array || isArray(Constructor.prototype))) {\n Constructor = undefined;\n } else if (isObject(Constructor)) {\n Constructor = Constructor[SPECIES];\n if (Constructor === null) Constructor = undefined;\n }\n if (Constructor === Array || Constructor === undefined) {\n return nativeSlice.call(O, k, fin);\n }\n }\n result = new (Constructor === undefined ? Array : Constructor)(max(fin - k, 0));\n for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);\n result.length = n;\n return result;\n }\n});\n","import { Component } from '@verndale/core';\nimport axios from 'axios';\nimport Choices from 'choices.js';\nimport Schema from 'validate';\nimport serialize from 'form-serialize';\n\n\nclass RifPartial extends Component {\n setupDefaults() {\n this.dom = {\n $location: this.el.querySelector('[data-field=\"partial-location\"]'),\n $locationSelect: this.el.querySelector('[data-field=\"partial-location\"] .rif__field--select'),\n $programSelect: this.el.querySelector('[data-field=\"partial-program\"] .rif__field--select'),\n $form: this.el.querySelector('.rif-partial__form'),\n $rif: document.querySelector('.rif')\n };\n this.selectText = this.dom.$location.querySelector('option').innerHTML;\n this.styleSelect();\n this.getData();\n }\n\n addListeners() {\n this.dom.$form.addEventListener('submit', :: this.onSubmit);\n this.dom.$location.addEventListener('choice', :: this.updatePrograms);\n }\n\n styleSelect() {\n const defaultOptions = {\n itemSelectText: '',\n searchEnabled: false,\n shouldSort: false\n };\n this.locationChoices = new Choices(this.dom.$locationSelect, defaultOptions);\n this.locationChoices.containerOuter.element.setAttribute('aria-label', this.el.dataset.location);\n\n this.programChoices = new Choices(this.dom.$programSelect, defaultOptions);\n this.programChoices.containerOuter.element.setAttribute('aria-label', this.el.dataset.program);\n }\n\n setLocationAndProgram(locations, newLocation, newProgram) {\n if (locations && locations.length) {\n this.locationChoices\n .setChoices(locations.map(({ value, label, programs }) => (\n { value, label, customProperties: { programs } }\n )), 'value', 'label', false)\n .enable();\n\n if (location) {\n const location = locations.find(({ value }) => String(value) === String(newLocation));\n if (!location) return;\n this.locationChoices.setChoiceByValue(newLocation);\n\n const programs = [{ label: this.selectText, value: '' }, ...location.programs];\n this.programChoices\n .setValue({ label: this.selectText, value: 'select' })\n .setChoices(programs.map(({ value, label }) => (\n { value, label }\n )), 'value', 'label', true)\n .enable();\n\n if (newProgram && programs.find(({ value }) => String(value) === String(newProgram))) {\n this.programChoices.setChoiceByValue(newProgram);\n }\n }\n }\n }\n\n async getData() {\n const url = this.el.dataset.rifEndpoint;\n const currentLocation = this.el.dataset.currentLocation;\n const currentProgram = this.el.dataset.currentProgram;\n const { data } = await axios.get(url);\n\n this.setLocationAndProgram(data.locations, currentLocation, currentProgram)\n\n }\n\n updatePrograms(e) {\n let { programs } = e.detail.choice.customProperties;\n programs = [{ label: this.selectText, value: '' }, ...programs];\n this.programChoices\n .setValue({ label: this.selectText, value: 'select' })\n .setChoices(programs.map(({ value, label }) =>\n ({ value, label })\n ), 'value', 'label', true)\n .enable();\n }\n\n onSubmit(e) {\n e.preventDefault();\n const data = this.getFormObject(e.target);\n const errors = this.createStep1ValidationSchema().validate(data);\n this.updateFormState(errors, this.dom.$form);\n if (errors.length) return;\n const location = data['partial-location'];\n const program = data['partial-program']\n if (this.dom.$rif) {\n // eslint-disable-next-line no-undef\n const event = new CustomEvent(\n 'fill-rif-from-partial',\n { detail: { location, program } }\n );\n window.dispatchEvent(event);\n } else {\n const { rifPageUrl } = this.el.dataset;\n window.location = `${rifPageUrl}?location=${location}&program=${program}`\n }\n }\n\n updateFormState(errors, form) {\n let count = 0;\n\n this.resetFormStatus(form);\n\n errors.forEach(err => {\n const field = form.querySelector(`[data-field=${err.path}]`);\n if (field) {\n const error = field.querySelector('.rif__error-wrapper');\n field.classList.add('error');\n error.innerHTML = `\n \n \n ${err.message}\n \n `;\n count = count + 1;\n }\n })\n\n return count;\n }\n\n resetFormStatus(form) {\n form.querySelectorAll('.rif__field-wrapper').forEach(el => {\n const error = el.querySelector('.rif__error-wrapper');\n el.classList.remove('error');\n error.innerHTML = '';\n })\n }\n\n getFormObject(form) {\n const obj = {};\n form.querySelectorAll('.rif__field-wrapper').forEach(el => {\n const { field } = el.dataset;\n obj[field] = el.querySelector('.rif__field').value;\n })\n return obj;\n }\n\n createStep1ValidationSchema() {\n const isPlaceholder = val => val !== 'select';\n return new Schema({\n 'partial-location': {\n type: String,\n required: true,\n message: {\n required: this.getErrorMessage('partial-location', 'required')\n }\n },\n 'partial-program': {\n type: String,\n required: true,\n use: { isPlaceholder },\n message: {\n required: this.getErrorMessage('partial-program', 'required'),\n use: this.getErrorMessage('partial-program', 'required')\n }\n }\n })\n }\n\n getErrorMessage(field, type) {\n return this.el.querySelector(`[data-field=${field}]`).querySelector('.rif__field').getAttribute(`data-msg-${type}`);\n }\n}\n\nexport default RifPartial;\n"],"sourceRoot":""}