{"version":3,"sources":["webpack:///./src/feature/gastrivix-calculator/gastrivix-calculator.js"],"names":["classes","section","checked","active","errorMessageVisible","hidden","dev","debuggingData","summary","returnOnInvestment","farmersMarginIncrease","EPEF","farmersIncomeExtra","fields","StarterFeedConsumption","GrowerFeedConsumption","FinisherFeedConsumption","defaultSettings","endpoint","GastrivixCalculator","element","el","settings","Object","assign","parseSettings","sections","querySelectorAll","nextButtons","previousButtons","submitButton","querySelector","errorMessage","openOnSummary","loadDataOnSelect","currentSection","prevSection","trackFlow","getAttribute","initDomCache","addEventListeners","initForm","forEach","button","addEventListener","handlePrevious","handleNext","e","inProgress","selectedItem","options","selectedIndex","value","selectName","name","formData","updateFields","getSelectData","dom","form","preventDefault","validateForm","formToJson","log","trackSection","id","renderSummary","sendForm","fetch","method","mode","headers","body","JSON","stringify","then","response","handleErrors","json","success","showErrorMessage","hideErrorMessage","catch","err","status","data","request","validate","ignore","signInForm","closest","nextSection","nextElementSibling","validateSection","classList","add","publish","scroll","previousElementSibling","remove","offsetSection","contains","entries","key","target","innerText","signInButton","parse","itemObj","fieldsets","i","length","isDisabled","attr","item","slice","call","fieldsetData","reduce","type","isValidValue","dataset","fieldName","Name","Id","push","includes","isValid","invalidAnswer","field","valid","formValid","$target","stop","animate","scrollTop","offset","top","ok","Error","statusText","formId","isSubmitted","formStepCompleted","textContent","window","dataLayer","event","console","BaseFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;AACA;;;;;;;;;;;;;;AAEA,IAAMA,UAAU;AACfC,UAAS,iBADM;AAEfC,UAAS,0BAFM;AAGfC,SAAQ,yBAHO;AAIfC,sBAAqB,yCAJN;AAKfC,SAAQ;AALO,CAAhB;;AAQA,IAAMC,MAAM,KAAZ;;AAEA,IAAMC,gBAAgB;AACrBC,UAAS;AACRC,sBAAoB,KADZ;AAERC,yBAAuB,IAFf;AAGRC,QAAM,OAHE;AAIRC,sBAAoB;AAJZ,EADY;AAOrBC,SAAQ;AACPC,0BAA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B;AAKA;AACDO,WAAQrF,GAAR,CAAY,WAAZ,EAAyBkF,OAAOC,SAAhC;AACA;;;;EA9V+CG,c;;kBAA5BlI,mB","file":"15-d880d4af.pkg.js","sourcesContent":["import $ from 'jquery';\r\nimport 'jquery-validation';\r\nimport BaseFeature from '../../foundation/base/base';\r\n\r\nconst classes = {\r\n\tsection: 'o-question-view',\r\n\tchecked: 'o-question-view--checked',\r\n\tactive: 'o-question-view--active',\r\n\terrorMessageVisible: 'o-question-view__error-message--visible',\r\n\thidden: 'u-hide'\r\n};\r\n\r\nconst dev = false;\r\n\r\nconst debuggingData = {\r\n\tsummary: {\r\n\t\treturnOnInvestment: '2:1',\r\n\t\tfarmersMarginIncrease: '55',\r\n\t\tEPEF: '945.5',\r\n\t\tfarmersIncomeExtra: '70 456'\r\n\t},\r\n\tfields: {\r\n\t\tStarterFeedConsumption: '0.333',\r\n\t\tGrowerFeedConsumption: '1.333',\r\n\t\tFinisherFeedConsumption: '3.333'\r\n\t}\r\n};\r\n\r\nconst defaultSettings = {\r\n\tendpoint: '/'\r\n};\r\n\r\nexport default class GastrivixCalculator extends BaseFeature {\r\n\tconstructor(element) {\r\n\t\tsuper(element);\r\n\t\tthis.el = element;\r\n\t\tthis.settings = Object.assign({}, defaultSettings, this.parseSettings());\r\n\t\tthis.sections = this.el.querySelectorAll('[data-section]');\r\n\t\tthis.nextButtons = this.el.querySelectorAll('[data-js=next-section]');\r\n\t\tthis.previousButtons = this.el.querySelectorAll('[data-js=previous-section]');\r\n\t\tthis.submitButton = this.el.querySelector('[data-js=submit]');\r\n\t\tthis.errorMessage = this.el.querySelector('[data-js=\"error-message\"]');\r\n\t\tthis.openOnSummary = this.el.querySelector('[data-open-on-summary]');\r\n\t\tthis.loadDataOnSelect = this.el.querySelector('[data-js=load-data-on-select');\r\n\t\t[this.currentSection] = this.sections;\r\n\t\tthis.prevSection = null;\r\n\t\tthis.trackFlow = this.el.getAttribute('data-track-flow');\r\n\t\tthis.initDomCache();\r\n\t\tthis.addEventListeners();\r\n\t\tthis.initForm();\r\n\t}\r\n\r\n\taddEventListeners() {\r\n\t\tthis.previousButtons.forEach((button) => {\r\n\t\t\tthis.addEventListener(button, 'click', () => {\r\n\t\t\t\tthis.handlePrevious(button);\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\tthis.nextButtons.forEach((button) => {\r\n\t\t\tthis.addEventListener(button, 'click', () => {\r\n\t\t\t\tthis.handleNext(button);\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\tif (this.loadDataOnSelect) {\r\n\t\t\tthis.addEventListener(this.loadDataOnSelect, 'change', (e) => {\r\n\t\t\t\tif (this.inProgress) return;\r\n\r\n\t\t\t\tconst selectedItem = this.loadDataOnSelect\r\n\t\t\t\t\t.options[this.loadDataOnSelect.selectedIndex]\r\n\t\t\t\t\t.value;\r\n\r\n\t\t\t\tconst selectName = this.loadDataOnSelect.name;\r\n\r\n\t\t\t\tconst formData = {\r\n\t\t\t\t\t[selectName]: selectedItem\r\n\t\t\t\t};\r\n\r\n\t\t\t\tif (dev) {\r\n\t\t\t\t\t// Mock a succesfull response\r\n\t\t\t\t\tthis.updateFields(debuggingData.fields);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.getSelectData(formData);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (this.dom.form) {\r\n\t\t\tthis.addEventListener(this.dom.form, 'submit', (e) => {\r\n\t\t\t\te.preventDefault();\r\n\t\t\t\tif (!GastrivixCalculator.validateForm(this.dom.form) || this.inProgress) return;\r\n\t\t\t\tconst formData = GastrivixCalculator.formToJson(this.dom.form);\r\n\t\t\t\tif (dev) {\r\n\t\t\t\t\t// Mock a succesfull response\r\n\t\t\t\t\tthis.log(formData);\r\n\t\t\t\t\tGastrivixCalculator.trackSection(this.currentSection, this.dom.form.id);\r\n\t\t\t\t\tthis.renderSummary(debuggingData.summary);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.sendForm(formData);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tsendForm(formData) {\r\n\t\tthis.inProgress = true;\r\n\t\treturn fetch(this.settings.endpoint, {\r\n\t\t\tmethod: 'POST',\r\n\t\t\tmode: 'same-origin',\r\n\t\t\theaders: {\r\n\t\t\t\t'Content-Type': 'Application/json; charset=utf-8'\r\n\t\t\t},\r\n\t\t\tbody: JSON.stringify(formData)\r\n\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tGastrivixCalculator.handleErrors(response);\r\n\t\t\t\treturn response.json();\r\n\t\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tif (!response.success) {\r\n\t\t\t\t\tthis.showErrorMessage();\r\n\t\t\t\t\tthis.inProgress = false;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.renderSummary(response.summary);\r\n\t\t\t\t\tGastrivixCalculator.trackSection(this.currentSection, this.dom.form.id);\r\n\t\t\t\t\tthis.hideErrorMessage();\r\n\t\t\t\t\tthis.inProgress = false;\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t.catch((err) => {\r\n\t\t\t\tif (err.response) {\r\n\t\t\t\t\t// Client received an error response (5xx, 4xx)\r\n\t\t\t\t\tthis.log('Response Error', `${err.response.status}: ${err.response.data}`);\r\n\t\t\t\t} else if (err.request) {\r\n\t\t\t\t\t// Client never received a response, or request never left\r\n\t\t\t\t\tthis.log('Network error', err.request);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// For debugging purposes if something unexpected goes wrong\r\n\t\t\t\t\tthis.log('Unexpected Error', err);\r\n\t\t\t\t}\r\n\t\t\t\tthis.showErrorMessage();\r\n\t\t\t\tthis.inProgress = false;\r\n\t\t\t});\r\n\t}\r\n\r\n\tgetSelectData(formData) {\r\n\t\tthis.inProgress = true;\r\n\t\treturn fetch(this.settings.updateFields, {\r\n\t\t\tmethod: 'POST',\r\n\t\t\tmode: 'same-origin',\r\n\t\t\theaders: {\r\n\t\t\t\t'Content-Type': 'Application/json; charset=utf-8'\r\n\t\t\t},\r\n\t\t\tbody: JSON.stringify(formData)\r\n\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tGastrivixCalculator.handleErrors(response);\r\n\t\t\t\treturn response.json();\r\n\t\t\t})\r\n\t\t\t.then((response) => {\r\n\t\t\t\tif (!response.success) {\r\n\t\t\t\t\tthis.showErrorMessage();\r\n\t\t\t\t\tthis.inProgress = false;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tif (response.fields) {\r\n\t\t\t\t\t\tthis.updateFields(response.fields);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tthis.hideErrorMessage();\r\n\t\t\t\t\tthis.inProgress = false;\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t.catch((err) => {\r\n\t\t\t\tif (err.response) {\r\n\t\t\t\t\t// Client received an error response (5xx, 4xx)\r\n\t\t\t\t\tthis.log('Response Error', `${err.response.status}: ${err.response.data}`);\r\n\t\t\t\t} else if (err.request) {\r\n\t\t\t\t\t// Client never received a response, or request never left\r\n\t\t\t\t\tthis.log('Network error', err.request);\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// For debugging purposes if something unexpected goes wrong\r\n\t\t\t\t\tthis.log('Unexpected Error', err);\r\n\t\t\t\t}\r\n\t\t\t\tthis.showErrorMessage();\r\n\t\t\t\tthis.inProgress = false;\r\n\t\t\t});\r\n\t}\r\n\r\n\tstatic formToJson(form) {\r\n\t\t// Return if there is no tab content\r\n\t\tif (typeof form === 'undefined') return;\r\n\t\tconst itemObj = [];\r\n\t\t// Get all fieldsets, each fieldset represent an item in the form under each form section.\r\n\t\tconst fieldsets = form.querySelectorAll('fieldset');\r\n\t\tfor (let i = 0; i < fieldsets.length; i++) {\r\n\t\t\tconst isDisabled = $(fieldsets[i]).attr('disabled');\r\n\t\t\tif (!isDisabled) {\r\n\t\t\t\tconst item = [].slice.call(fieldsets[i].querySelectorAll('input, select, textarea'));\r\n\t\t\t\tconst fieldsetData = [].reduce.call(item, (data, element) => {\r\n\t\t\t\t\t// Check for valid value, no checkboxes in customer info\r\n\t\t\t\t\tif (element.type === 'checkbox') {\r\n\t\t\t\t\t\tdata[element.name] = element.checked;\r\n\t\t\t\t\t\tdata[element.id] = element.checked;\r\n\t\t\t\t\t} else if (GastrivixCalculator.isValidValue(element)) {\r\n\t\t\t\t\t\t// If the form element has a attribute for field name, use this instead of standard name.\r\n\t\t\t\t\t\tif (element.dataset.fieldName) {\r\n\t\t\t\t\t\t\tdata[element.dataset.fieldName] = element.value;\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tdata[element.name] = element.value;\r\n\t\t\t\t\t\t\tdata[element.id] = element.value;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn data;\r\n\t\t\t\t}, {});\r\n\r\n\t\t\t\tfieldsetData.Name = fieldsets[i].dataset.name;\r\n\t\t\t\tfieldsetData.Id = fieldsets[i].dataset.id;\r\n\t\t\t\titemObj.push(fieldsetData);\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Returns all data in one object\r\n\t\treturn Object.assign({}, ...itemObj);\r\n\t}\r\n\r\n\tstatic isValidValue(element) {\r\n\t\t// Check that the element has a valid value.\r\n\t\treturn (!['checkbox', 'radio'].includes(element.type) || element.checked);\r\n\t}\r\n\tinitForm() {\r\n\t\tif (this.dom.form) {\r\n\t\t\t$(this.dom.form).validate({\r\n\t\t\t\tignore: []\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (this.dom.signInForm) {\r\n\t\t\t$(this.dom.signInForm).validate({\r\n\t\t\t\tignore: []\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\thandleNext(button) {\r\n\t\tconst prevSection = button.closest(`.${classes.section}`);\r\n\t\tconst nextSection = prevSection.nextElementSibling;\r\n\r\n\t\tif (GastrivixCalculator.validateSection(prevSection)) {\r\n\t\t\tthis.currentSection = nextSection;\r\n\t\t\tprevSection.classList.add(classes.checked);\r\n\t\t\tthis.publish('/form/question/close', ({ section: prevSection }));\r\n\t\t\tthis.publish('/form/question/open', ({ section: nextSection }));\r\n\t\t\tGastrivixCalculator.scroll(prevSection);\r\n\r\n\t\t\tif (this.trackFlow && (this.trackFlow === 'True' || this.trackFlow === 'true')) {\r\n\t\t\t\t/* Track navigation to next section */\r\n\t\t\t\tGastrivixCalculator.trackSection(prevSection, this.dom.form.id);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\thandlePrevious(button) {\r\n\t\tconst prevSection = button.closest(`.${classes.section}`);\r\n\t\tconst nextSection = prevSection.previousElementSibling;\r\n\t\tnextSection.classList.remove(classes.checked);\r\n\t\tthis.currentSection = nextSection;\r\n\t\tthis.publish('/form/question/close', ({ section: prevSection }));\r\n\t\tthis.publish('/form/question/open', ({ section: nextSection }));\r\n\t\t// Used for scrolling\r\n\t\tconst offsetSection = nextSection.previousElementSibling;\r\n\t\tif (offsetSection) {\r\n\t\t\tGastrivixCalculator.scroll(offsetSection);\r\n\t\t}\r\n\r\n\t\tif (this.trackFlow && (this.trackFlow === 'True' || this.trackFlow === 'true')) {\r\n\t\t\t/* Track navigation to previous section */\r\n\t\t\tGastrivixCalculator.trackSection(nextSection, this.dom.form.id);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic validateSection(section) {\r\n\t\tconst fields = section.querySelectorAll('input');\r\n\t\tlet isValid = true;\r\n\t\tconst invalidAnswer = section.querySelector('[data-invalid-answer]');\r\n\t\tfields.forEach((field) => {\r\n\t\t\tif ($(field).valid()) {\r\n\t\t\t\tisValid = true;\r\n\t\t\t\t// If checked radio/checkbox is an incorrect answer\r\n\t\t\t\tif (field === invalidAnswer && field.checked) {\r\n\t\t\t\t\tisValid = false;\r\n\t\t\t\t\t// show modal with message\r\n\t\t\t\t\treturn isValid;\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tisValid = false;\r\n\t\t\t\treturn isValid;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn isValid;\r\n\t}\r\n\r\n\tstatic validateForm(form) {\r\n\t\tlet formValid = true;\r\n\t\t$(form).validate({\r\n\t\t\tignore: []\r\n\t\t});\r\n\t\tif ($(form).valid() === false) {\r\n\t\t\tformValid = false;\r\n\t\t}\r\n\r\n\t\treturn formValid;\r\n\t}\r\n\r\n\tstatic scroll(target) {\r\n\t\tconst $target = $(target);\r\n\t\t$('html, body').stop().animate({\r\n\t\t\tscrollTop: $target.offset().top\r\n\t\t}, 400);\r\n\t}\r\n\r\n\tstatic handleErrors(response) {\r\n\t\tif (!response.ok) {\r\n\t\t\tthrow Error(response.statusText);\r\n\t\t}\r\n\t\treturn response;\r\n\t}\r\n\r\n\tshowErrorMessage() {\r\n\t\tif (!this.errorMessage.classList.contains(classes.errorMessageVisible)) {\r\n\t\t\tthis.errorMessage.classList.add(classes.errorMessageVisible);\r\n\t\t}\r\n\t}\r\n\r\n\thideErrorMessage() {\r\n\t\tif (this.errorMessage.classList.contains(classes.errorMessageVisible)) {\r\n\t\t\tthis.errorMessage.classList.remove(classes.errorMessageVisible);\r\n\t\t}\r\n\t}\r\n\r\n\trenderSummary(data) {\r\n\t\tObject.entries(data).forEach(([key, value]) => {\r\n\t\t\tconst target = this.dom.summary.querySelector(`[data-id=${key}`);\r\n\t\t\tif (target) {\r\n\t\t\t\ttarget.innerText = value;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tthis.dom.summary.classList.remove(classes.hidden);\r\n\r\n\t\tif (!this.openOnSummary || this.openOnSummary === 'false' || this.openOnSummary === 'False') {\r\n\t\t\tthis.dom.form.classList.add(classes.hidden);\r\n\t\t\tthis.dom.signInButton.classList.add(classes.hidden);\r\n\t\t}\r\n\t\tGastrivixCalculator.scroll(this.dom.summary);\r\n\t}\r\n\r\n\tupdateFields(data) {\r\n\t\tObject.entries(data).forEach(([key, value]) => {\r\n\t\t\tthis.log(key, value);\r\n\t\t\tconst target = this.dom.form.querySelector(`[data-id=${key}`);\r\n\t\t\tif (target) {\r\n\t\t\t\ttarget.value = value;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tparseSettings() {\r\n\t\tconst settings = this.el.getAttribute('data-settings') || '{}';\r\n\t\treturn JSON.parse(settings);\r\n\t}\r\n\r\n\tstatic trackSection(section, formId, isSubmitted = false) {\r\n\t\tconst formStepCompleted = isSubmitted ? 'Summary Report' : section.querySelector('.o-question-view__heading').textContent;\r\n\r\n\t\tif (window.dataLayer) {\r\n\t\t\twindow.dataLayer.push({\r\n\t\t\t\tevent: 'gastrivixForm',\r\n\t\t\t\tformStepCompleted,\r\n\t\t\t\tformId\r\n\t\t\t});\r\n\t\t}\r\n\t\tconsole.log(\"datalayer\", window.dataLayer);\r\n\t}\r\n}\r\n"],"sourceRoot":""}