{"version":3,"file":"store-manual-entry.js","sources":["../../../../IREP.Web.Content/v7/scripts/modules/public/store-position.ts","../../../../IREP.Web.Content/v7/scripts/modules/public/retailer-search.ts","../../../../IREP.Web.Content/v7/scripts/modules/public/store-manual-entry.ts"],"sourcesContent":["import Component from \"irep/modules/component\";\nvar PositionIds;\n(function (PositionIds) {\n PositionIds[PositionIds[\"RetailSales\"] = 300] = \"RetailSales\";\n PositionIds[PositionIds[\"OnlineSales\"] = 301] = \"OnlineSales\";\n PositionIds[PositionIds[\"CallCenter\"] = 302] = \"CallCenter\";\n PositionIds[PositionIds[\"Promoter\"] = 303] = \"Promoter\";\n PositionIds[PositionIds[\"Manager\"] = 304] = \"Manager\";\n PositionIds[PositionIds[\"Other\"] = 305] = \"Other\";\n PositionIds[PositionIds[\"ManagerOneStore\"] = 306] = \"ManagerOneStore\";\n PositionIds[PositionIds[\"ManagerMultiple\"] = 307] = \"ManagerMultiple\";\n PositionIds[PositionIds[\"DepartmentManager\"] = 308] = \"DepartmentManager\";\n PositionIds[PositionIds[\"RegionalManager\"] = 309] = \"RegionalManager\";\n})(PositionIds || (PositionIds = {}));\nexport class StorePosition extends Component {\n constructor(options) {\n super(options.id);\n this.options = options;\n this.retailerSearch = options.retailerSearch;\n this.promoterRetailerSearch = options.promoterRetailerSearch;\n this.storeManual = options.storeManual;\n this.countryCode = options.countryCode;\n this.storePositionFail = this.$component.find(\"#storePositionFail\");\n this.storeNotListedFail = this.$component.find(\"#storeNotListedFail\");\n this.managerSelect = this.$component.find(\".managerSelect\");\n this.otherInfo = this.$component.find(\".otherInfo\");\n this.otherCompany = this.$component.find(\"[name='StorePositionModel.StoreManualEntryModel.OtherCompany']\");\n this.jobDescription = this.$component.find(\"[name='StorePositionModel.StoreManualEntryModel.sInfo.JobDescription']\");\n this.promoterStore = this.$component.find(\"#PromoterStore\");\n this.promoterRetailerRadio = this.$component.find(\"[name='StorePositionModel.PromoData.SpecificRetailer']\");\n this.promoterStoreRadio = this.$component.find(\"[name='StorePositionModel.PromoData.SpecificStore']\");\n this.promoterRetailerRadioSelect = this.$component.find(\".promoterRetailerRadioSelect\");\n this.promoterRetailerError = this.$component.find(\".promoterRetailerError\");\n this.promoterStoreError = this.$component.find(\".promoterStoreError\");\n this.promoterStoreRadioSelect = this.$component.find(\".promoterStoreRadioSelect\");\n this.retailerSelect = this.$component.find(\".retailerSelect\");\n this.storeSelect = this.$component.find(\".storeSelect\");\n this.promoterRetailerSelect = this.$component.find(\".promoterRetailerSelect\");\n this.searchRetailer = this.$component.find(\"#SearchRetailer\");\n this.searchLocation = this.$component.find(\"#SearchLocation\");\n this.searchPromoterRetailer = this.$component.find(\"#SearchPromoterRetailer\");\n this.searchRetailerBtn = this.$component.find(\".searchRetailer\");\n this.searchLocationBtn = this.$component.find(\".searchLocation\");\n this.searchPromoterRetailerBtn = this.$component.find(\".searchPromoterRetailer\");\n this.retailerLabel = this.$component.find(\"#RetailerLabel\");\n this.storeLocationLabel = this.$component.find(\"#LocationLabel\");\n this.jobPositionSelect = this.$component.find(\"#jobPositionSelect\");\n this.additionPromoterStoresText = this.$component.find(\"#addition-promoter-stores-text\");\n this.retailerSearch.setCountry(options.countryCode, options.countryName);\n this.retailerSearch.setPromoterCountry(options.countryCode, options.countryName);\n this.promoterRetailerSearch.setCountry(options.countryCode, options.countryName);\n this.promoterRetailerSearch.setPromoterCountry(options.countryCode, options.countryName);\n this.storeManual.setCountry(options.countryCode, false);\n this.initCallbacks();\n this.retailerSearch.manualForm(this.storeManual);\n this.promoterRetailerSearch.manualForm(this.storeManual);\n this.bindEvents();\n }\n setCountry(value, name) {\n this.countryCode = value;\n this.retailerSearch.setCountry(value, name);\n this.promoterRetailerSearch.setPromoterCountry(value, name);\n this.storeManual.setCountry(value, true);\n this.updateRetailers(false);\n }\n bindEvents() {\n this.unbindEvents();\n this.jobPositionSelect.on(\"change\", (e) => this.changePosition(false));\n this.promoterRetailerRadioSelect.on(\"change\", (e) => this.promoterRetailerRadioChoice());\n this.promoterStoreRadioSelect.on(\"change\", (e) => this.promoterStoreRadioChoice());\n this.promoterRetailerSelect.on(\"change\", (e) => this.promoterRetailerRadioShow());\n this.retailerSelect.on(\"change\", (e) => this.promoterStoreRadioShow());\n this.searchRetailer.on(\"change\", (e) => { this.employeeCodeCheck(); this.changeLocationList(this.initializing); this.clearError(e); });\n this.searchLocation.on(\"change\", (e) => this.clearError(e));\n this.searchPromoterRetailer.on(\"change\", (e) => { this.changePromoterLocation(); this.clearError(e); });\n this.searchRetailerBtn.on(\"click\", (e) => this.retailerOpenSearch());\n this.searchLocationBtn.on(\"click\", (e) => this.openStoreEntry());\n this.searchPromoterRetailerBtn.on(\"click\", (e) => this.promoterRetailerOpenSearch());\n function addressFormatting(text) {\n if (text.element != undefined) {\n return $(\"\" + $(text.element).attr('display-text').replace(\"|\", \"\") + \"\");\n }\n else\n return $(text.text);\n }\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 211567, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.jobPositionSelect.select2({\n placeholder: d.text,\n templateResult: addressFormatting,\n allowClear: true\n });\n });\n }\n unbindEvents() {\n this.promoterRetailerRadioSelect.off(\"change\");\n this.promoterStoreRadioSelect.off(\"change\");\n this.jobPositionSelect.off('change');\n this.searchRetailer.off('change');\n this.searchLocation.off('change');\n this.searchPromoterRetailer.off(\"change\");\n this.searchRetailerBtn.off('click');\n this.searchLocationBtn.off('click');\n this.searchPromoterRetailerBtn.off(\"click\");\n }\n initSelection(storePositionTypeId, retailerName, storeChainId, promoterAgency, promoterStoreId, storeName, storeId) {\n let qq = this;\n let val = Number(storePositionTypeId);\n if (PositionIds[val] === undefined) {\n val = PositionIds.RetailSales;\n }\n else if ([PositionIds.ManagerMultiple, PositionIds.ManagerOneStore, PositionIds.RegionalManager, PositionIds.DepartmentManager].indexOf(val) != -1) {\n $(\"input:radio[name='StorePositionModel.listName'][value='\" + val + \"']\").click();\n val = PositionIds.Manager;\n }\n this.jobPositionSelect.val(val.toString());\n qq.changePosition(true);\n qq.initializing = true;\n setTimeout(function () {\n qq.setRetailer(retailerName, storeChainId, true);\n qq.setPromoterRetailer(promoterAgency, promoterStoreId, true);\n qq.initPromoterRetailerTexts();\n if (storeId == 0) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184274, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n qq.searchLocation.html(qq.searchLocation.html() + \"\");\n qq.setStore(storeName, storeId);\n });\n }\n }, 500);\n this.searchLocationBtn.removeClass('hide');\n }\n initCallbacks() {\n let qq = this;\n let rsCallback = (id, name) => {\n qq.setRetailer(name, id, true);\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"True\")\n qq.changeLocationList(false);\n else\n qq.setStoreNotListed();\n };\n let prsCallback = (id, name) => {\n qq.setPromoterRetailer(name, id, true);\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"False\")\n qq.changeLocationList(false);\n else\n qq.setStoreNotListed();\n };\n let snlCallback = (storeId) => {\n if (storeId == 0) {\n qq.setStoreNotListed();\n }\n else {\n let snl = $(\"#SearchLocation option[value='\" + storeId + \"']\");\n if (snl.length > 0) {\n this.searchLocation.val(snl.attr(\"value\")).trigger('change');\n }\n }\n };\n let rsnlCallback = (retailerId, storeId) => {\n if (retailerId == 0) {\n qq.setRetailerNotListed();\n qq.setStoreNotListed();\n }\n else {\n let stnl = $(\"#SearchRetailer option[value='\" + retailerId + \"']\");\n if (stnl.length > 0) {\n this.searchLocation.val(stnl.attr(\"value\"));\n }\n }\n if (storeId == 0) {\n qq.setStoreNotListed();\n }\n else {\n let snl = $(\"#SearchLocation option[value='\" + storeId + \"']\");\n if (snl.length > 0) {\n this.searchLocation.val(snl.attr(\"value\")).trigger('change');\n }\n }\n };\n let prsnlCallback = (retailerId, storeId) => {\n if (retailerId == 0) {\n qq.setPromoterRetailerNotListed();\n }\n else {\n let stnl = $(\"#SearchPromoterRetailer option[value='\" + retailerId + \"']\");\n if (stnl.length > 0) {\n this.searchLocation.val(stnl.attr(\"value\"));\n }\n }\n if (storeId == 0) {\n qq.setStoreNotListed();\n }\n else {\n let snl = $(\"#SearchLocation option[value='\" + storeId + \"']\");\n if (snl.length > 0) {\n this.searchLocation.val(snl.attr(\"value\")).trigger('change');\n }\n }\n };\n this.storeManual.setCallback(snlCallback, this.promoterRetailerRadio.filter(\":checked\").val() == \"True\" ? prsnlCallback : rsnlCallback);\n this.retailerSearch.setCallback(rsCallback);\n this.promoterRetailerSearch.setCallback(prsCallback);\n }\n setRetailerNotListed() {\n if (this.searchRetailer.val() != \"0\") {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184275, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.setRetailer(d.text, 0, true);\n this.setStoreNotListed();\n });\n }\n }\n setPromoterRetailerNotListed() {\n if (this.searchPromoterRetailer.val() != \"0\") {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184275, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.setPromoterRetailer(d.text, 0, true);\n });\n }\n }\n setStoreNotListed() {\n let snl = $(\"#SearchLocation option[data-storenotlisted='true']\");\n if (snl.length > 0) {\n this.searchLocation.val(snl.attr(\"value\")).trigger('change');\n }\n else {\n if (this.searchLocation.val() != \"0\") {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184274, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.setStore(d.text, 0);\n });\n }\n }\n }\n setRetailer(name, id, trigger) {\n this.searchRetailer.html(this.searchRetailer.html() + \"\");\n this.searchRetailer.val(id.toString());\n this.searchRetailer.select2();\n if (trigger) {\n this.searchRetailer.trigger('change');\n }\n }\n setPromoterRetailer(name, id, trigger) {\n this.searchPromoterRetailer.html(this.searchPromoterRetailer.html() + \"\");\n this.searchPromoterRetailer.val(id.toString());\n this.searchPromoterRetailer.select2();\n if (trigger) {\n this.searchPromoterRetailer.trigger('change');\n }\n else {\n this.setStoreNotListed();\n }\n }\n setStore(name, id) {\n this.searchLocation.html(this.searchLocation.html() + \"\");\n this.searchLocation.val(id.toString()).trigger('change');\n this.searchLocation.select2();\n }\n getResults() {\n this.storeManual.getForm().find(\"input\").each(function () {\n this.value = $(this).val().toString().trim();\n });\n return this.storeManual.getForm().serialize() + \"&StorePositionModel.Info.StorePositionTypeId=\" + this.getStorePositionId();\n }\n getStorePositionId() {\n return this.managerSelect.is(\":visible\") ? $(\"input:radio[name='StorePositionModel.listName']:checked\").val() : $(\"#jobPositionSelect\").val();\n }\n changePosition(retainRetailer) {\n $(\"#select2-StorePositionModel_Info_StoreChainId-container\").attr('title', '');\n $(\"#select2-StorePositionModel_Info_StoreId-container\").attr('title', '');\n this.managerSelect.addClass('hide');\n this.retailerSelect.removeClass('hide');\n this.storeSelect.removeClass('hide');\n this.promoterRetailerSelect.addClass('hide');\n this.otherInfo.addClass('hide');\n this.promoterRetailerRadioSelect.addClass('hide');\n this.promoterStoreRadioSelect.addClass('hide');\n this.additionPromoterStoresText.addClass('hide');\n this.dataStatus = this.jobPositionSelect.val().toString();\n switch (this.jobPositionSelect.val()) {\n case \"305\":\n $('.promoterRetailerRadioSelect input[type=\"radio\"]').prop('checked', false);\n $('.promoterStoreRadioSelect input[type=\"radio\"]').prop('checked', false);\n this.searchPromoterRetailer.val(0).trigger('change');\n this.promoterStore.val(0).trigger('change');\n this.otherInfo.removeClass('hide');\n this.retailerSelect.addClass('hide');\n this.storeSelect.addClass('hide');\n $('.employeeCode').addClass('hide');\n this.dataStatus = \"other\";\n this.setRetailerNotListed();\n this.setStoreNotListed();\n break;\n case \"304\":\n $('.promoterRetailerRadioSelect input[type=\"radio\"]').prop('checked', false);\n $('.promoterStoreRadioSelect input[type=\"radio\"]').prop('checked', false);\n this.searchPromoterRetailer.val(0).trigger('change');\n this.promoterStore.val(0).trigger('change');\n this.managerSelect.removeClass('hide');\n $('.employeeCode').addClass('hide');\n this.setPositionTexts(StorePosition.PositionMode.MANAGER);\n this.dataStatus = \"retail\";\n this.updateRetailers(retainRetailer);\n break;\n case \"303\":\n this.storeSelect.addClass('hide');\n this.retailerSelect.addClass('hide');\n this.promoterRetailerSelect.removeClass('hide');\n $('.employeeCode').addClass('hide');\n this.setPositionTexts(StorePosition.PositionMode.PROMOTER);\n this.dataStatus = \"promoter\";\n this.updatePromoterRetailers(retainRetailer);\n break;\n case \"302\":\n $('.promoterRetailerRadioSelect input[type=\"radio\"]').prop('checked', false);\n $('.promoterStoreRadioSelect input[type=\"radio\"]').prop('checked', false);\n this.searchPromoterRetailer.val(0).trigger('change');\n this.promoterStore.val(0).trigger('change');\n this.setPositionTexts(StorePosition.PositionMode.MANUFACTURER);\n this.dataStatus = \"manufacturer\";\n this.updateRetailers(retainRetailer);\n break;\n default:\n $('.promoterRetailerRadioSelect input[type=\"radio\"]').prop('checked', false);\n $('.promoterStoreRadioSelect input[type=\"radio\"]').prop('checked', false);\n this.searchPromoterRetailer.val(0).trigger('change');\n this.promoterStore.val(0).trigger('change');\n $('.employeeCode').addClass('hide');\n this.setPositionTexts(StorePosition.PositionMode.RETAILER);\n this.dataStatus = \"retail\";\n this.updateRetailers(retainRetailer);\n break;\n }\n }\n promoterRetailerRadioShow() {\n if (this.searchPromoterRetailer.val() != null && this.searchPromoterRetailer.val() != \"\" && this.dataStatus == \"promoter\") {\n this.promoterRetailerRadioSelect.removeClass('hide');\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"False\") {\n this.storeSelect.removeClass('hide');\n }\n }\n else {\n return;\n }\n }\n promoterRetailerRadioChoice() {\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"True\") {\n this.changePromoterLocation();\n this.updateRetailers(false);\n this.storeSelect.addClass('hide');\n this.retailerSelect.removeClass('hide');\n if (this.countryCode == 'US' && this.options.isRegistration) {\n this.additionPromoterStoresText.removeClass('hide');\n }\n }\n else if (this.promoterRetailerRadio.filter(\":checked\").val() == \"False\") {\n this.setRetailer((this.searchPromoterRetailer.select2('data'))[0].text, Number.parseInt((this.searchPromoterRetailer.select2('data'))[0].id), false);\n $('.promoterStoreRadioSelect input[type=\"radio\"]').prop('checked', false);\n this.changeLocationList(false);\n this.promoterStoreRadioSelect.addClass('hide');\n this.retailerSelect.addClass('hide');\n this.storeSelect.removeClass('hide');\n this.setStorePositionTextPromoter();\n }\n }\n promoterStoreRadioShow() {\n if (this.searchRetailer.val() != null && this.searchRetailer.val() != \"\" && this.promoterRetailerRadio.filter(\":checked\").val() == \"True\") {\n this.retailerSelect.removeClass('hide');\n this.promoterStoreRadioSelect.removeClass('hide');\n if (this.promoterStoreRadio.filter(\":checked\").val() == \"True\") {\n this.storeSelect.removeClass('hide');\n }\n }\n else {\n return;\n }\n }\n initPromoterRetailerTexts() {\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"True\") {\n this.setStorePositionTextRetailer();\n }\n else if (this.promoterRetailerRadio.filter(\":checked\").val() == \"False\") {\n this.setStorePositionTextPromoter();\n }\n }\n promoterStoreRadioChoice() {\n if (this.promoterStoreRadio.filter(\":checked\").val() == \"True\") {\n this.setStorePositionTextRetailer();\n this.storeSelect.removeClass('hide');\n this.changeLocationList(false);\n }\n else if (this.promoterStoreRadio.filter(\":checked\").val() == \"False\") {\n this.storeSelect.addClass('hide');\n this.changeLocationList(false);\n return;\n }\n }\n setPositionTexts(type) {\n let that = this;\n if (type == StorePosition.PositionMode.RETAILER || type == StorePosition.PositionMode.MANAGER) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 208741, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.retailerLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 231064, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\".mtRetailerSearch\").data('placeholder', d.text);\n $(\".mtRetailerSearch.mt-select2\").select2({\n placeholder: d.text\n });\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184254, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.searchRetailerBtn.html(d.text);\n });\n this.storeManual.setMode(StorePosition.PositionMode.RETAILER);\n this.retailerSearch.setMode(StorePosition.PositionMode.RETAILER);\n }\n else if (type == StorePosition.PositionMode.MANUFACTURER) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 208743, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.retailerLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 231063, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\".mtRetailerSearch\").data('placeholder', d.text);\n $(\".mtRetailerSearch.mt-select2\").select2({\n placeholder: d.text\n });\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184268, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.searchRetailerBtn.html(d.text);\n });\n this.storeManual.setMode(StorePosition.PositionMode.MANUFACTURER);\n this.retailerSearch.setMode(StorePosition.PositionMode.MANUFACTURER);\n }\n else if (type == StorePosition.PositionMode.PROMOTER) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 217082, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.retailerLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 231061, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\".mtPromoterRetailerSearch\").data('placeholder', d.text);\n $(\".mtPromoterRetailerSearch.mt-select2\").select2({\n placeholder: d.text\n });\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 231059, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\".mtRetailerSearch\").data('placeholder', d.text);\n $(\".mtRetailerSearch.mt-select2\").select2({\n placeholder: d.text\n });\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 217087, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.searchRetailerBtn.html(d.text);\n });\n this.storeManual.setMode(StorePosition.PositionMode.PROMOTER);\n this.promoterRetailerSearch.setMode(StorePosition.PositionMode.PROMOTER);\n this.retailerSearch.setMode(StorePosition.PositionMode.PROMOTER);\n }\n if (type == StorePosition.PositionMode.MANAGER) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 208746, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.storeLocationLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184209, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.searchLocationBtn.html(d.text);\n });\n }\n else if (type == StorePosition.PositionMode.MANUFACTURER) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 208745, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.storeLocationLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184250, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\".mtSearchLocation\").data('placeholder', d.text);\n $(\".mtSearchLocation.mt-select2\").select2({\n placeholder: d.text\n });\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184223, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n that.searchLocationBtn.html(d.text);\n });\n }\n else if (type == StorePosition.PositionMode.PROMOTER) {\n this.setStorePositionTextPromoter();\n }\n else {\n this.setStorePositionTextRetailer();\n }\n }\n setStorePositionTextRetailer() {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 282807, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.storeLocationLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184250, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.searchLocation.data('placeholder', d.text);\n this.searchLocation.find('.select2-selection__placeholder').text(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184209, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.searchLocationBtn.html(d.text);\n });\n }\n setStorePositionTextPromoter() {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 208744, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.storeLocationLabel.html(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184250, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.searchLocation.data('placeholder', d.text);\n this.searchLocation.find('.select2-selection__placeholder').text(d.text);\n });\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 231060, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n this.searchLocationBtn.html(d.text);\n });\n }\n retailerOpenSearch() {\n this.retailerSearch.setupRetailers();\n this.retailerSearch.openSearch();\n }\n promoterRetailerOpenSearch() {\n this.promoterRetailerSearch.setupRetailers();\n this.promoterRetailerSearch.openSearch();\n }\n clearError(e) {\n $(e.target).closest('.has-error').removeClass('has-error');\n }\n openStoreEntry() {\n this.storeManual.open(false);\n }\n updatePromoterRetailers(retainRetailer) {\n let qq = this;\n $.ajax({\n type: \"get\",\n dataType: \"json\",\n url: window.irep.options.appUrl + 'RetailersByAttribute',\n data: { countryCode: this.countryCode, attribute: \"promoter\" }\n }).done(function (d) {\n let listItems = \"\";\n for (let i = 0; i < d.Data.length; i++) {\n listItems += \"\";\n }\n if (retainRetailer) {\n qq.searchPromoterRetailer.html(qq.searchPromoterRetailer.html() + listItems);\n qq.searchPromoterRetailerBtn.removeClass('hide');\n }\n else {\n qq.searchPromoterRetailer.html(listItems);\n qq.searchPromoterRetailerBtn.removeClass('hide');\n qq.searchPromoterRetailer.val(null).trigger('change');\n }\n qq.searchPromoterRetailer.select2();\n });\n }\n updateRetailers(retainRetailer) {\n if (this.dataStatus == \"other\" || this.dataStatus == undefined)\n return;\n let ApiCmd = 'RetailersByAttribute';\n if (this.dataStatus == 'retail' || this.dataStatus == 'online' || this.promoterRetailerRadio.filter(\":checked\").val() != undefined)\n ApiCmd = 'PreferredRetailers';\n let qq = this;\n let currentRetailerId = this.searchRetailer.val();\n $.ajax({\n type: \"get\",\n dataType: \"json\",\n url: window.irep.options.appUrl + ApiCmd,\n data: { countryCode: this.countryCode, attribute: this.dataStatus }\n }).done(function (d) {\n let listItems = \"\";\n for (let i = 0; i < d.Data.length; i++) {\n listItems += \"\";\n }\n if (retainRetailer) {\n qq.searchRetailer.html(qq.searchRetailer.html() + listItems);\n }\n else {\n qq.searchRetailer.html(listItems);\n qq.searchRetailer.val(null).trigger('change');\n qq.searchLocation.val(null).trigger('change');\n }\n qq.searchRetailer.select2();\n });\n }\n processGermanLogic() {\n let that = this;\n if ($.inArray(this.promoterRetailerRadio.filter(\":checked\").val() == \"True\" ? this.searchPromoterRetailer.val() : this.searchRetailer.val(), [\"204552\", \"28101\", \"28057\", \"151552\", \"31643\", \"884\", \"912\", \"104620\", \"1516\", \"1531\", \"287877\", \"170664\", \"211277\", \"31649\", \"284489\", \"2048\", \"1838\", \"289810\"]) != -1) {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 190658, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\"#AgeDisclaimer1 .control-label\").html(d.text);\n });\n }\n else {\n window.irep.getHtml({ url: \"api/localization/text\", type: \"GET\", data: { id: 184237, cultureCode: window.irep.options.user.cultureCode } }).done((resp) => {\n let d = JSON.parse(resp);\n $(\"#AgeDisclaimer1 .control-label\").html(d.text);\n });\n }\n }\n changePromoterLocation() {\n if (this.countryCode == \"DE\") {\n this.processGermanLogic();\n }\n if (this.dataStatus != \"promoter\")\n return;\n let currentLocationId = this.searchLocation.val();\n let qq = this;\n if (this.promoterRetailerRadio.filter(\":checked\").val() == \"True\") {\n $.ajax({\n type: \"get\",\n dataType: \"json\",\n url: window.irep.options.appUrl + \"StoreList\",\n data: {\n storeChainId: this.searchPromoterRetailer.val(),\n countryCode: this.countryCode\n }\n }).done(function (d) {\n let storeNotListed;\n for (let i = 0; i < d.Data.length; i++) {\n if (d.Data[i].IsStoreNotListed == true) {\n storeNotListed += \"\";\n break;\n }\n }\n qq.promoterStore.html(storeNotListed);\n });\n }\n else if (this.promoterRetailerRadio.filter(\":checked\").val() == \"False\") {\n qq.changeLocationList(true);\n }\n }\n changeLocationList(retainRetailer) {\n if (this.countryCode == \"DE\") {\n this.processGermanLogic();\n }\n if (this.searchRetailer.val() == \"\" && this.dataStatus != \"promoter\")\n return;\n if (this.dataStatus == \"other\" || this.dataStatus == undefined)\n return;\n let currentLocationId = this.searchLocation.val();\n let defaultResults = [];\n this.searchLocation.select2({\n dataAdapter: $.fn.select2.amd.require('select2/data/extended-ajax'),\n defaultResults: () => defaultResults,\n minimumInputLength: 1,\n width: '100%',\n ajax: {\n delay: 200,\n dataType: 'json',\n headers: { \"PaxUID\": window.irep.options.user.currentUID },\n url: window.irep.options.irepUrl + \"/api/retailers/stores/search\",\n data: (params) => {\n return {\n storeChainId: this.searchRetailer.val(),\n countryCode: this.countryCode,\n includeStoreNotListed: true,\n searchText: params.term,\n };\n },\n processResults: (data) => {\n return {\n results: $.map(data.results, function (item) {\n return {\n text: item.valueText,\n id: item.value\n };\n })\n };\n }\n }\n });\n $.ajax({\n type: \"get\",\n dataType: \"json\",\n url: window.irep.options.irepUrl + \"/api/retailers/stores/search\",\n data: {\n storeChainId: this.searchRetailer.val(),\n countryCode: this.countryCode,\n includeStoreNotListed: true,\n }\n }).done((response) => {\n this.searchLocationBtn.removeClass('hide');\n defaultResults.push(...response.results);\n if (retainRetailer) {\n this.searchLocation.val(currentLocationId).trigger('change');\n }\n else {\n this.searchLocation.val(null).trigger('change');\n }\n this.initializing = false;\n });\n }\n employeeCodeCheck() {\n if ((this.searchRetailer.val() == \"39041\" || this.searchRetailer.val() == \"129859\") && this.dataStatus != 'promoter') {\n $('.employeeCode').removeClass('hide');\n }\n else {\n $('.employeeCode').addClass('hide');\n }\n }\n validate() {\n $(\"#reg7-store\").find(\".select2-selection.has-error\").removeClass(\"has-error\");\n $(\"#reg7-store\").find(\".error-message:visible\").addClass(\"hide\");\n this.retailerSelect.removeClass('has-error');\n this.storeSelect.removeClass('has-error');\n this.promoterRetailerSelect.removeClass('has-error');\n this.promoterRetailerRadioSelect.removeClass('has-error');\n this.promoterStoreRadioSelect.removeClass('has-error');\n this.managerSelect.removeClass('has-error');\n this.searchLocationBtn.removeClass('has-error');\n this.searchRetailerBtn.removeClass('has-error');\n this.searchPromoterRetailerBtn.removeClass('has-error');\n this.jobDescription.parent().removeClass('has-error');\n this.otherCompany.parent().removeClass('has-error');\n this.storePositionFail.addClass('hide');\n this.storeNotListedFail.addClass('hide');\n let res = true;\n if (this.jobPositionSelect.val() == \"\") {\n this.setSelect2Error(this.jobPositionSelect);\n res = false;\n }\n if (this.retailerSelect.is(\":visible\") && (this.searchRetailer.val() == null || this.searchRetailer.val() == \"\")) {\n this.setSelect2Error(this.searchRetailer);\n res = false;\n }\n if (this.storeSelect.is(\":visible\") && (this.searchLocation.val() == null || this.searchLocation.val() == \"\")) {\n this.setSelect2Error(this.searchLocation);\n res = false;\n }\n if (this.dataStatus == \"other\" && this.otherInfo.is(\":visible\")) {\n if (this.otherCompany.val() == null || this.otherCompany.val().toString().trim() == \"\") {\n this.setSelect2Error(this.otherCompany);\n res = false;\n }\n if (this.jobDescription.val() == null || this.jobDescription.val().toString().trim() == \"\") {\n this.setSelect2Error(this.jobDescription);\n res = false;\n }\n }\n if (this.dataStatus == \"promoter\" && this.promoterRetailerSelect.is(\":visible\")) {\n if (this.searchPromoterRetailer.val() == null || this.searchPromoterRetailer.val() == \"\") {\n this.setSelect2Error(this.searchPromoterRetailer);\n res = false;\n }\n if (this.searchPromoterRetailer.val() == \"0\" && !this.storeManual.isValid(true) && !this.otherInfo.is(\":visible\")) {\n this.searchPromoterRetailerBtn.addClass('has-error');\n res = false;\n }\n if (this.promoterRetailerRadioSelect.is(\":visible\") && this.promoterRetailerRadio.filter(\":checked\").val() == undefined) {\n this.promoterRetailerRadioSelect.addClass('has-error');\n this.promoterRetailerError.removeClass('hide');\n res = false;\n }\n if (this.promoterStoreRadioSelect.is(\":visible\") && this.promoterStoreRadio.filter(\":checked\").val() == undefined) {\n this.promoterStoreRadioSelect.addClass('has-error');\n this.promoterStoreError.removeClass('hide');\n res = false;\n }\n }\n if ((this.searchLocation.val() == \"0\" || $(\"#SearchLocation :selected\").attr('data-storenotlisted') == \"true\") && this.dataStatus != \"promoter\" && !this.storeManual.isValid(false) && !this.otherInfo.is(\":visible\")) {\n this.searchLocationBtn.addClass('has-error');\n this.storeNotListedFail.removeClass('hide');\n res = false;\n }\n if (this.searchRetailer.val() == \"0\" && !this.storeManual.isValid(true) && !this.otherInfo.is(\":visible\")) {\n this.searchRetailerBtn.addClass('has-error');\n res = false;\n }\n if (this.managerSelect.is(\":visible\") && $(\"input:radio[name='StorePositionModel.listName']:checked\").length == 0) {\n this.managerSelect.addClass('has-error');\n res = false;\n }\n return res;\n }\n setSelect2Error(element) {\n let $parent = element.parent();\n $parent.find(\".select2-selection\").addClass(\"has-error\");\n $parent.find(\".error-message\").removeClass(\"hide\");\n }\n}\nStorePosition.PositionMode = {\n RETAILER: 1,\n MANUFACTURER: 2,\n PROMOTER: 3,\n MANAGER: 4\n};\n","import Component from \"irep/modules/component\";\nimport { StorePosition } from \"./store-position\";\nexport class RetailerSearch extends Component {\n constructor(options) {\n super(options.id);\n this.options = options;\n this.searchModal = this.$component.find(\".searchreveal\");\n this.searchText = this.$component.find(\"#searchText\");\n this.searchResults = this.$component.find(\".searchResults\");\n this.selectedValue = this.$component.find(\"#selectedValue\");\n this.buttonSelect = this.$component.find(\"#buttonSelect\");\n this.buttonCantFind = this.$component.find(\".buttonCantFind\");\n this.hiddenPromoterRetailerSearch = this.$component.find(\"#StorePositionModel_PromoterRetailerCountrySearch\");\n this.hiddenRetailerSearch = this.$component.find(\"#StorePositionModel_RetailerCountrySearch\");\n this.bindEvents();\n }\n bindEvents() {\n this.unbindEvents();\n this.searchText.on(\"keyup\", (e) => this.pauseSearchRetailers());\n this.searchResults.on(\"click\", (e) => this.setSelection(e));\n this.searchResults.on(\"dblclick\", (e) => this.takeSelection());\n this.buttonSelect.on(\"click\", (e) => this.takeSelection());\n this.buttonCantFind.on(\"click\", (e) => this.manualRetailer());\n this.hiddenPromoterRetailerSearch.on(\"change\", (e) => this.changePromoterCountry());\n this.hiddenRetailerSearch.on(\"change\", (e) => this.changeCountry());\n document.addEventListener('keypress', (e) => this.processKey2(e));\n }\n setMode(mode) {\n if (mode == StorePosition.PositionMode.RETAILER) {\n $(\".retailerText\").removeClass(\"hide\");\n $(\".manufacturerText\").addClass(\"hide\");\n $(\".promoterText\").addClass(\"hide\");\n }\n else if (mode == StorePosition.PositionMode.MANUFACTURER) {\n $(\".retailerText\").addClass(\"hide\");\n $(\".manufacturerText\").removeClass(\"hide\");\n $(\".promoterText\").addClass(\"hide\");\n }\n else {\n $(\"#RetailerSearchContainer .retailerText\").removeClass(\"hide\");\n $(\".manufacturerText\").addClass(\"hide\");\n $(\"#PromoterRetailerSearchContainer .promoterText\").removeClass(\"hide\");\n }\n }\n processKey2(e) {\n if (e.keyCode == 13 || e.keyCode == 32) {\n if (this.searchResults.attr('id') == $(e.target).attr('id')) {\n this.takeSelection();\n e.preventDefault();\n }\n }\n }\n unbindEvents() {\n this.searchText.off('change');\n }\n manualForm(value) {\n this.storeManual = value;\n }\n setCallback(closeCallback) {\n this.closeCallback = closeCallback;\n }\n openSearch() {\n this.searchModal.foundation('open');\n return;\n }\n closeSearch() {\n this.searchModal.foundation('close');\n }\n setCountry(countryCode, countryName) {\n this.hiddenRetailerSearch.val(countryCode).trigger('change');\n }\n setPromoterCountry(countryCode, countryName) {\n this.hiddenPromoterRetailerSearch.val(countryCode).trigger('change');\n }\n setupRetailers() {\n this.searchRetailers();\n }\n changeCountry() {\n this.countryCode = this.hiddenRetailerSearch.val().toString();\n if (this.countryCode !== \"\") {\n this.searchRetailers();\n }\n }\n changePromoterCountry() {\n this.countryCode = this.hiddenPromoterRetailerSearch.val().toString();\n if (this.countryCode !== \"\") {\n this.searchRetailers();\n }\n }\n setSelection(e) {\n if (e.target.localName == \"li\") {\n $(\"li.selected\").removeClass('selected');\n $(e.target).addClass('selected');\n this.selectedValue.html($(e.target).html());\n this.searchResults.val($(e.target).attr('data-value'));\n this.selectedValue.parent().removeClass('hide');\n this.buttonSelect.removeClass('hide');\n }\n }\n takeSelection() {\n if (this.searchResults.val() != null && this.searchResults.val() != \"\") {\n this.closeSearch();\n this.closeCallback(Number.parseInt(this.searchResults.val().toString()), this.selectedValue.html());\n }\n }\n manualRetailer() {\n this.closeSearch();\n this.storeManual.open(true);\n }\n pauseSearchRetailers() {\n clearTimeout(this.searchDebounceTimer);\n this.searchDebounceTimer = setTimeout(() => {\n this.searchRetailers();\n }, 500);\n }\n searchRetailers() {\n $.ajax({\n type: \"get\",\n dataType: \"json\",\n url: window.irep.options.appUrl + \"SearchRetailers\",\n data: { CountryCode: this.countryCode, SearchText: this.searchText.val(), IsDre: false, Limit: 100 }\n }).done((d) => {\n this.searchResults.html(null);\n for (let i = 0; i < d.Data.length; i++) {\n let li = $(\"