diff --git a/amd/build/coursefilter.min.js b/amd/build/coursefilter.min.js index 9122415..0a2d5e0 100644 --- a/amd/build/coursefilter.min.js +++ b/amd/build/coursefilter.min.js @@ -1,4 +1,4 @@ -define("block_townsquare/coursefilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){checkboxes.forEach((function(checkbox){checkbox.addEventListener("change",(function(){const courseid=checkbox.id;document.querySelectorAll(".townsquare_letter.ts_timefilter_active.ts_letterfilter_active").forEach((function(letter){let letterCourseId=letter.querySelector(".townsquareletter_course").id;courseid===letterCourseId&&(checkbox.checked?letter.classList.add("ts_coursefilter_active"):letter.classList.remove("ts_coursefilter_active"))}))}))}))}; +define("block_townsquare/coursefilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){checkboxes.forEach((function(checkbox){checkbox.addEventListener("change",(function(){const courseid=checkbox.id;document.querySelectorAll(".townsquare_letter.ts_timefilter_approved.ts_letterfilter_approved").forEach((function(letter){let letterCourseId=letter.querySelector(".townsquareletter_course").id;courseid===letterCourseId&&(checkbox.checked?letter.classList.add("ts_coursefilter_approved"):letter.classList.remove("ts_coursefilter_approved"))}))}))}))}; /** * Javascript for the course filter * diff --git a/amd/build/coursefilter.min.js.map b/amd/build/coursefilter.min.js.map index de47173..f46ae26 100644 --- a/amd/build/coursefilter.min.js.map +++ b/amd/build/coursefilter.min.js.map @@ -1 +1 @@ -{"version":3,"file":"coursefilter.min.js","sources":["../src/coursefilter.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 .\n\n/**\n * Javascript for the course filter\n *\n * This file implements 1 functionality:\n * - Checks the checkboxes of the course filter and hides content from courses if the checkbox is not checked.\n *\n * @module block_townsquare/coursefilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant checkboxes.\nconst checkboxes = document.querySelectorAll('.ts_course_checkbox');\n\n/**\n * Init function\n */\nexport function init() {\n checkboxes.forEach(function(checkbox) {\n checkbox.addEventListener('change', function() {\n // Get the courseid associated with the checkbox\n const courseid = checkbox.id;\n\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.ts_timefilter_active.ts_letterfilter_active');\n\n // Loop through each letter mark it as \"active\" or not based on checkbox state and the letter id.\n letters.forEach(function(letter) {\n let letterCourseId = letter.querySelector('.townsquareletter_course').id;\n\n if (courseid === letterCourseId) {\n if (checkbox.checked) {\n letter.classList.add('ts_coursefilter_active'); // Mark the letter as \"active\".\n } else {\n letter.classList.remove('ts_coursefilter_active'); // Mark the letter as \"not active\".\n }\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","courseid","id","document","querySelectorAll","letter","letterCourseId","querySelector","checked","classList","add","remove"],"mappings":"6IAgCO,WACHA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,WAEhC,MAAMC,SAAWF,SAASG,GAIVC,SAASC,iBAAiB,kEAGlCN,SAAQ,SAASO,QACrB,IAAIC,eAAiBD,OAAOE,cAAc,4BAA4BL,GAElED,WAAaK,iBACTP,SAASS,QACTH,OAAOI,UAAUC,IAAI,0BAErBL,OAAOI,UAAUE,OAAO;;;;;;;;;;;AAvBhD,MAAMd,WAAaM,SAASC,iBAAiB,sBA6B5C"} \ No newline at end of file +{"version":3,"file":"coursefilter.min.js","sources":["../src/coursefilter.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 .\n\n/**\n * Javascript for the course filter\n *\n * This file implements 1 functionality:\n * - Checks the checkboxes of the course filter and hides content from courses if the checkbox is not checked.\n *\n * @module block_townsquare/coursefilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant checkboxes.\nconst checkboxes = document.querySelectorAll('.ts_course_checkbox');\n\n/**\n * Init function\n */\nexport function init() {\n checkboxes.forEach(function(checkbox) {\n checkbox.addEventListener('change', function() {\n // Get the courseid associated with the checkbox.\n const courseid = checkbox.id;\n\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.ts_timefilter_approved.ts_letterfilter_approved');\n\n // Loop through each letter mark it as \"active\" or not based on checkbox state and the letter id.\n letters.forEach(function(letter) {\n let letterCourseId = letter.querySelector('.townsquareletter_course').id;\n\n if (courseid === letterCourseId) {\n if (checkbox.checked) {\n letter.classList.add('ts_coursefilter_approved'); // Mark the letter as \"active\" or \"approved\".\n } else {\n letter.classList.remove('ts_coursefilter_approved'); // Mark the letter as \"not active\".\n }\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","courseid","id","document","querySelectorAll","letter","letterCourseId","querySelector","checked","classList","add","remove"],"mappings":"6IAgCO,WACHA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,WAEhC,MAAMC,SAAWF,SAASG,GAIVC,SAASC,iBAAiB,sEAGlCN,SAAQ,SAASO,QACrB,IAAIC,eAAiBD,OAAOE,cAAc,4BAA4BL,GAElED,WAAaK,iBACTP,SAASS,QACTH,OAAOI,UAAUC,IAAI,4BAErBL,OAAOI,UAAUE,OAAO;;;;;;;;;;;AAvBhD,MAAMd,WAAaM,SAASC,iBAAiB,sBA6B5C"} \ No newline at end of file diff --git a/amd/build/filtercontroller.min.js b/amd/build/filtercontroller.min.js index 4a17ab0..9d9a1bc 100644 --- a/amd/build/filtercontroller.min.js +++ b/amd/build/filtercontroller.min.js @@ -1,4 +1,4 @@ -define("block_townsquare/filtercontroller",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){letters.forEach((function(letter){letter.classList.add("ts_coursefilter_active"),letter.classList.add("ts_timefilter_active"),letter.classList.add("ts_letterfilter_active")})),letters.forEach((function(letter){new MutationObserver((function(mutations){mutations.forEach((function(mutation){if("class"===mutation.attributeName){let coursefilter=letter.classList.contains("ts_coursefilter_active"),timefilter=letter.classList.contains("ts_timefilter_active"),letterfilter=letter.classList.contains("ts_letterfilter_active");letter.style.display=coursefilter&&timefilter&&letterfilter?"block":"none"}}))})).observe(letter,{attributes:!0})}))}; +define("block_townsquare/filtercontroller",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){letters.forEach((function(letter){letter.classList.add("ts_coursefilter_approved"),letter.classList.add("ts_timefilter_approved"),letter.classList.add("ts_letterfilter_approved")})),letters.forEach((function(letter){new MutationObserver((function(mutations){mutations.forEach((function(mutation){if("class"===mutation.attributeName){let coursefilter=letter.classList.contains("ts_coursefilter_approved"),timefilter=letter.classList.contains("ts_timefilter_approved"),letterfilter=letter.classList.contains("ts_letterfilter_approved");letter.style.display=coursefilter&&timefilter&&letterfilter?"block":"none"}}))})).observe(letter,{attributes:!0})}))}; /** * Javascript to show/hide letters based on all filters * diff --git a/amd/build/filtercontroller.min.js.map b/amd/build/filtercontroller.min.js.map index ed17974..35efe35 100644 --- a/amd/build/filtercontroller.min.js.map +++ b/amd/build/filtercontroller.min.js.map @@ -1 +1 @@ -{"version":3,"file":"filtercontroller.min.js","sources":["../src/filtercontroller.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 .\n\n/**\n * Javascript to show/hide letters based on all filters\n *\n * This file implements 1 functionality:\n * - If the \"save settings\" button is pressed, store the settings in the database.\n *\n * @module block_townsquare/filtercontroller\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get all letters from townsquare.\nconst letters = document.querySelectorAll('.townsquare_letter');\n\n/**\n * Init function\n */\nexport function init() {\n // First step: activate every letter by adding the filter classes.\n letters.forEach(function(letter) {\n letter.classList.add('ts_coursefilter_active');\n letter.classList.add('ts_timefilter_active');\n letter.classList.add('ts_letterfilter_active');\n });\n\n // Add a mutation listener to each letter.\n letters.forEach(function(letter) {\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(mutation) {\n if (mutation.attributeName === 'class') {\n // If the class of the letter changes, check if the letter should be shown or hidden.\n let coursefilter = letter.classList.contains('ts_coursefilter_active');\n let timefilter = letter.classList.contains('ts_timefilter_active');\n let letterfilter = letter.classList.contains('ts_letterfilter_active');\n\n // If all filters are active, show the letter.\n if (coursefilter && timefilter && letterfilter) {\n letter.style.display = 'block';\n } else {\n letter.style.display = 'none';\n }\n }\n });\n });\n\n observer.observe(letter, {attributes: true});\n });\n}\n"],"names":["letters","forEach","letter","classList","add","MutationObserver","mutations","mutation","attributeName","coursefilter","contains","timefilter","letterfilter","style","display","observe","attributes","document","querySelectorAll"],"mappings":"iJAgCO,WAEHA,QAAQC,SAAQ,SAASC,QACrBA,OAAOC,UAAUC,IAAI,0BACrBF,OAAOC,UAAUC,IAAI,wBACrBF,OAAOC,UAAUC,IAAI,6BAIzBJ,QAAQC,SAAQ,SAASC,QACJ,IAAIG,kBAAiB,SAASC,WAC3CA,UAAUL,SAAQ,SAASM,UACvB,GAA+B,UAA3BA,SAASC,cAA2B,CAEpC,IAAIC,aAAeP,OAAOC,UAAUO,SAAS,0BACzCC,WAAaT,OAAOC,UAAUO,SAAS,wBACvCE,aAAeV,OAAOC,UAAUO,SAAS,0BAIzCR,OAAOW,MAAMC,QADbL,cAAgBE,YAAcC,aACP,QAEA,cAM9BG,QAAQb,OAAQ,CAACc,YAAY;;;;;;;;;;;AAjC9C,MAAMhB,QAAUiB,SAASC,iBAAiB,qBAmCzC"} \ No newline at end of file +{"version":3,"file":"filtercontroller.min.js","sources":["../src/filtercontroller.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 .\n\n/**\n * Javascript to show/hide letters based on all filters\n *\n * This file implements 1 functionality:\n * - If the \"save settings\" button is pressed, store the settings in the database.\n *\n * @module block_townsquare/filtercontroller\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get all letters from townsquare.\nconst letters = document.querySelectorAll('.townsquare_letter');\n\n/**\n * Init function\n */\nexport function init() {\n // First step: activate every letter by adding the filter classes.\n letters.forEach(function(letter) {\n letter.classList.add('ts_coursefilter_approved');\n letter.classList.add('ts_timefilter_approved');\n letter.classList.add('ts_letterfilter_approved');\n });\n\n // Add a mutation listener to each letter.\n letters.forEach(function(letter) {\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(mutation) {\n if (mutation.attributeName === 'class') {\n // If the class of the letter changes, check if the letter should be shown or hidden.\n let coursefilter = letter.classList.contains('ts_coursefilter_approved');\n let timefilter = letter.classList.contains('ts_timefilter_approved');\n let letterfilter = letter.classList.contains('ts_letterfilter_approved');\n\n // If all filters are active, show the letter.\n if (coursefilter && timefilter && letterfilter) {\n letter.style.display = 'block';\n } else {\n letter.style.display = 'none';\n }\n }\n });\n });\n\n observer.observe(letter, {attributes: true});\n });\n}\n"],"names":["letters","forEach","letter","classList","add","MutationObserver","mutations","mutation","attributeName","coursefilter","contains","timefilter","letterfilter","style","display","observe","attributes","document","querySelectorAll"],"mappings":"iJAgCO,WAEHA,QAAQC,SAAQ,SAASC,QACrBA,OAAOC,UAAUC,IAAI,4BACrBF,OAAOC,UAAUC,IAAI,0BACrBF,OAAOC,UAAUC,IAAI,+BAIzBJ,QAAQC,SAAQ,SAASC,QACJ,IAAIG,kBAAiB,SAASC,WAC3CA,UAAUL,SAAQ,SAASM,UACvB,GAA+B,UAA3BA,SAASC,cAA2B,CAEpC,IAAIC,aAAeP,OAAOC,UAAUO,SAAS,4BACzCC,WAAaT,OAAOC,UAAUO,SAAS,0BACvCE,aAAeV,OAAOC,UAAUO,SAAS,4BAIzCR,OAAOW,MAAMC,QADbL,cAAgBE,YAAcC,aACP,QAEA,cAM9BG,QAAQb,OAAQ,CAACc,YAAY;;;;;;;;;;;AAjC9C,MAAMhB,QAAUiB,SAASC,iBAAiB,qBAmCzC"} \ No newline at end of file diff --git a/amd/build/letterfilter.min.js b/amd/build/letterfilter.min.js index 880a8cd..a244a11 100644 --- a/amd/build/letterfilter.min.js +++ b/amd/build/letterfilter.min.js @@ -1,4 +1,4 @@ -define("block_townsquare/letterfilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){checkboxes.forEach((function(checkbox){checkbox.addEventListener("change",(function(){const lettername=checkbox.id;document.querySelectorAll(".townsquare_letter."+lettername+".ts_timefilter_active.ts_coursefilter_active").forEach((function(letter){checkbox.checked?letter.classList.add("ts_letterfilter_active"):letter.classList.remove("ts_letterfilter_active")}))}))}))}; +define("block_townsquare/letterfilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){checkboxes.forEach((function(checkbox){checkbox.addEventListener("change",(function(){const lettername=checkbox.id;document.querySelectorAll(".townsquare_letter."+lettername+".ts_timefilter_approved.ts_coursefilter_approved").forEach((function(letter){checkbox.checked?letter.classList.add("ts_letterfilter_approved"):letter.classList.remove("ts_letterfilter_approved")}))}))}))}; /** * Javascript for the letter filter * diff --git a/amd/build/letterfilter.min.js.map b/amd/build/letterfilter.min.js.map index 02c4ab5..ca989b8 100644 --- a/amd/build/letterfilter.min.js.map +++ b/amd/build/letterfilter.min.js.map @@ -1 +1 @@ -{"version":3,"file":"letterfilter.min.js","sources":["../src/letterfilter.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 .\n\n/**\n * Javascript for the letter filter\n *\n * This file implements 1 functionality:\n * - Checks the checkboxes of the letter filter and hides content from courses if the checkbox is not checked.\n *\n * @module block_townsquare/letterfilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant checkboxes.\nconst checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n/**\n * Init function\n */\nexport function init() {\n checkboxes.forEach(function(checkbox) {\n checkbox.addEventListener('change', function() {\n // Get the letter name associated with the checkbox.\n const lettername = checkbox.id;\n\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.' + lettername +\n '.ts_timefilter_active.ts_coursefilter_active');\n\n // Loop through each letter and hide/show based on checkbox state.\n letters.forEach(function(letter) {\n if (checkbox.checked) {\n letter.classList.add('ts_letterfilter_active'); // Mark the letter as \"active\".\n } else {\n letter.classList.remove('ts_letterfilter_active'); // Mark the letter as \"not active\".\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","lettername","id","document","querySelectorAll","letter","checked","classList","add","remove"],"mappings":"6IAgCO,WACHA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,WAEhC,MAAMC,WAAaF,SAASG,GAIZC,SAASC,iBAAiB,sBAAwBH,WACxB,gDAGlCH,SAAQ,SAASO,QACjBN,SAASO,QACTD,OAAOE,UAAUC,IAAI,0BAErBH,OAAOE,UAAUE,OAAO;;;;;;;;;;;AArB5C,MAAMZ,WAAaM,SAASC,iBAAiB,sBA0B5C"} \ No newline at end of file +{"version":3,"file":"letterfilter.min.js","sources":["../src/letterfilter.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 .\n\n/**\n * Javascript for the letter filter\n *\n * This file implements 1 functionality:\n * - Checks the checkboxes of the letter filter and hides content from courses if the checkbox is not checked.\n *\n * @module block_townsquare/letterfilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant checkboxes.\nconst checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n/**\n * Init function\n */\nexport function init() {\n checkboxes.forEach(function(checkbox) {\n checkbox.addEventListener('change', function() {\n // Get the letter name associated with the checkbox.\n const lettername = checkbox.id;\n\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.' + lettername +\n '.ts_timefilter_approved.ts_coursefilter_approved');\n\n // Loop through each letter and hide/show based on checkbox state.\n letters.forEach(function(letter) {\n if (checkbox.checked) {\n letter.classList.add('ts_letterfilter_approved'); // Mark the letter as \"active\" or \"approved\".\n } else {\n letter.classList.remove('ts_letterfilter_approved'); // Mark the letter as \"not active\".\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","lettername","id","document","querySelectorAll","letter","checked","classList","add","remove"],"mappings":"6IAgCO,WACHA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,WAEhC,MAAMC,WAAaF,SAASG,GAIZC,SAASC,iBAAiB,sBAAwBH,WACxB,oDAGlCH,SAAQ,SAASO,QACjBN,SAASO,QACTD,OAAOE,UAAUC,IAAI,4BAErBH,OAAOE,UAAUE,OAAO;;;;;;;;;;;AArB5C,MAAMZ,WAAaM,SAASC,iBAAiB,sBA0B5C"} \ No newline at end of file diff --git a/amd/build/postletter.min.js.map b/amd/build/postletter.min.js.map index fde6c82..c3ade26 100644 --- a/amd/build/postletter.min.js.map +++ b/amd/build/postletter.min.js.map @@ -1 +1 @@ -{"version":3,"file":"postletter.min.js","sources":["../src/postletter.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 .\n\nimport {getString} from \"core/str\";\nimport {prefetchStrings} from 'core/prefetch';\n\n/**\n * Javascript for the post letter\n *\n * This file implements 2 functionalities:\n * - cuts posts that have many characters and shows a \"see more\" Button to see the whole text.\n * - Unnecessary

Tags from the Database are being replaced with line breaks to make the text more readable.\n *\n * @module block_townsquare/postletter\n * @copyright 2023 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst contentElements = document.getElementsByClassName('postletter_message');\nconst buttons = document.getElementsByClassName('townsquare_showmore');\nconst originalTexts = [];\n\nconst Selectors = {\n actions: {\n seemorebutton: '[data-action=\"block_townsquare/showmore_button\"]',\n },\n};\n\n/**\n * Init function\n *\n * The function can cut the text or extract paragraphs of a post.\n */\nexport function init() {\n contentElements.forEach(\n (element) => {\n // Replace all

within the text with simple line breaks..\n replaceParagraghTags(element);\n\n // Check if the text is too long.\n if (element.textContent.length >= 250) {\n // If the text is too long, cut it.\n originalTexts[element.id] = element.innerHTML;\n cutString(element);\n element.parentElement.insertAdjacentHTML('beforeend', '

');\n buttons[element.id].setAttribute('showmore', 'true');\n } else {\n // If the text is not too long, hide the show more button.\n buttons[element.id].style.display = \"none\";\n }\n }\n );\n\n // Get the strings for the show more/show less button.\n prefetchStrings('moodle', ['showmore', 'showless',]);\n\n // Add event listeners for the show more Button.\n addEventListener();\n}\n\n/**\n * Function to cut a String at a length of 250 characters.\n * The function does not cut within a word or after a space.\n * If the cutting point is within a word, the function searches for the next space and cuts there.\n * @param {object} element\n */\nfunction cutString(element) {\n let text = element.textContent;\n let index = 250;\n while (text.charAt(index) != \" \") {\n index++;\n }\n element.innerHTML = text.substring(0,index);\n}\n\n/**\n * Event listener for the show more/show less button.\n */\nconst addEventListener = () => {\n document.addEventListener('click', e => {\n if (e.target.closest(Selectors.actions.seemorebutton)) {\n // Get the id of the clicked element.\n let letterid = e.target.id;\n contentElements.forEach(\n (element) => {\n if (element.id == letterid) {\n if (buttons[letterid].getAttribute('showmore') == 'true') {\n element.innerHTML = originalTexts[letterid];\n changeButtonString(letterid, false);\n } else {\n cutString(element);\n changeButtonString(letterid, true);\n }\n }\n }\n );\n }\n });\n};\n\n/**\n * Changes the button strings.\n * @param {string} index Which button should be changed\n * @param {boolean} toshowmore a boolean that indicates if the button should show more or less\n */\nasync function changeButtonString(index, toshowmore) {\n if (toshowmore == true) {\n buttons[index].textContent = await getString('showmore', 'moodle');\n buttons[index].setAttribute('showmore', 'true');\n } else {\n buttons[index].textContent = await getString('showless', 'moodle');\n buttons[index].setAttribute('showmore', 'false');\n }\n}\n\n/**\n * Removes in a text all   and surrounding

tags excluding the first occurrence.\n *\n * Helper function to make post look better.\n * @param {object} element\n */\nasync function replaceParagraghTags(element) {\n // Identify and store the first

and

tags\n let message = element.innerHTML;\n const firstPTag = message.indexOf('

');\n const lastPTag = message.lastIndexOf('

');\n\n // Remove   and surrounding

tags excluding the first occurrence\n message = message.replace(/

 <\\/p>/g, '').replace(/ /g, '');\n\n // Replace

tags with
excluding the first occurrence\n message = message.substring(0, firstPTag + 3) +\n message.substring(firstPTag + 3, lastPTag).replace(/

/g, '
').replace(/<\\/p>/g, '') +\n message.substring(lastPTag);\n element.innerHTML = message;\n}"],"names":["contentElements","forEach","element","async","message","innerHTML","firstPTag","indexOf","lastPTag","lastIndexOf","replace","substring","replaceParagraghTags","textContent","length","originalTexts","id","cutString","parentElement","insertAdjacentHTML","buttons","setAttribute","style","display","prefetchStrings","addEventListener","document","getElementsByClassName","Selectors","seemorebutton","text","index","charAt","e","target","closest","letterid","getAttribute","changeButtonString","toshowmore","getString"],"mappings":"qLA6CO,WACHA,gBAAgBC,SACXC,WAsFTC,eAAoCD,SAEhC,IAAIE,QAAUF,QAAQG,UACtB,MAAMC,UAAYF,QAAQG,QAAQ,OAC5BC,SAAWJ,QAAQK,YAAY,Q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Aa,WAAY,UAExCD,QAAQW,OAAOlB,kBAAoB,EAAA2B,gBAAU,WAAY,UACzDpB,QAAQW,OAAOV,aAAa,WAAY,UAwB/C"} \ No newline at end of file +{"version":3,"file":"postletter.min.js","sources":["../src/postletter.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 .\n\nimport {getString} from \"core/str\";\nimport {prefetchStrings} from 'core/prefetch';\n\n/**\n * Javascript for the post letter\n *\n * This file implements 2 functionalities:\n * - cuts posts that have many characters and shows a \"see more\" Button to see the whole text.\n * - Unnecessary

Tags from the Database are being replaced with line breaks to make the text more readable.\n *\n * @module block_townsquare/postletter\n * @copyright 2023 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst contentElements = document.getElementsByClassName('postletter_message');\nconst buttons = document.getElementsByClassName('townsquare_showmore');\nconst originalTexts = [];\n\nconst Selectors = {\n actions: {\n seemorebutton: '[data-action=\"block_townsquare/showmore_button\"]',\n },\n};\n\n/**\n * Init function\n *\n * The function can cut the text or extract paragraphs of a post.\n */\nexport function init() {\n contentElements.forEach(\n (element) => {\n // Replace all

within the text with simple line breaks..\n replaceParagraghTags(element);\n\n // Check if the text is too long.\n if (element.textContent.length >= 250) {\n // If the text is too long, cut it.\n originalTexts[element.id] = element.innerHTML;\n cutString(element);\n element.parentElement.insertAdjacentHTML('beforeend', '

');\n buttons[element.id].setAttribute('showmore', 'true');\n } else {\n // If the text is not too long, hide the show more button.\n buttons[element.id].style.display = \"none\";\n }\n }\n );\n\n // Get the strings for the show more/show less button.\n prefetchStrings('moodle', ['showmore', 'showless',]);\n\n // Add event listeners for the show more Button.\n addEventListener();\n}\n\n/**\n * Function to cut a String at a length of 250 characters.\n * The function does not cut within a word or after a space.\n * If the cutting point is within a word, the function searches for the next space and cuts there.\n * @param {object} element\n */\nfunction cutString(element) {\n let text = element.textContent;\n let index = 250;\n while (text.charAt(index) != \" \") {\n index++;\n }\n element.innerHTML = text.substring(0,index);\n}\n\n/**\n * Event listener for the show more/show less button.\n */\nconst addEventListener = () => {\n document.addEventListener('click', e => {\n if (e.target.closest(Selectors.actions.seemorebutton)) {\n // Get the id of the clicked element.\n let letterid = e.target.id;\n contentElements.forEach(\n (element) => {\n if (element.id == letterid) {\n if (buttons[letterid].getAttribute('showmore') == 'true') {\n element.innerHTML = originalTexts[letterid];\n changeButtonString(letterid, false);\n } else {\n cutString(element);\n changeButtonString(letterid, true);\n }\n }\n }\n );\n }\n });\n};\n\n/**\n * Changes the button strings.\n * @param {string} index Which button should be changed\n * @param {boolean} toshowmore a boolean that indicates if the button should show more or less\n */\nasync function changeButtonString(index, toshowmore) {\n if (toshowmore == true) {\n buttons[index].textContent = await getString('showmore', 'moodle');\n buttons[index].setAttribute('showmore', 'true');\n } else {\n buttons[index].textContent = await getString('showless', 'moodle');\n buttons[index].setAttribute('showmore', 'false');\n }\n}\n\n/**\n * Removes in a text all   and surrounding

tags excluding the first occurrence.\n *\n * Helper function to make post look better.\n * @param {object} element\n */\nasync function replaceParagraghTags(element) {\n // Identify and store the first

and

tags.\n let message = element.innerHTML;\n const firstPTag = message.indexOf('

');\n const lastPTag = message.lastIndexOf('

');\n\n // Remove   and surrounding

tags excluding the first occurrence.\n message = message.replace(/

 <\\/p>/g, '').replace(/ /g, '');\n\n // Replace

tags with
excluding the first occurrence.\n message = message.substring(0, firstPTag + 3) +\n message.substring(firstPTag + 3, lastPTag).replace(/

/g, '
').replace(/<\\/p>/g, '') +\n message.substring(lastPTag);\n element.innerHTML = message;\n}"],"names":["contentElements","forEach","element","async","message","innerHTML","firstPTag","indexOf","lastPTag","lastIndexOf","replace","substring","replaceParagraghTags","textContent","length","originalTexts","id","cutString","parentElement","insertAdjacentHTML","buttons","setAttribute","style","display","prefetchStrings","addEventListener","document","getElementsByClassName","Selectors","seemorebutton","text","index","charAt","e","target","closest","letterid","getAttribute","changeButtonString","toshowmore","getString"],"mappings":"qLA6CO,WACHA,gBAAgBC,SACXC,WAsFTC,eAAoCD,SAEhC,IAAIE,QAAUF,QAAQG,UACtB,MAAMC,UAAYF,QAAQG,QAAQ,OAC5BC,SAAWJ,QAAQK,YAAY,QAGrCL,QAAUA,QAAQM,QAAQ,kBAAmB,IAAIA,QAAQ,UAAW,IAGpEN,QAAUA,QAAQO,UAAU,EAAGL,UAAY,GACvCF,QAAQO,UAAUL,UAAY,EAAGE,UAAUE,QAAQ,OAAQ,QAAQA,QAAQ,SAAU,IACrFN,QAAQO,UAAUH,UACtBN,QAAQG,UAAYD,QAjGZQ,CAAqBV,SAGjBA,QAAQW,YAAYC,QAAU,KAE9BC,cAAcb,QAAQc,IAAMd,QAAQG,UACpCY,UAAUf,SACVA,QAAQgB,cAAcC,mBAAmB,YAAa,OACtDC,QAAQlB,QAAQc,IAAIK,aAAa,WAAY,SAG7CD,QAAQlB,QAAQc,IAAIM,MAAMC,QAAU,WAMhD,EAAAC,2BAAgB,SAAU,CAAC,WAAY,aAGvCC;;;;;;;;;;;;AAvCJ,MAAMzB,gBAAkB0B,SAASC,uBAAuB,sBAClDP,QAAUM,SAASC,uBAAuB,uBAC1CZ,cAAgB,GAEhBa,kBACO,CACLC,cAAe,oDA0CvB,SAASZ,UAAUf,SACf,IAAI4B,KAAO5B,QAAQW,YACfkB,MAAQ,IACZ,KAA6B,KAAtBD,KAAKE,OAAOD,QACfA,QAEJ7B,QAAQG,UAAYyB,KAAKnB,UAAU,EAAEoB,OAMzC,MAAMN,iBAAmBA,KACrBC,SAASD,iBAAiB,SAASQ,IAC/B,GAAIA,EAAEC,OAAOC,QAAQP,kBAAkBC,eAAgB,CAEnD,IAAIO,SAAWH,EAAEC,OAAOlB,GACxBhB,gBAAgBC,SACXC,UACOA,QAAQc,IAAMoB,WACoC,QAA9ChB,QAAQgB,UAAUC,aAAa,aAC/BnC,QAAQG,UAAYU,cAAcqB,UAClCE,mBAAmBF,UAAU,KAE7BnB,UAAUf,SACVoC,mBAAmBF,UAAU,WAMnD,EAQNjC,eAAemC,mBAAmBP,MAAOQ,YACnB,GAAdA,YACAnB,QAAQW,OAAOlB,kBAAoB,EAAA2B,gBAAU,WAAY,UACzDpB,QAAQW,OAAOV,aAAa,WAAY,UAExCD,QAAQW,OAAOlB,kBAAoB,EAAA2B,gBAAU,WAAY,UACzDpB,QAAQW,OAAOV,aAAa,WAAY,UAwB/C"} \ No newline at end of file diff --git a/amd/build/timefilter.min.js b/amd/build/timefilter.min.js index 8205054..d2347f9 100644 --- a/amd/build/timefilter.min.js +++ b/amd/build/timefilter.min.js @@ -9,6 +9,6 @@ define("block_townsquare/timefilter",["exports"],(function(_exports){Object.defi * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const alltimebutton=document.querySelectorAll(".ts_all_time_button"),futureradiobuttons=document.querySelectorAll(".ts_future_time_button"),pastradiobuttons=document.querySelectorAll(".ts_past_time_button");let currenttime,timestart,timeend,addstarttime,addendtime;function executefilter(starttime,endtime,addstarttime,addendtime,buttonstate){document.querySelectorAll(".townsquare_letter.ts_coursefilter_active.ts_letterfilter_active").forEach((function(letter){let lettertime=letter.querySelector(".townsquareletter_date").id;buttonstate&&lettertime>=starttime&&lettertime<=endtime||lettertime>=addstarttime&&lettertime<=addendtime?letter.classList.add("ts_timefilter_active"):letter.classList.remove("ts_timefilter_active")}))}function convertidtotime(id){switch(id){case"ts_time_all":return 15778463;case"ts_time_next_twodays":case"ts_time_last_twodays":return 172800;case"ts_time_next_fivedays":case"ts_time_last_fivedays":return 432e3;case"ts_time_next_week":case"ts_time_last_week":return 604800;case"ts_time_next_month":case"ts_time_last_month":return 2592e3}}})); +const alltimebutton=document.querySelectorAll(".ts_all_time_button"),futureradiobuttons=document.querySelectorAll(".ts_future_time_button"),pastradiobuttons=document.querySelectorAll(".ts_past_time_button");let currenttime,timestart,timeend,addstarttime,addendtime;function executefilter(starttime,endtime,addstarttime,addendtime,buttonstate){document.querySelectorAll(".townsquare_letter.ts_coursefilter_approved.ts_letterfilter_approved").forEach((function(letter){let lettertime=letter.querySelector(".townsquareletter_date").id;buttonstate&&lettertime>=starttime&&lettertime<=endtime||lettertime>=addstarttime&&lettertime<=addendtime?letter.classList.add("ts_timefilter_approved"):letter.classList.remove("ts_timefilter_approved")}))}function convertidtotime(id){switch(id){case"ts_time_all":return 15778463;case"ts_time_next_twodays":case"ts_time_last_twodays":return 172800;case"ts_time_next_fivedays":case"ts_time_last_fivedays":return 432e3;case"ts_time_next_week":case"ts_time_last_week":return 604800;case"ts_time_next_month":case"ts_time_last_month":return 2592e3}}})); //# sourceMappingURL=timefilter.min.js.map \ No newline at end of file diff --git a/amd/build/timefilter.min.js.map b/amd/build/timefilter.min.js.map index 1763f9d..b958f63 100644 --- a/amd/build/timefilter.min.js.map +++ b/amd/build/timefilter.min.js.map @@ -1 +1 @@ -{"version":3,"file":"timefilter.min.js","sources":["../src/timefilter.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 .\n\n/**\n * Javascript for the time filter\n *\n * This file implements 1 functionality:\n * - Checks, which of the radio buttons is pressed and filters the content based on the time.\n *\n * @module block_townsquare/timefilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant radio buttons.\nconst alltimebutton = document.querySelectorAll('.ts_all_time_button');\nconst futureradiobuttons = document.querySelectorAll('.ts_future_time_button');\nconst pastradiobuttons = document.querySelectorAll('.ts_past_time_button');\n\n// Define to change the time span, an additional time span and the current time.\nlet currenttime;\nlet timestart;\nlet timeend;\nlet addstarttime;\nlet addendtime;\n\n/**\n * Init function\n */\nexport function init() {\n // Set the current time.\n currenttime = new Date().getTime() / 1000;\n\n // Add event listeners to the all kind of buttons.\n alltimeaddEventListener();\n futuretimeaddEventListener();\n pasttimeaddEventListener();\n}\n\n/**\n * Function to execute the filter\n * @param {int} starttime Start of time span for filtering of the current pressed button\n * @param {int} endtime End of time span for filtering of the current pressed\n * @param {int} addstarttime Start of time span for filtering of an additional radio button.\n * @param {int} addendtime End of time span for filtering of an additional radio button.\n * @param {boolean} buttonstate State of the radio button (true or false)\n */\nfunction executefilter(starttime, endtime, addstarttime, addendtime, buttonstate) {\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.ts_coursefilter_active.ts_letterfilter_active');\n\n // Loop through each letter and hide/show based on radiobutton state.\n letters.forEach(function(letter) {\n\n // Get the created time stamp of each letter.\n let lettertime = letter.querySelector('.townsquareletter_date').id;\n\n // If the radio button is checked and the letter is in the time span, activate it.\n if ((buttonstate && (lettertime >= starttime && lettertime <= endtime)) ||\n (lettertime >= addstarttime && lettertime <= addendtime)) {\n letter.classList.add('ts_timefilter_active'); // Mark the letter as \"active\".\n } else {\n letter.classList.remove('ts_timefilter_active'); // Mark the letter as \"not active\".\n }\n });\n}\n\n/**\n * Function to add event listeners to the all_time button.\n */\nfunction alltimeaddEventListener() {\n alltimebutton.forEach(function(button) {\n button.addEventListener('change', function() {\n // Set the time span to show all letters.\n timestart = currenttime - convertidtotime(button.id);\n timeend = currenttime + convertidtotime(button.id);\n addstarttime = 0;\n addendtime = 0;\n\n // Disable all other radio buttons that filter more specific times.\n futureradiobuttons.forEach(function(futureradiobutton) {\n futureradiobutton.checked = false;\n futureradiobutton.parentNode.classList.remove(\"active\");\n });\n pastradiobuttons.forEach(function(pastradiobutton) {\n pastradiobutton.checked = false;\n pastradiobutton.parentNode.classList.remove(\"active\");\n\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime,addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to add event listeners to the future time radio buttons.\n */\nfunction futuretimeaddEventListener() {\n futureradiobuttons.forEach(function(button) {\n button.addEventListener('change', function() {\n // Disable the all_time button.\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n\n // Set the time span based on the radiobutton id.\n timestart = currenttime;\n timeend = currenttime + convertidtotime(button.id);\n\n // Check if one past time button is checked. If yes, set the additional time span based on its id.\n addstarttime = 0;\n addendtime = 0;\n pastradiobuttons.forEach(function(pastradiobutton) {\n if (pastradiobutton.parentNode.classList.contains('active')) {\n addstarttime = currenttime - convertidtotime(pastradiobutton.id);\n addendtime = currenttime;\n }\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime, addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to add event listeners to the past time radio buttons.\n */\nfunction pasttimeaddEventListener() {\n pastradiobuttons.forEach(function(button) {\n button.addEventListener('change', function() {\n // Disable the all_time button.\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n\n // Set the time span based on the radiobutton id.\n timestart = currenttime - convertidtotime(button.id);\n timeend = currenttime;\n\n // Check if one future time button is checked. If yes, set the additional time span based on its id.\n addstarttime = 0;\n addendtime = 0;\n futureradiobuttons.forEach(function(futureradiobutton) {\n if (futureradiobutton.parentNode.classList.contains('active')) {\n addstarttime = currenttime;\n addendtime = currenttime + convertidtotime(futureradiobutton.id);\n }\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime, addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to convert the radio button id to a useable time span.\n * @param {string} id The id of the radio button\n * @returns {number}\n */\nfunction convertidtotime(id) {\n switch(id) {\n case \"ts_time_all\":\n return 15778463;\n case \"ts_time_next_twodays\":\n case \"ts_time_last_twodays\":\n return 172800;\n case \"ts_time_next_fivedays\":\n case \"ts_time_last_fivedays\":\n return 432000;\n case \"ts_time_next_week\":\n case \"ts_time_last_week\":\n return 604800;\n case \"ts_time_next_month\":\n case \"ts_time_last_month\":\n return 2592000;\n }\n}\n"],"names":["currenttime","Date","getTime","alltimebutton","forEach","button","addEventListener","timestart","convertidtotime","id","timeend","addstarttime","addendtime","futureradiobuttons","futureradiobutton","checked","parentNode","classList","remove","pastradiobuttons","pastradiobutton","executefilter","contains","document","querySelectorAll","starttime","endtime","buttonstate","letter","lettertime","querySelector","add"],"mappings":"2IAyCO,WAEHA,aAAc,IAAIC,MAAOC,UAAY,IAyCrCC,cAAcC,SAAQ,SAASC,QAC3BA,OAAOC,iBAAiB,UAAU,WAE9BC,UAAYP,YAAcQ,gBAAgBH,OAAOI,IACjDC,QAAUV,YAAcQ,gBAAgBH,OAAOI,IAC/CE,aAAe,EACfC,WAAa,EAGbC,mBAAmBT,SAAQ,SAASU,mBAChCA,kBAAkBC,SAAU,EAC5BD,kBAAkBE,WAAWC,UAAUC,OAAO,aAElDC,iBAAiBf,SAAQ,SAASgB,iBAC9BA,gBAAgBL,SAAU,EAC1BK,gBAAgBJ,WAAWC,UAAUC,OAAO,aAKhDG,cAAcd,UAAWG,QAASC,aAAaC,WAAYP,OAAOU,eAS1EF,mBAAmBT,SAAQ,SAASC,QAChCA,OAAOC,iBAAiB,UAAU,WAE9BH,cAAcC,SAAQ,SAASD,eAC3BA,cAAcY,SAAU,EACxBZ,cAAca,WAAWC,UAAUC,OAAO,aAI9CX,UAAYP,YACZU,QAAUV,YAAcQ,gBAAgBH,OAAOI,IAG/CE,aAAe,EACfC,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AElB"} \ No newline at end of file +{"version":3,"file":"timefilter.min.js","sources":["../src/timefilter.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 .\n\n/**\n * Javascript for the time filter\n *\n * This file implements 1 functionality:\n * - Checks, which of the radio buttons is pressed and filters the content based on the time.\n *\n * @module block_townsquare/timefilter\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n// Get the relevant radio buttons.\nconst alltimebutton = document.querySelectorAll('.ts_all_time_button');\nconst futureradiobuttons = document.querySelectorAll('.ts_future_time_button');\nconst pastradiobuttons = document.querySelectorAll('.ts_past_time_button');\n\n// Define to change the time span, an additional time span and the current time.\nlet currenttime;\nlet timestart;\nlet timeend;\nlet addstarttime;\nlet addendtime;\n\n/**\n * Init function\n */\nexport function init() {\n // Set the current time.\n currenttime = new Date().getTime() / 1000;\n\n // Add event listeners to the all kind of buttons.\n alltimeaddEventListener();\n futuretimeaddEventListener();\n pasttimeaddEventListener();\n}\n\n/**\n * Function to execute the filter\n * @param {int} starttime Start of time span for filtering of the current pressed button\n * @param {int} endtime End of time span for filtering of the current pressed\n * @param {int} addstarttime Start of time span for filtering of an additional radio button.\n * @param {int} addendtime End of time span for filtering of an additional radio button.\n * @param {boolean} buttonstate State of the radio button (true or false)\n */\nfunction executefilter(starttime, endtime, addstarttime, addendtime, buttonstate) {\n // Get all letters that are \"activated\".\n // Activated means that all filters accept the letter and want to show it.\n const letters = document.querySelectorAll('.townsquare_letter.ts_coursefilter_approved.ts_letterfilter_approved');\n\n // Loop through each letter and hide/show based on radiobutton state.\n letters.forEach(function(letter) {\n\n // Get the created time stamp of each letter.\n let lettertime = letter.querySelector('.townsquareletter_date').id;\n\n // If the radio button is checked and the letter is in the time span, activate it.\n if ((buttonstate && (lettertime >= starttime && lettertime <= endtime)) ||\n (lettertime >= addstarttime && lettertime <= addendtime)) {\n letter.classList.add('ts_timefilter_approved'); // Mark the letter as \"approved\".\n } else {\n letter.classList.remove('ts_timefilter_approved'); // Mark the letter as \"not approved\".\n }\n });\n}\n\n/**\n * Function to add event listeners to the all_time button.\n */\nfunction alltimeaddEventListener() {\n alltimebutton.forEach(function(button) {\n button.addEventListener('change', function() {\n // Set the time span to show all letters.\n timestart = currenttime - convertidtotime(button.id);\n timeend = currenttime + convertidtotime(button.id);\n addstarttime = 0;\n addendtime = 0;\n\n // Disable all other radio buttons that filter more specific times.\n futureradiobuttons.forEach(function(futureradiobutton) {\n futureradiobutton.checked = false;\n futureradiobutton.parentNode.classList.remove(\"active\");\n });\n pastradiobuttons.forEach(function(pastradiobutton) {\n pastradiobutton.checked = false;\n pastradiobutton.parentNode.classList.remove(\"active\");\n\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime,addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to add event listeners to the future time radio buttons.\n */\nfunction futuretimeaddEventListener() {\n futureradiobuttons.forEach(function(button) {\n button.addEventListener('change', function() {\n // Disable the all_time button.\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n\n // Set the time span based on the radiobutton id.\n timestart = currenttime;\n timeend = currenttime + convertidtotime(button.id);\n\n // Check if one past time button is checked. If yes, set the additional time span based on its id.\n addstarttime = 0;\n addendtime = 0;\n pastradiobuttons.forEach(function(pastradiobutton) {\n if (pastradiobutton.parentNode.classList.contains('active')) {\n addstarttime = currenttime - convertidtotime(pastradiobutton.id);\n addendtime = currenttime;\n }\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime, addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to add event listeners to the past time radio buttons.\n */\nfunction pasttimeaddEventListener() {\n pastradiobuttons.forEach(function(button) {\n button.addEventListener('change', function() {\n // Disable the all_time button.\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n\n // Set the time span based on the radiobutton id.\n timestart = currenttime - convertidtotime(button.id);\n timeend = currenttime;\n\n // Check if one future time button is checked. If yes, set the additional time span based on its id.\n addstarttime = 0;\n addendtime = 0;\n futureradiobuttons.forEach(function(futureradiobutton) {\n if (futureradiobutton.parentNode.classList.contains('active')) {\n addstarttime = currenttime;\n addendtime = currenttime + convertidtotime(futureradiobutton.id);\n }\n });\n\n // Execute the filter function.\n executefilter(timestart, timeend, addstarttime, addendtime, button.checked);\n });\n });\n}\n\n/**\n * Function to convert the radio button id to a useable time span.\n * @param {string} id The id of the radio button\n * @returns {number}\n */\nfunction convertidtotime(id) {\n switch(id) {\n case \"ts_time_all\":\n return 15778463;\n case \"ts_time_next_twodays\":\n case \"ts_time_last_twodays\":\n return 172800;\n case \"ts_time_next_fivedays\":\n case \"ts_time_last_fivedays\":\n return 432000;\n case \"ts_time_next_week\":\n case \"ts_time_last_week\":\n return 604800;\n case \"ts_time_next_month\":\n case \"ts_time_last_month\":\n return 2592000;\n }\n}\n"],"names":["currenttime","Date","getTime","alltimebutton","forEach","button","addEventListener","timestart","convertidtotime","id","timeend","addstarttime","addendtime","futureradiobuttons","futureradiobutton","checked","parentNode","classList","remove","pastradiobuttons","pastradiobutton","executefilter","contains","document","querySelectorAll","starttime","endtime","buttonstate","letter","lettertime","querySelector","add"],"mappings":"2IAyCO,WAEHA,aAAc,IAAIC,MAAOC,UAAY,IAyCrCC,cAAcC,SAAQ,SAASC,QAC3BA,OAAOC,iBAAiB,UAAU,WAE9BC,UAAYP,YAAcQ,gBAAgBH,OAAOI,IACjDC,QAAUV,YAAcQ,gBAAgBH,OA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,QACAC,aACAC,WAuBJ,SAASS,cAAcI,UAAWC,QAASf,aAAcC,WAAYe,aAGjDJ,SAASC,iBAAiB,wEAGlCpB,SAAQ,SAASwB,QAGrB,IAAIC,WAAaD,OAAOE,cAAc,0BAA0BrB,GAG3DkB,aAAgBE,YAAcJ,WAAaI,YAAcH,SACzDG,YAAclB,cAAgBkB,YAAcjB,WAC7CgB,OAAOX,UAAUc,IAAI,0BAErBH,OAAOX,UAAUC,OAAO,6BAuGpC,SAASV,gBAAgBC,IACrB,OAAOA,IACH,IAAK,cACD,OAAO,SACX,IAAK,uBACL,IAAK,uBACD,OAAO,OACX,IAAK,wBACL,IAAK,wBACD,OAAO,MACX,IAAK,oBACL,IAAK,oBACD,OAAO,OACX,IAAK,qBACL,IAAK,qBACD,OAAO,QAElB"} \ No newline at end of file diff --git a/amd/build/usersettings_save.min.js.map b/amd/build/usersettings_save.min.js.map index 8cc2c92..13932df 100644 --- a/amd/build/usersettings_save.min.js.map +++ b/amd/build/usersettings_save.min.js.map @@ -1 +1 @@ -{"version":3,"file":"usersettings_save.min.js","sources":["../src/usersettings_save.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 .\n\n/**\n * Javascript to save the user settings in the database.\n *\n * This file implements 1 functionality:\n * - If the \"save settings\" button is pressed, store the settings in the database.\n *\n * @module block_townsquare/usersettings_save\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n// Get the save button for the user settings.\nconst savebutton = document.getElementById('ts_usersettings_savebutton');\n\n// Get the buttons from the time filter.\nconst alltimebutton = document.querySelectorAll('.ts_all_time_button');\nconst futureradiobuttons = document.querySelectorAll('.ts_future_time_button');\nconst pastradiobuttons = document.querySelectorAll('.ts_past_time_button');\n\n// Get the checkboxes from the letter filter.\nconst checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n/**\n * Init function\n *\n * @param {number} userid The id of the current user.\n * @param {object} settingsfromdb The settings from the database, if there are any.\n */\nexport function init(userid, settingsfromdb) {\n // When the page is loaded, set the settings from the database.\n if (settingsfromdb) {\n executeusersettings(settingsfromdb);\n }\n\n // Add event listener to the save button.\n savebutton.addEventListener('click', async function() {\n\n // First step: collect the current settings.\n // Get the relevant time spans of the time filter and the setting of the letter filter checkboxes.\n let timespans = collecttimefiltersettings();\n let letterfilter = collectletterfiltersettings();\n\n // Second step: store the usersettings in the database.\n await saveusersettings(userid, timespans['timepast'], timespans['timefuture'], letterfilter['basicletter'],\n letterfilter['completionletter'], letterfilter['postletter']);\n });\n}\n\n/**\n * Function to save the user settings in the database.\n * @param {number} userid\n * @param {number} timefilterpast\n * @param {number} timefilterfuture\n * @param {number} basicletter\n * @param {number} completionletter\n * @param {number} postletter\n * @returns {Promise<*>}\n */\nfunction saveusersettings(userid, timefilterpast, timefilterfuture, basicletter, completionletter, postletter) {\n let result;\n\n const data = {\n methodname: 'block_townsquare_record_usersettings',\n args: {\n userid: userid,\n timefilterpast: timefilterpast,\n timefilterfuture: timefilterfuture,\n basicletter: basicletter,\n completionletter: completionletter,\n postletter: postletter,\n },\n };\n result = Ajax.call([data]);\n\n // Make the clicked button green by adding a class.\n savebutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n\n // Remove the classes after one second.\n setTimeout(function() {\n savebutton.classList.remove('bg-success');\n savebutton.classList.remove('text-white');\n }, 1500);\n return result;\n\n}\n\n/**\n * Function to execute existing user settings when loading the townsquare.\n * @param {Object} settingsfromdb\n */\nfunction executeusersettings(settingsfromdb) {\n\n // First step: set the time filter settings.\n // Change the time into the correct radio button id.\n let futurebuttonid = converttimetoid(settingsfromdb['timefilterfuture'], true);\n let pastbuttonid = converttimetoid(settingsfromdb['timefilterpast'], false);\n\n // If the time span is a combination of past and future, go through the two radio buttons and activate the filter.\n if (futurebuttonid !== \"ts_time_all\") {\n futureradiobuttons.forEach(function(button) {\n if (button.id === futurebuttonid) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n }\n });\n pastradiobuttons.forEach(function(button) {\n if (button.id === pastbuttonid) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n }\n });\n } else {\n // If the time span is set to all time, activate the all time button.\n alltimebutton.forEach(function(button) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n });\n }\n\n // Second step: set the letter filter settings.\n // Per default all checkboxes are checked. If the setting is 0, uncheck the checkbox.\n checkboxes.forEach(function(checkbox) {\n let basiclettercheck = checkbox.id === 'basicletter' && settingsfromdb['basicletter'] === \"\";\n let completionlettercheck = checkbox.id === 'completionletter' && settingsfromdb['completionletter'] === \"0\";\n let postlettercheck = checkbox.id === 'postletter' && settingsfromdb['postletter'] === \"0\";\n\n if (basiclettercheck || completionlettercheck || postlettercheck) {\n checkbox.click();\n }\n });\n}\n\n/**\n * Function to collect the letter filter settings.\n * @returns {{basicletter: number, completionletter: number, postletter: number}}\n */\nfunction collectletterfiltersettings() {\n let settings = {'basicletter': 0, 'completionletter': 0, 'postletter': 0 };\n\n checkboxes.forEach(function(checkbox) {\n if (checkbox.checked) {\n switch(checkbox.id) {\n case \"basicletter\":\n settings['basicletter'] = 1;\n break;\n case \"completionletter\":\n settings['completionletter'] = 1;\n break;\n case \"postletter\":\n settings['postletter'] = 1;\n break;\n\n }\n }\n });\n // Calculate the setting number. It is a number between 0 and 7, and each letter represents a bit.\n return settings;\n}\n\n/**\n * Function to collect the time filter settings.\n * @returns {{timepast: number, timefuture: number}}\n */\nfunction collecttimefiltersettings() {\n let settings = { timepast: 0, timefuture: 0};\n let settingsset = false;\n\n // Get the relevant time spans of the time filter.\n // Check if the alltimebutton is set.\n alltimebutton.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timepast'] = convertidtotime(button.id);\n settings['timefuture'] = convertidtotime(button.id);\n settingsset = true;\n }\n });\n\n if (settingsset) {\n return settings;\n }\n\n // If the alltimebutton is not set, check which of the future/past buttons is set.\n futureradiobuttons.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timefuture'] = convertidtotime(button.id);\n }\n });\n\n pastradiobuttons.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timepast'] = convertidtotime(button.id);\n }\n });\n return settings;\n}\n\n\n/**\n * Function to convert the radio button id to a useable time span.\n * @param {string} id The id of the radio button\n * @returns {number}\n */\nfunction convertidtotime(id) {\n // TODO: Please use global functions if possible.\n switch(id) {\n case \"ts_time_all\":\n return 15778463;\n case \"ts_time_next_twodays\":\n case \"ts_time_last_twodays\":\n return 172800;\n case \"ts_time_next_fivedays\":\n case \"ts_time_last_fivedays\":\n return 432000;\n case \"ts_time_next_week\":\n case \"ts_time_last_week\":\n return 604800;\n case \"ts_time_next_month\":\n case \"ts_time_last_month\":\n return 2592000;\n }\n}\n\n/**\n * Function to convert the time span to a radio button id.\n * @param {string} time\n * @param {boolean} future\n * @returns {string}\n */\nfunction converttimetoid(time, future) {\n switch (time) {\n case \"15778463\":\n return \"ts_time_all\";\n case \"172800\":\n if (future) {\n return \"ts_time_next_twodays\";\n }\n return \"ts_time_past_twodays\";\n case \"432000\":\n if (future) {\n return \"ts_time_next_fivedays\";\n }\n return \"ts_time_last_fivedays\";\n case \"604800\":\n if (future) {\n return \"ts_time_next_week\";\n }\n return \"ts_time_last_week\";\n case \"2592000\":\n if (future) {\n return \"ts_time_next_month\";\n\n }\n return \"ts_time_last_month\";\n }\n}\n"],"names":["obj","userid","settingsfromdb","futurebuttonid","converttimetoid","pastbuttonid","futureradiobuttons","forEach","button","id","parentNode","classList","add","checked","dispatchEvent","Event","alltimebutton","remove","pastradiobuttons","checkboxes","checkbox","basiclettercheck","completionlettercheck","postlettercheck","click","executeusersettings","savebutton","addEventListener","async","timespans","settings","timepast","timefuture","settingsset","contains","convertidtotime","collecttimefiltersettings","letterfilter","basicletter","completionletter","postletter","collectletterfiltersettings","timefilterpast","timefilterfuture","result","data","methodname","args","Ajax","call","setTimeout","saveusersettings","_ajax","__esModule","default","document","getElementById","querySelectorAll","time","future"],"mappings":"8FA0B6B,IAAAA;;;;;;;;;;2EAmBtB,SAAcC,OAAQC,gBAErBA,gBA4DR,SAA6BA,gBAIzB,IAAIC,eAAiBC,gBAAgBF,eAAiC,kBAAG,GACrEG,aAAeD,gBAAgBF,eAA+B,gBAAG,GAG9C,gBAAnBC,gBACAG,mBAAmBC,SAAQ,SAASC,QAC5BA,OAAOC,KAAON,iBACdK,OAAOE,WAAWC,UAAUC,IAAI,UAChCJ,OAAOK,SAAU,EACjBL,OAAOM,cAAc,IAAIC,MAAM,WAC/BC,cAAcT,SAAQ,SAASS,eAC3BA,cAAcH,SAAU,EACxBG,cAAcN,WAAWC,UAAUM,OAAO,iBAItDC,iBAAiBX,SAAQ,SAASC,QAC1BA,OAAOC,KAAOJ,eACdG,OAAOE,WAAWC,UAAUC,IAAI,UAChCJ,OAAOK,SAAU,EACjBL,OAAOM,cAAc,IAAIC,MAAM,WAC/BC,cAAcT,SAAQ,SAASS,eAC3BA,cAAcH,SAAU,EACxBG,cAAcN,WAAWC,UAAUM,OAAO,kBAMtDD,cAAcT,SAAQ,SAASC,QAC3BA,OAAOE,WAAWC,UAAUC,IAAI,UAChCJ,OA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ACTC,WAAY,uCACZC,KAAM,CACF9C,OAAQA,OACRyC,eAAgBA,eAChBC,iBAAkBA,iBAClBL,YAAaA,YACbC,iBAAkBA,iBAClBC,WAAYA,aAapB,OAVAI,OAASI,cAAKC,KAAK,CAACJ,OAGpBnB,WAAWf,UAAUC,IAAI,aAAc,aAAc,wBAGrDsC,YAAW,WACPxB,WAAWf,UAAUM,OAAO,cAC5BS,WAAWf,UAAUM,OAAO,gBAC7B,MACI2B,OAvCGO,CAAiBlD,OAAQ4B,UAAoB,SAAGA,UAAsB,WAAGQ,aAA0B,YACrGA,aAA+B,iBAAGA,aAAyB,gBAnCvEe,OAA6BpD,IAA7BoD,QAA6BpD,IAAAqD,WAAArD,KAAAsD,QAAAtD,KAG7B,MAAM0B,WAAa6B,SAASC,eAAe,8BAGrCxC,cAAgBuC,SAASE,iBAAiB,uBAC1CnD,mBAAqBiD,SAASE,iBAAiB,0BAC/CvC,iBAAmBqC,SAASE,iBAAiB,wBAG7CtC,WAAaoC,SAASE,iBAAiB,uBAoM7C,SAAStB,gBAAgB1B,IAErB,OAAOA,IACH,IAAK,cACD,OAAO,SACX,IAAK,uBACL,IAAK,uBACD,OAAO,OACX,IAAK,wBACL,IAAK,wBACD,OAAO,MACX,IAAK,oBACL,IAAK,oBACD,OAAO,OACX,IAAK,qBACL,IAAK,qBACD,OAAO,QAUnB,SAASL,gBAAgBsD,KAAMC,QAC3B,OAAQD,MACJ,IAAK,WACD,MAAO,cACX,IAAK,SACD,OAAIC,OACO,uBAEJ,uBACX,IAAK,SACD,OAAIA,OACO,wBAEJ,wBACX,IAAK,SACD,OAAIA,OACO,oBAEJ,oBACX,IAAK,UACD,OAAIA,OACO,qBAGJ,sBAElB"} \ No newline at end of file +{"version":3,"file":"usersettings_save.min.js","sources":["../src/usersettings_save.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 .\n\n/**\n * Javascript to save the user settings in the database.\n *\n * This file implements 1 functionality:\n * - If the \"save settings\" button is pressed, store the settings in the database.\n *\n * @module block_townsquare/usersettings_save\n * @copyright 2024 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n// Get the save button for the user settings.\nconst savebutton = document.getElementById('ts_usersettings_savebutton');\n\n// Get the buttons from the time filter.\nconst alltimebutton = document.querySelectorAll('.ts_all_time_button');\nconst futureradiobuttons = document.querySelectorAll('.ts_future_time_button');\nconst pastradiobuttons = document.querySelectorAll('.ts_past_time_button');\n\n// Get the checkboxes from the letter filter.\nconst checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n/**\n * Init function\n *\n * @param {number} userid The id of the current user.\n * @param {object} settingsfromdb The settings from the database, if there are any.\n */\nexport function init(userid, settingsfromdb) {\n // When the page is loaded, set the settings from the database.\n if (settingsfromdb) {\n executeusersettings(settingsfromdb);\n }\n\n // Add event listener to the save button.\n savebutton.addEventListener('click', async function() {\n\n // First step: collect the current settings.\n // Get the relevant time spans of the time filter and the setting of the letter filter checkboxes.\n let timespans = collecttimefiltersettings();\n let letterfilter = collectletterfiltersettings();\n\n // Second step: store the usersettings in the database.\n await saveusersettings(userid, timespans['timepast'], timespans['timefuture'], letterfilter['basicletter'],\n letterfilter['completionletter'], letterfilter['postletter']);\n });\n}\n\n/**\n * Function to save the user settings in the database.\n * @param {number} userid\n * @param {number} timefilterpast\n * @param {number} timefilterfuture\n * @param {number} basicletter\n * @param {number} completionletter\n * @param {number} postletter\n * @returns {Promise<*>}\n */\nfunction saveusersettings(userid, timefilterpast, timefilterfuture, basicletter, completionletter, postletter) {\n let result;\n\n const data = {\n methodname: 'block_townsquare_record_usersettings',\n args: {\n userid: userid,\n timefilterpast: timefilterpast,\n timefilterfuture: timefilterfuture,\n basicletter: basicletter,\n completionletter: completionletter,\n postletter: postletter,\n },\n };\n result = Ajax.call([data]);\n // Make the clicked button green by adding a class.\n savebutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n\n // Remove the classes after one second.\n setTimeout(function() {\n savebutton.classList.remove('bg-success');\n savebutton.classList.remove('text-white');\n }, 1500);\n return result;\n\n}\n\n/**\n * Function to execute existing user settings when loading the townsquare.\n * @param {Object} settingsfromdb\n */\nfunction executeusersettings(settingsfromdb) {\n\n // First step: set the time filter settings.\n // Change the time into the correct radio button id.\n let futurebuttonid = converttimetoid(settingsfromdb['timefilterfuture'], true);\n let pastbuttonid = converttimetoid(settingsfromdb['timefilterpast'], false);\n\n // If the time span is a combination of past and future, go through the two radio buttons and activate the filter.\n if (futurebuttonid !== \"ts_time_all\") {\n futureradiobuttons.forEach(function(button) {\n if (button.id === futurebuttonid) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n }\n });\n pastradiobuttons.forEach(function(button) {\n if (button.id === pastbuttonid) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n alltimebutton.parentNode.classList.remove('active');\n });\n }\n });\n } else {\n // If the time span is set to all time, activate the all time button.\n alltimebutton.forEach(function(button) {\n button.parentNode.classList.add('active');\n button.checked = true;\n button.dispatchEvent(new Event('change'));\n });\n }\n\n // Second step: set the letter filter settings.\n // Per default all checkboxes are checked. If the setting is 0, uncheck the checkbox.\n checkboxes.forEach(function(checkbox) {\n let basiclettercheck = checkbox.id === 'basicletter' && settingsfromdb['basicletter'] === \"\";\n let completionlettercheck = checkbox.id === 'completionletter' && settingsfromdb['completionletter'] === \"0\";\n let postlettercheck = checkbox.id === 'postletter' && settingsfromdb['postletter'] === \"0\";\n\n if (basiclettercheck || completionlettercheck || postlettercheck) {\n checkbox.click();\n }\n });\n}\n\n/**\n * Function to collect the letter filter settings.\n * @returns {{basicletter: number, completionletter: number, postletter: number}}\n */\nfunction collectletterfiltersettings() {\n let settings = {'basicletter': 0, 'completionletter': 0, 'postletter': 0 };\n\n checkboxes.forEach(function(checkbox) {\n if (checkbox.checked) {\n switch(checkbox.id) {\n case \"basicletter\":\n settings['basicletter'] = 1;\n break;\n case \"completionletter\":\n settings['completionletter'] = 1;\n break;\n case \"postletter\":\n settings['postletter'] = 1;\n break;\n\n }\n }\n });\n // Calculate the setting number. It is a number between 0 and 7, and each letter represents a bit.\n return settings;\n}\n\n/**\n * Function to collect the time filter settings.\n * @returns {{timepast: number, timefuture: number}}\n */\nfunction collecttimefiltersettings() {\n let settings = { timepast: 0, timefuture: 0};\n let settingsset = false;\n\n // Get the relevant time spans of the time filter.\n // Check if the alltimebutton is set.\n alltimebutton.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timepast'] = convertidtotime(button.id);\n settings['timefuture'] = convertidtotime(button.id);\n settingsset = true;\n }\n });\n\n if (settingsset) {\n return settings;\n }\n\n // If the alltimebutton is not set, check which of the future/past buttons is set.\n futureradiobuttons.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timefuture'] = convertidtotime(button.id);\n }\n });\n\n pastradiobuttons.forEach(function(button) {\n if (button.parentNode.classList.contains('active')) {\n // Get the timespan.\n settings['timepast'] = convertidtotime(button.id);\n }\n });\n return settings;\n}\n\n\n/**\n * Function to convert the radio button id to a useable time span.\n * @param {string} id The id of the radio button\n * @returns {number}\n */\nfunction convertidtotime(id) {\n // TODO: Please use global functions if possible.\n switch(id) {\n case \"ts_time_all\":\n return 15778463;\n case \"ts_time_next_twodays\":\n case \"ts_time_last_twodays\":\n return 172800;\n case \"ts_time_next_fivedays\":\n case \"ts_time_last_fivedays\":\n return 432000;\n case \"ts_time_next_week\":\n case \"ts_time_last_week\":\n return 604800;\n case \"ts_time_next_month\":\n case \"ts_time_last_month\":\n return 2592000;\n }\n}\n\n/**\n * Function to convert the time span to a radio button id.\n * @param {string} time\n * @param {boolean} future\n * @returns {string}\n */\nfunction converttimetoid(time, future) {\n switch (time) {\n case \"15778463\":\n return \"ts_time_all\";\n case \"172800\":\n if (future) {\n return \"ts_time_next_twodays\";\n }\n return \"ts_time_past_twodays\";\n case \"432000\":\n if (future) {\n return \"ts_time_next_fivedays\";\n }\n return \"ts_time_last_fivedays\";\n case \"604800\":\n if (future) {\n return \"ts_time_next_week\";\n }\n return \"ts_time_last_week\";\n case \"2592000\":\n if (future) {\n return \"ts_time_next_month\";\n\n }\n return \"ts_time_last_month\";\n }\n}\n"],"names":["obj","userid","settingsfromdb","futurebuttonid","converttimetoid","pastbuttonid","futureradiobuttons","forEach","button","id","parentNode","classList","add","checked","dispatchEvent","Event","alltimebutton","remove","pastradiobuttons","checkboxes","checkbox","basiclettercheck","completionlettercheck","postlettercheck","click","executeusersettings","savebutton","addEventListener","async","timespans","settings","timepast","timefuture","settingsset","contains","convertidtotime","collecttimefiltersettings","letterfilter","basicletter","completionletter","postletter","collectletterfiltersettings","timefilterpast","timefilterfuture","result","data","methodname","args","Ajax","call","setTimeout","saveusersettings","_ajax","__esModule","default","document","getElementById","querySelectorAll","time","future"],"mappings":"8FA0B6B,IAAAA;;;;;;;;;;2EAmBtB,SAAcC,OAAQC,gBAErBA,gBA2DR,SAA6BA,gBAIzB,IAAIC,eAAiBC,gBAAgBF,eAAiC,kBAAG,GACrEG,aAAeD,gBAAgBF,eAA+B,gBAAG,GAG9C,gBAAnBC,gBACAG,mBAAmBC,SAAQ,SAASC,QAC5BA,OAAOC,KAAON,iBACdK,OAAOE,WAAWC,UAAUC,IAAI,UAChCJ,OAAOK,SAAU,E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AK,qBACL,IAAK,qBACD,OAAO,QAUnB,SAASL,gBAAgBsD,KAAMC,QAC3B,OAAQD,MACJ,IAAK,WACD,MAAO,cACX,IAAK,SACD,OAAIC,OACO,uBAEJ,uBACX,IAAK,SACD,OAAIA,OACO,wBAEJ,wBACX,IAAK,SACD,OAAIA,OACO,oBAEJ,oBACX,IAAK,UACD,OAAIA,OACO,qBAGJ,sBAElB"} \ No newline at end of file diff --git a/amd/src/coursefilter.js b/amd/src/coursefilter.js index 2162ebe..bc4b046 100644 --- a/amd/src/coursefilter.js +++ b/amd/src/coursefilter.js @@ -36,19 +36,18 @@ export function init() { // Get the courseid associated with the checkbox. const courseid = checkbox.id; - // Get all letters that are "activated". - // Activated means that all filters accept the letter and want to show it. - const letters = document.querySelectorAll('.townsquare_letter.ts_timefilter_active.ts_letterfilter_active'); + // Get all letters. + const letters = document.querySelectorAll('.townsquare_letter'); - // Loop through each letter mark it as "active" or not based on checkbox state and the letter id. + // Loop through each letter and mark it as "approved" or not based on checkbox state and the letter id. letters.forEach(function(letter) { let letterCourseId = letter.querySelector('.townsquareletter_course').id; if (courseid === letterCourseId) { if (checkbox.checked) { - letter.classList.add('ts_coursefilter_active'); // Mark the letter as "active". + letter.classList.add('ts_coursefilter_approved'); // Mark the letter as "approved". } else { - letter.classList.remove('ts_coursefilter_active'); // Mark the letter as "not active". + letter.classList.remove('ts_coursefilter_approved'); // Mark the letter as "not approved". } } }); diff --git a/amd/src/filtercontroller.js b/amd/src/filtercontroller.js index 11ccf50..c11cb9f 100644 --- a/amd/src/filtercontroller.js +++ b/amd/src/filtercontroller.js @@ -33,9 +33,9 @@ const letters = document.querySelectorAll('.townsquare_letter'); export function init() { // First step: activate every letter by adding the filter classes. letters.forEach(function(letter) { - letter.classList.add('ts_coursefilter_active'); - letter.classList.add('ts_timefilter_active'); - letter.classList.add('ts_letterfilter_active'); + letter.classList.add('ts_coursefilter_approved'); + letter.classList.add('ts_timefilter_approved'); + letter.classList.add('ts_letterfilter_approved'); }); // Add a mutation listener to each letter. @@ -44,11 +44,11 @@ export function init() { mutations.forEach(function(mutation) { if (mutation.attributeName === 'class') { // If the class of the letter changes, check if the letter should be shown or hidden. - let coursefilter = letter.classList.contains('ts_coursefilter_active'); - let timefilter = letter.classList.contains('ts_timefilter_active'); - let letterfilter = letter.classList.contains('ts_letterfilter_active'); + let coursefilter = letter.classList.contains('ts_coursefilter_approved'); + let timefilter = letter.classList.contains('ts_timefilter_approved'); + let letterfilter = letter.classList.contains('ts_letterfilter_approved'); - // If all filters are active, show the letter. + // If all filters approve the letter, show the letter. if (coursefilter && timefilter && letterfilter) { letter.style.display = 'block'; } else { diff --git a/amd/src/letterfilter.js b/amd/src/letterfilter.js index 77c544c..bc617d1 100644 --- a/amd/src/letterfilter.js +++ b/amd/src/letterfilter.js @@ -36,17 +36,15 @@ export function init() { // Get the letter name associated with the checkbox. const lettername = checkbox.id; - // Get all letters that are "activated". - // Activated means that all filters accept the letter and want to show it. - const letters = document.querySelectorAll('.townsquare_letter.' + lettername + - '.ts_timefilter_active.ts_coursefilter_active'); + // Get all letters associate with the checkbox. + const letters = document.querySelectorAll('.townsquare_letter.' + lettername); // Loop through each letter and hide/show based on checkbox state. letters.forEach(function(letter) { if (checkbox.checked) { - letter.classList.add('ts_letterfilter_active'); // Mark the letter as "active". + letter.classList.add('ts_letterfilter_approved'); // Mark the letter as "approved". } else { - letter.classList.remove('ts_letterfilter_active'); // Mark the letter as "not active". + letter.classList.remove('ts_letterfilter_approved'); // Mark the letter as "not approved". } }); }); diff --git a/amd/src/postletter.js b/amd/src/postletter.js index 08e50f9..99abbe0 100644 --- a/amd/src/postletter.js +++ b/amd/src/postletter.js @@ -46,7 +46,7 @@ const Selectors = { export function init() { contentElements.forEach( (element) => { - // Replace all

within the text with simple line breaks.. + // Replace all

within the text with simple line breaks. replaceParagraghTags(element); // Check if the text is too long. diff --git a/amd/src/timefilter.js b/amd/src/timefilter.js index 3a2b3c5..7cbe4ee 100644 --- a/amd/src/timefilter.js +++ b/amd/src/timefilter.js @@ -58,9 +58,8 @@ export function init() { * @param {boolean} buttonstate State of the radio button (true or false) */ function executefilter(starttime, endtime, addstarttime, addendtime, buttonstate) { - // Get all letters that are "activated". - // Activated means that all filters accept the letter and want to show it. - const letters = document.querySelectorAll('.townsquare_letter.ts_coursefilter_active.ts_letterfilter_active'); + // Get all letters. + const letters = document.querySelectorAll('.townsquare_letter'); // Loop through each letter and hide/show based on radiobutton state. letters.forEach(function(letter) { @@ -71,9 +70,9 @@ function executefilter(starttime, endtime, addstarttime, addendtime, buttonstate // If the radio button is checked and the letter is in the time span, activate it. if ((buttonstate && (lettertime >= starttime && lettertime <= endtime)) || (lettertime >= addstarttime && lettertime <= addendtime)) { - letter.classList.add('ts_timefilter_active'); // Mark the letter as "active". + letter.classList.add('ts_timefilter_approved'); // Mark the letter as "approved". } else { - letter.classList.remove('ts_timefilter_active'); // Mark the letter as "not active". + letter.classList.remove('ts_timefilter_approved'); // Mark the letter as "not approved". } }); }