{"version":3,"file":"AssociationSaleViewComponent.min.js","sources":["../../../../Business/Components/AssociationSale/AssociationSaleViewComponent.js"],"sourcesContent":["(function () {\n window.kombiApp = window.kombiApp || {};\n window.kombiApp.Components = window.kombiApp.Components || {};\n\n window.kombiApp.Components.AssoicationSale = function (\n element, // The element that the component is attached to\n campaignCodeInputEl, \n gameProductDropdownEl // the element that holds the select game product and its campaign code. This value is used to set the form campaign code\n ) {\n const districtSelect = element.querySelector('.js-district-select');\n const associationSelect = element.querySelector('.js-association-select');\n districtSelect.value = '';\n associationSelect.value = '';\n let showErrors = false;\n\n districtSelect.addEventListener('change', function (evt) {\n filterAssociations(evt.target.value);\n setAssociation('');\n })\n\n associationSelect.addEventListener('change', function (evt) {\n setAssociation(evt.target.value)\n })\n\n function validate() {\n const isValid = !!associationSelect.value;\n if (!isValid && showErrors) {\n element.classList.add('is-invalid');\n }\n else {\n element.classList.remove('is-invalid');\n }\n }\n\n // the reason why errors is not shown from start ios that we want to let the user enter this first.\n // We show the errors when the user tries to submit and there still are validation errors \n function validateAndShowErrors() {\n showErrors = true;\n validate();\n }\n\n\n function setAssociation(campaignCode) {\n associationSelect.value = campaignCode;\n validate();\n\n // update campaign code of the dropdown value in campaign page sign up.\n // the reason is that this dropdown sets the campaign code input.\n // A hacky solution but perhaps the best for the moment without rewriting the whole thing...\n gameProductDropdownEl.querySelectorAll('option')[1].value = campaignCode;\n gameProductDropdownEl.value = campaignCode;\n gameProductDropdownEl.dispatchEvent(new Event('change'));\n\n element.dispatchEvent(new CustomEvent('kombi.associationsale.change', { detail: { value: campaignCode } }));\n }\n\n function filterAssociations(districtId) {\n var defaultOptionEl = associationSelect.firstElementChild.cloneNode(true)\n associationSelect.innerHTML = '';\n associationSelect.appendChild(defaultOptionEl)\n\n window.associations\n .filter(x => !districtId || x.districtId == districtId)\n .forEach(x => {\n const optionEl = document.createElement('option');\n optionEl.value = x.campaignCode;\n optionEl.text = x.name;\n associationSelect.appendChild(optionEl)\n })\n }\n\n // update the select values to correspond the campaign code\n function initByCampaignCode(campaignCode) {\n const option = Array.from(associationSelect.querySelectorAll('option')).find(x => x.value === campaignCode);\n if (option) {\n const districtId = option.getAttribute('data-district-id');\n districtSelect.value = districtId;\n filterAssociations(districtId);\n setAssociation(campaignCode);\n }\n }\n\n // an association can be preselected by provide the campaign-code in the url\n // example: datumlotteriet.se/bestall-lotter-forening/?campaign-code=22BCF14\n function getCampaignCodeFromUrl() {\n const urlParams = new URLSearchParams(window.location.search);\n const campaignCode = urlParams.get('campaign-code');\n return campaignCode;\n }\n\n function init() {\n const campaignCodeFromUrl = getCampaignCodeFromUrl();\n const campaignCodeFromForm = campaignCodeInputEl.value;\n const campaignCode = campaignCodeFromForm || campaignCodeFromUrl;\n if (!!campaignCode) {\n initByCampaignCode(campaignCode);\n }\n // 'kombi.assoicationsale.validate' is called from campaign-page.js when the clicks on \"Välj\"\n document.addEventListener('kombi.assoicationsale.validate', validateAndShowErrors);\n }\n\n init();\n }\n})();"],"names":["window","kombiApp","Components","AssoicationSale","element","campaignCodeInputEl","gameProductDropdownEl","districtSelect","querySelector","associationSelect","value","let","showErrors","validate","classList","add","remove","validateAndShowErrors","setAssociation","campaignCode","querySelectorAll","dispatchEvent","Event","CustomEvent","detail","filterAssociations","districtId","defaultOptionEl","firstElementChild","cloneNode","innerHTML","appendChild","associations","filter","x","forEach","optionEl","document","createElement","text","name","campaignCodeFromUrl","addEventListener","evt","target","URLSearchParams","location","search","get","option","Array","from","find","getAttribute"],"mappings":"AACIA,OAAOC,SAAWD,OAAOC,UAAY,GACrCD,OAAOC,SAASC,WAAaF,OAAOC,SAASC,YAAc,GAE3DF,OAAOC,SAASC,WAAWC,gBAAkB,SACzCC,EACAC,EACAC,GAEA,MAAMC,EAAiBH,EAAQI,cAAc,qBAAqB,EAC5DC,EAAoBL,EAAQI,cAAc,wBAAwB,EACxED,EAAeG,MAAQ,GACvBD,EAAkBC,MAAQ,GAC1BC,IAAIC,EAAa,CAAA,EAWjB,SAASC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