AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"tour_filters.min.js","sources":["../src/tour_filters.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * User tours filters.\n *\n * @module tool_usertours/tour_filters\n * @copyright 2025 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nconst ANY_VALUE = \"__ANYVA
LUE__\";\n\nexport const init = () => {\n // Initialize the category filter\n initConfigurationCategoryFilter();\n};\n\n/**\n * Initialize the category filter for the configuration page.\n */\nconst initConfigurationCategoryFilter = () => {\n const categorySelect = document.querySelector(\"[name='filter_category[]']\");\n const excludeSelect = document.querySelector(\"[name='filter_exclude_category[]']\");\n const excludeCategoriesContainer = document.getElementById('fitem_id_filter_exclude_category');\n\n if (categorySelect && excludeSelect) {\n // Add event listeners to update the exclude categories when the include categories change.\n categorySelect.addEventListener(\"change\", () => {\n updateExcludeCategories(categorySelect, excludeSelect, excludeCategoriesContainer);\n });\n\n // Initialize the exclude categories based on the selected include categories.\n updateExcludeCategories(categorySelect, excludeSelect, excludeCategoriesContainer);
\n }\n};\n\n/**\n * Adjust the height of a select element based on the number of options.\n *\n * @param {HTMLSelectElement} select\n */\nconst adjustHeight = (select) => {\n select.size = Math.min(select.options.length || 1, 10);\n};\n\n/**\n * Update the exclude categories based on the selected include categories.\n *\n * @param {HTMLSelectElement} categorySelect\n * @param {HTMLSelectElement} excludeSelect\n * @param {HTMLElement} excludeCategoriesContainer\n */\nconst updateExcludeCategories = (categorySelect, excludeSelect, excludeCategoriesContainer) => {\n // Get the selected categories and update the 'Any' option.\n const selectedCategories = new Set(Array.from(categorySelect.selectedOptions).map(option => option.value));\n\n // Get the selected exclude categories and create a map of options.\n const excludeSelected = new Set(Array.from(excludeSelect.selectedOptions).map(option => option.value));\n const excludeOptions = new Map();\n\n // Flag to check if 'Any' value is select
ed.\n const anySelected = selectedCategories.has(ANY_VALUE);\n Array.from(categorySelect.options).forEach(option => {\n const isNotAny = option.value !== ANY_VALUE;\n\n // If 'Any' is selected, include all options in excludeOptions.\n if (anySelected && isNotAny) {\n excludeOptions.set(option.value, option.text);\n } else if (isNotAny) {\n // Otherwise, check if the option is a child of any selected category.\n for (const selected of selectedCategories) {\n const selectedOption = categorySelect.querySelector(`option[value=\"${selected}\"]`);\n if (option.text.startsWith(`${selectedOption.text} / `)) {\n excludeOptions.set(option.value, option.text);\n break;\n }\n }\n }\n });\n if (excludeOptions.size) {\n // Update the exclude categories select element.\n excludeSelect.innerHTML = '';\n Array.from(excludeOptions)\n
.sort(([, a], [, b]) => a.localeCompare(b))\n .forEach(([key, value]) => {\n const option = document.createElement(\"option\");\n option.value = key;\n option.text = value;\n if (excludeSelected.has(key)) {\n option.selected = true;\n }\n excludeSelect.appendChild(option);\n });\n\n // Adjust the height of the select elements.\n adjustHeight(excludeSelect);\n // Show the exclude categories container if it was hidden.\n if (excludeCategoriesContainer.classList.contains('d-none')) {\n excludeCategoriesContainer.classList.remove('d-none');\n }\n } else {\n // Hide the exclude categories container when no child categories exist.\n if (!excludeCategoriesContainer.classList.contains('d-none')) {\n excludeCategoriesContainer.classList.add('d-none');\n }\n // Clear selections to prevent sub
mitting excluded categories when container is hidden.\n excludeSelect.innerHTML = '';\n }\n\n};\n"],"names":["initConfigurationCategoryFilter","categorySelect","document","querySelector","excludeSelect","excludeCategoriesContainer","getElementById","addEventListener","updateExcludeCategories","selectedCategories","Set","Array","from","selectedOptions","map","option","value","excludeSelected","excludeOptions","Map","anySelected","has","select","options","forEach","isNotAny","set","text","selected","selectedOption","startsWith","size","innerHTML","sort","a","b","localeCompare","_ref3","key","createElement","appendChild","Math","min","length","classList","contains","remove","add"],"mappings":"gKAwBoB,KAEhBA,yCAMEA,gCAAkC,WAC9BC,eAAiBC,SAASC,cAAc,8BACxCC,cAAgBF,SAASC,cAAc,sCACvCE,2BAA6BH,SAASI,eAAe,oCAEvDL,gBAAkBG,gBAElBH,eAAeM,iBAAiB,UAAU,KACtCC,wBAAwBP,eAAgBG,cAAeC,+BAI3DG,wBAAwBP,eAAgBG,cAAeC,8BAoBzDG,wBAA0B,CAACP,eAAgBG,cAAeC,oCAEtDI,mBAAqB,IAAIC,IAAIC,MAAMC,KAAKX,eAAeY,iBAAiBC,KAAIC,QAAUA,OAAOC,SA
G7FC,gBAAkB,IAAIP,IAAIC,MAAMC,KAAKR,cAAcS,iBAAiBC,KAAIC,QAAUA,OAAOC,SACzFE,eAAiB,IAAIC,IAGrBC,YAAcX,mBAAmBY,IAnDzB,gBA+BIC,IAAAA,OAqBlBX,MAAMC,KAAKX,eAAesB,SAASC,SAAQT,eACjCU,SArDI,iBAqDOV,OAAOC,SAGpBI,aAAeK,SACfP,eAAeQ,IAAIX,OAAOC,MAAOD,OAAOY,WACrC,GAAIF,aAEF,MAAMG,YAAYnB,mBAAoB,OACjCoB,eAAiB5B,eAAeE,sCAA+ByB,mBACjEb,OAAOY,KAAKG,qBAAcD,eAAeF,aAAY,CACrDT,eAAeQ,IAAIX,OAAOC,MAAOD,OAAOY,iBAMpDT,eAAea,MAEf3B,cAAc4B,UAAY,GAC1BrB,MAAMC,KAAKM,gBACNe,MAAK,oBAAIC,UAAOC,gBAAOD,EAAEE,cAAcD,MACvCX,SAAQa,YAAEC,IAAKtB,mBACND,OAASb,SAASqC,cAAc,UACtCxB,OAAOC,MAAQsB,IACfvB,OAAOY,KAAOX,MACVC,gBAAgBI,IAAIiB,OACpBvB,OAAOa,UAAW,GAEtBxB,cAAcoC,YAAYzB,YAlDpBO,OAsDDlB,eArDV2B,KAAOU,KAAKC,IAAIpB,OAAOC,QAAQoB,QAAU,EAAG,IAuD3CtC,2BAA2BuC,UAAUC,SAAS,WAC9CxC,2BAA2BuC,UAAUE,OAAO,YAI3CzC,2BAA2BuC,UAAUC,SAAS,WAC/CxC,2BAA2BuC,UAAUG,IAAI,UAG7C3C,cAAc4B,UAAY"}