{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./app/javascript/location_functions.js","webpack:///./app/javascript/packs/select_location_form.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","populateDropdown","dropdown","data","forEach","item","option","document","createElement","id","text","appendChild","handleRegionSelect","regionDropdown","getElementById","addEventListener","populateCountryDropdown","selectedRegion","countryDropdown","url","concat","innerHTML","disabled","fetch","then","response","json","selectedCountryId","dataset","options","getElementsByTagName","length","selected","event","Event","dispatchEvent","error","console","submitButton","form","actionDropdown","venueDropdown","selectedRegionValue","getSelectedAction","updateLabelsBasedOnAction","selectedAction","regionLabel","querySelector","countryLabel","venueLabel","textContent","log","selectedValue","selectedVenueId","e","preventDefault","year","region","country","alert","action","submit"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,qBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,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,MAAMJ,GACHK,MAAK,SAACC,GAAQ,OAAKA,EAASC,UAC5BF,MAAK,SAACrB,IAtBb,SAA0BD,EAAUC,GAClCA,EAAKC,SAAQ,SAACC,GACZ,IAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOpB,MAAQmB,EAAKI,GACpBH,EAAOI,KAAOL,EAAK7B,KACnB0B,EAASS,YAAYL,MAkBjBL,CAAiBwC,EAAetC,GAGhC,IAFA,IAAMkD,EAAkBZ,EAAcb,QAAQyB,gBACxCxB,EAAUY,EAAcX,qBAAqB,UAC1C7D,EAAI,EAAGA,EAAI4D,EAAQE,OAAQ9D,IAClC,GAAI4D,EAAQ5D,GAAGiB,QAAUmE,EAAiB,CAC1CxB,EAAQ5D,GAAG+D,UAAW,EACtB,UAKH,OACM,SAACI,GACNC,QAAQD,MAAM,uBAAwBA,SAQtCE,EAAe/B,SAASO,eAAe,iBACvCyB,EAAOhC,SAASwC,cAAc,yBAEpCT,EAAavB,iBAAiB,SAAS,SAASuC,GAC9CA,EAAEC,iBACF,IAAMV,EAAiBF,IACjBa,EAAOjD,SAASO,eAAe,QAAQ5B,MACvCuE,EAASlD,SAASO,eAAe,mBAAmB5B,MACpDwE,EAAUnD,SAASO,eAAe,oBAAoB5B,MAE5D,GAAuB,KAAnB2D,EAEF,OADAc,MAAM,4BACC,EAGT,GAAa,KAATH,EAEF,OADAG,MAAM,2BACC,EAGT,GAAuB,UAAnBd,EAA4B,CAC7B,GAAe,KAAXY,EAEH,OADAE,MAAM,yBACC,EAGT,GAAgB,KAAZD,EAEF,OADAC,MAAM,0BACC,EAQXrB,EAAahB,UAAW,EAGD,UAAnBuB,EACFN,EAAKqB,OAAS,kBACc,WAAnBf,IACTN,EAAKqB,OAAS,sBAGhBrB,EAAKsB,YAsDTrB,EAAezB,iBAAiB,UAAU,WAGxC6B,EAFuBJ,EAAetD","file":"js/select_location_form-2ad072550995a190ab82.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/packs/\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 8);\n","export function populateDropdown(dropdown, data) {\n data.forEach((item) => {\n const option = document.createElement(\"option\");\n option.value = item.id;\n option.text = item.name;\n dropdown.appendChild(option);\n });\n }\n\nexport function handleRegionSelect() {\n\n const regionDropdown = document.getElementById(\"region-dropdown\");\n\n regionDropdown.addEventListener(\"change\", function() {\n const selectedValue = regionDropdown.value;\n populateCountryDropdown(selectedValue);\n\n });\n }\n\nexport function populateCountryDropdown(selectedRegion) {\n const countryDropdown = document.getElementById(\"country-dropdown\");\n\n const url = `/locations/retrieve_children_of_location?id=${selectedRegion}`;\n\n countryDropdown.innerHTML = ``;\n countryDropdown.disabled = false;\n\n fetch(url)\n .then((response) => response.json())\n .then((data) => {\n populateDropdown(countryDropdown, data);\n const selectedCountryId = countryDropdown.dataset.selectedCountryId;\n const options = countryDropdown.getElementsByTagName(\"option\");\n for (let i = 0; i < options.length; i++) {\n if (options[i].value === selectedCountryId) {\n options[i].selected = true;\n const event = new Event('change');\n countryDropdown.dispatchEvent(event);\n break; // Stop the loop once the corresponding option is found and selected\n }\n }\n })\n .catch((error) => {\n console.error(\"Error fetching data:\", error);\n });\n \n\n\n\n }","import { populateDropdown, handleRegionSelect, populateCountryDropdown } from '../location_functions';\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n \n // Get references to the dropdown elements\n const actionDropdown = document.getElementById(\"action-dropdown\");\n const regionDropdown = document.getElementById(\"region-dropdown\");\n const countryDropdown = document.getElementById(\"country-dropdown\");\n const venueDropdown = document.getElementById(\"venue-dropdown\");\n\n const selectedRegionValue = regionDropdown.value\n\n // Disable country and venue dropdowns initially\n countryDropdown.disabled = true;\n venueDropdown.disabled = true;\n\n if (selectedRegionValue) {\n // If a region is selected, populate the country dropdown\n populateCountryDropdown(selectedRegionValue);\n // const countryDropdown = document.getElementById(\"country-dropdown\");\n // const selectedCountryValue = countryDropdown.value\n }\n\n\n\n // Function to populate a dropdown with options\n function populateDropdown(dropdown, data) {\n data.forEach((item) => {\n const option = document.createElement(\"option\");\n option.value = item.id;\n option.text = item.name;\n dropdown.appendChild(option);\n });\n }\n\n\n function handleCountrySelect() {\n countryDropdown.addEventListener(\"change\", function() {\n console.log(\"change event for countryDropdown detected\");\n console.log(\"countryDropdown.value\", countryDropdown.value);\n const selectedValue = countryDropdown.value;\n const url = `/locations/retrieve_children_of_location?id=${selectedValue}`;\n\n venueDropdown.innerHTML = ``;\n venueDropdown.disabled = false;\n\n fetch(url)\n .then((response) => response.json())\n .then((data) => {\n populateDropdown(venueDropdown, data);\n const selectedVenueId = venueDropdown.dataset.selectedVenueId;\n const options = venueDropdown.getElementsByTagName(\"option\");\n for (let i = 0; i < options.length; i++) {\n if (options[i].value === selectedVenueId) {\n options[i].selected = true;\n break\n }\n }\n }\n\n )\n .catch((error) => {\n console.error(\"Error fetching data:\", error);\n });\n\n });\n }\n // Function to handle submitting the form for different actions\n function handleFormSubmission() {\n\n const submitButton = document.getElementById(\"submit-button\");\n const form = document.querySelector('.location-select-form');\n \n submitButton.addEventListener(\"click\", function(e) {\n e.preventDefault();\n const selectedAction = getSelectedAction();\n const year = document.getElementById('year').value;\n const region = document.getElementById('region-dropdown').value;\n const country = document.getElementById('country-dropdown').value;\n\n if (selectedAction === '') {\n alert('Please choose an action');\n return false;\n }\n\n if (year === '') {\n alert('Please choose the year');\n return false;\n }\n\n if (selectedAction === 'input') {\n if (region === '') {\n alert('Please select region');\n return false;\n }\n\n if (country === '') {\n alert('Please select country');\n return false;\n }\n\n\n }\n\n\n\n submitButton.disabled = true;\n \n \n if (selectedAction === 'input') {\n form.action = \"/statistics/new\"; // Change to your actual endpoint for input statistics\n } else if (selectedAction === \"report\") {\n form.action = \"/statistics/report\"; // Change to your actual endpoint for generating a report\n }\n \n form.submit(); // Submit the form based on the updated action\n });\n }\n\n function submitForm() {\n const submitButton = document.getElementById(\"submit-button\");\n const form = document.querySelector('.location-select-form');\n submitButton.disabled = true;\n e.preventDefault();\n \n const selectedAction = getSelectedAction()\n \n if (selectedAction === 'input') {\n form.action = \"/statistics/new\"; // Change to your actual endpoint for input statistics\n } else if (selectedAction === \"report\") {\n form.action = \"/statistics/report\"; // Change to your actual endpoint for generating a report\n }\n \n form.submit(); // Submit the form based on the updated action\n\n }\n\n function getSelectedAction() {\n const actionDropdown = document.getElementById('action-dropdown'); \n const selectedAction = actionDropdown.value;\n\n return selectedAction\n }\n \n \n\n \n\n \n function updateLabelsBasedOnAction(selectedAction) {\n const regionLabel = document.querySelector('label[for=\"region-dropdown\"]');\n const countryLabel = document.querySelector('label[for=\"country-dropdown\"]');\n const venueLabel = document.querySelector('label[for=\"venue-dropdown\"]');\n\n if (selectedAction === 'input'){\n regionLabel.textContent = 'Region (Required) :'\n countryLabel.textContent = 'Country (Required) :'\n venueLabel.textContent = 'Venue (Optional) :'\n\n } else if (selectedAction === \"report\") {\n regionLabel.textContent = 'Region (Optional) :'\n countryLabel.textContent = 'Country (Optional) :'\n venueLabel.textContent = 'Venue (Optional) :'\n }\n }\n\n\n function handleActionSelect () {\n \n actionDropdown.addEventListener(\"change\", function() {\n const selectedAction = actionDropdown.value;\n\n updateLabelsBasedOnAction(selectedAction);\n });\n\n }\n\n \n const selectedAction = actionDropdown.value;\n updateLabelsBasedOnAction(selectedAction);\n\n handleRegionSelect();\n handleCountrySelect();\n handleFormSubmission();\n\n handleActionSelect();\n })"],"sourceRoot":""}