diff --git a/amd/build/coursefilter.min.js b/amd/build/coursefilter.min.js deleted file mode 100644 index 08b02a1..0000000 --- a/amd/build/coursefilter.min.js +++ /dev/null @@ -1,14 +0,0 @@ -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=Number(checkbox.dataset.courseid);document.querySelectorAll(".townsquare_letter").forEach(function(letter){let letterCourseId=Number(letter.querySelector(".townsquareletter_course").dataset.courseid);courseid===letterCourseId&&(checkbox.checked?letter.classList.add("ts_coursefilter_approved"):letter.classList.remove("ts_coursefilter_approved"))})})})}; -/** - * JavaScript for the course filter - * - * This file implements 1 functionality: - * - Checks the checkboxes of the course filter and hides content from courses if the checkbox is not checked. - * - * @module block_townsquare/coursefilter - * @copyright 2024 Tamaro Walter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -const checkboxes=document.querySelectorAll(".ts_course_checkbox")}); - -//# sourceMappingURL=coursefilter.min.js.map \ No newline at end of file diff --git a/amd/build/coursefilter.min.js.map b/amd/build/coursefilter.min.js.map deleted file mode 100644 index 2ebd983..0000000 --- a/amd/build/coursefilter.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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. Adds an event listener to the course filter checkboxes. This is part of the content filtering functionality.\n * Every checkbox represents one course that shows content in Town square.\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 = Number(checkbox.dataset.courseid);\n\n // Get all letters.\n const letters = document.querySelectorAll('.townsquare_letter');\n\n // Loop through each letter and mark it as \"approved\" or not based on checkbox state and the letter id.\n letters.forEach(function(letter) {\n let letterCourseId = Number(letter.querySelector('.townsquareletter_course').dataset.courseid);\n\n if (courseid === letterCourseId) {\n if (checkbox.checked) {\n letter.classList.add('ts_coursefilter_approved'); // Mark the letter as \"approved\".\n } else {\n letter.classList.remove('ts_coursefilter_approved'); // Mark the letter as \"not approved\".\n }\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","courseid","Number","dataset","document","querySelectorAll","letter","letterCourseId","querySelector","checked","classList","add","remove"],"mappings":"4IAiCO,WACHA,WAAWC,QAAQ,SAASC,UACxBA,SAASC,iBAAiB,SAAU,WAEhC,MAAMC,SAAWC,OAAOH,SAASI,QAAQF,UAGzBG,SAASC,iBAAiB,sBAGlCP,QAAQ,SAASQ,QACrB,IAAIC,eAAiBL,OAAOI,OAAOE,cAAc,4BAA4BL,QAAQF,UAEjFA,WAAaM,iBACTR,SAASU,QACTH,OAAOI,UAAUC,IAAI,4BAErBL,OAAOI,UAAUE,OAAO,4BAGpC,EACJ,EACJ,EACJ;;;;;;;;;;;AA7BA,MAAMf,WAAaO,SAASC,iBAAiB,sBA6B5C"} \ No newline at end of file diff --git a/amd/build/db/usersettings_reset.min.js b/amd/build/db/usersettings_reset.min.js new file mode 100644 index 0000000..4449d3a --- /dev/null +++ b/amd/build/db/usersettings_reset.min.js @@ -0,0 +1,13 @@ +define("block_townsquare/db/usersettings_reset",["exports","core/ajax"],(function(_exports,_ajax){var obj; +/** + * JavaScript to reset the user settings. + * + * This file implements 1 functionality: + * - If the "reset settings" button is pressed, reset all settings and delete the users database record. + * + * @module block_townsquare/db/usersettings_reset + * @copyright 2024 Tamaro Walter + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(userid){resetbutton.addEventListener("click",(async function(){const data={methodname:"block_townsquare_reset_usersettings",args:{userid:userid}};let result=_ajax.default.call([data]);resetbutton.classList.add("bg-success","text-white","ts_button_transition"),setTimeout((function(){resetbutton.classList.remove("bg-success"),resetbutton.classList.remove("text-white")}),1500);const coursecheckboxes=document.querySelectorAll(".ts_course_checkbox"),lettercheckboxes=document.querySelectorAll(".ts_letter_checkbox"),alltimebutton=document.querySelectorAll(".ts_all_time_button");return coursecheckboxes.forEach((function(checkbox){checkbox.checked||checkbox.click()})),alltimebutton.forEach((function(button){button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change"))})),lettercheckboxes.forEach((function(checkbox){checkbox.checked||checkbox.click()})),result}))},_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};const resetbutton=document.getElementById("ts_usersettings_resetbutton")})); + +//# sourceMappingURL=usersettings_reset.min.js.map \ No newline at end of file diff --git a/amd/build/db/usersettings_reset.min.js.map b/amd/build/db/usersettings_reset.min.js.map new file mode 100644 index 0000000..265728c --- /dev/null +++ b/amd/build/db/usersettings_reset.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"usersettings_reset.min.js","sources":["../../src/db/usersettings_reset.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 reset the user settings.\n *\n * This file implements 1 functionality:\n * - If the \"reset settings\" button is pressed, reset all settings and delete the users database record.\n *\n * @module block_townsquare/db/usersettings_reset\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 reset button for the user settings.\nconst resetbutton = document.getElementById('ts_usersettings_resetbutton');\n\n/**\n * Init function. This functions resets the user settings from the database.\n * @param {number} userid The id of the current user.\n */\nexport function init(userid) {\n // First step: delete user settings in database.\n\n // Add event listener to the reset button.\n resetbutton.addEventListener('click', async function() {\n // Set up for AJAX call.\n const data = {\n methodname: 'block_townsquare_reset_usersettings',\n args: {\n userid: userid,\n },\n };\n // Call the AJAX function.\n let result = Ajax.call([data]);\n\n // Make the clicked button green by adding a class and remove it afterward.\n resetbutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n setTimeout(function() {\n resetbutton.classList.remove('bg-success');\n resetbutton.classList.remove('text-white');\n }, 1500);\n\n // Second step: reset all active filters.\n const coursecheckboxes = document.querySelectorAll('.ts_course_checkbox');\n const lettercheckboxes = document.querySelectorAll('.ts_letter_checkbox');\n const alltimebutton = document.querySelectorAll('.ts_all_time_button');\n\n coursecheckboxes.forEach(function(checkbox) {\n if (!checkbox.checked) {\n checkbox.click();\n }\n });\n\n alltimebutton.forEach(function(button) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n });\n\n lettercheckboxes.forEach(function(checkbox) {\n if (!checkbox.checked) {\n checkbox.click();\n }\n });\n return result;\n });\n}\n"],"names":["userid","resetbutton","addEventListener","async","data","methodname","args","result","Ajax","call","classList","add","setTimeout","remove","coursecheckboxes","document","querySelectorAll","lettercheckboxes","alltimebutton","forEach","checkbox","checked","click","button","parentNode","dispatchEvent","Event","getElementById"],"mappings":";;;;;;;;;;oFAmCqBA,QAIjBC,YAAYC,iBAAiB,SAASC,uBAE5BC,KAAO,CACTC,WAAY,sCACZC,KAAM,CACFN,OAAQA,aAIZO,OAASC,cAAKC,KAAK,CAACL,OAGxBH,YAAYS,UAAUC,IAAI,aAAc,aAAc,wBACtDC,YAAW,WACPX,YAAYS,UAAUG,OAAO,cAC7BZ,YAAYS,UAAUG,OAAO,gBAC9B,YAGGC,iBAAmBC,SAASC,iBAAiB,uBAC7CC,iBAAmBF,SAASC,iBAAiB,uBAC7CE,cAAgBH,SAASC,iBAAiB,8BAEhDF,iBAAiBK,SAAQ,SAASC,UACzBA,SAASC,SACVD,SAASE,WAIjBJ,cAAcC,SAAQ,SAASI,QAC3BA,OAAOF,SAAU,EACjBE,OAAOC,WAAWd,UAAUC,IAAI,UAChCY,OAAOE,cAAc,IAAIC,MAAM,cAGnCT,iBAAiBE,SAAQ,SAASC,UACzBA,SAASC,SACVD,SAASE,WAGVf,qEAlDTN,YAAcc,SAASY,eAAe"} \ No newline at end of file diff --git a/amd/build/db/usersettings_save.min.js b/amd/build/db/usersettings_save.min.js new file mode 100644 index 0000000..fa6f833 --- /dev/null +++ b/amd/build/db/usersettings_save.min.js @@ -0,0 +1,13 @@ +define("block_townsquare/db/usersettings_save",["exports","core/ajax"],(function(_exports,_ajax){var obj; +/** + * JavaScript to save the user settings in the database. + * + * This file implements 1 functionality: + * - If the "save settings" button is pressed, store the settings in the database. + * + * @module block_townsquare/db/usersettings_save + * @copyright 2024 Tamaro Walter + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(userid,settingsfromdb){settingsfromdb&&function(settingsfromdb){let futurebuttonid=converttimetoid(settingsfromdb.timefilterfuture,!0),pastbuttonid=converttimetoid(settingsfromdb.timefilterpast,!1);"ts_time_all"!==futurebuttonid?(alltimebutton.forEach((function(alltimebutton){alltimebutton.checked=!1})),futureradiobuttons.forEach((function(button){button.id===futurebuttonid&&(button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change")))})),pastradiobuttons.forEach((function(button){button.id===pastbuttonid&&(button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change")))}))):(alltimebutton.forEach((function(button){button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change"))})),futureradiobuttons.forEach((function(button){button.checked=!1})),pastradiobuttons.forEach((function(button){button.checked=!1})));letter_checkboxes.forEach((function(checkbox){let basiclettercheck="basicletter"===checkbox.id&&"0"===settingsfromdb.basicletter,completionlettercheck="completionletter"===checkbox.id&&"0"===settingsfromdb.completionletter,postlettercheck="postletter"===checkbox.id&&"0"===settingsfromdb.postletter;(basiclettercheck||completionlettercheck||postlettercheck)&&checkbox.click()}));let coursessettings=JSON.parse(settingsfromdb.courses);course_checkboxes.forEach((function(checkbox){let courseid=Number(checkbox.dataset.courseid);coursessettings.hasOwnProperty(courseid)&&!coursessettings[courseid]&&checkbox.checked&&checkbox.click()}))}(settingsfromdb);savebutton.addEventListener("click",(async function(){let timespans=function(){let settings={timepast:0,timefuture:0},settingsset=!1;if(alltimebutton.forEach((function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timepast=convertidtotime(button.id),settings.timefuture=convertidtotime(button.id),settingsset=!0)})),settingsset)return settings;return futureradiobuttons.forEach((function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timefuture=convertidtotime(button.id))})),pastradiobuttons.forEach((function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timepast=convertidtotime(button.id))})),settings}(),letterfilter=function(){let settings={basicletter:0,completionletter:0,postletter:0};return letter_checkboxes.forEach((function(checkbox){if(checkbox.checked)switch(checkbox.id){case"basicletter":settings.basicletter=1;break;case"completionletter":settings.completionletter=1;break;case"postletter":settings.postletter=1}})),settings}(),courses=function(coursesettingsfromdb){let settings=coursesettingsfromdb?JSON.parse(coursesettingsfromdb):{};return course_checkboxes.forEach((function(checkbox){settings[Number(checkbox.dataset.courseid)]=checkbox.checked})),JSON.stringify(settings)}(settingsfromdb.courses);await function(userid,timefilterpast,timefilterfuture,basicletter,completionletter,postletter,courses){let result;const data={methodname:"block_townsquare_record_usersettings",args:{userid:userid,timefilterpast:timefilterpast,timefilterfuture:timefilterfuture,basicletter:basicletter,completionletter:completionletter,postletter:postletter,courses:courses}};return result=_ajax.default.call([data]),savebutton.classList.add("bg-success","text-white","ts_button_transition"),setTimeout((function(){savebutton.classList.remove("bg-success"),savebutton.classList.remove("text-white")}),1500),result}(userid,timespans.timepast,timespans.timefuture,letterfilter.basicletter,letterfilter.completionletter,letterfilter.postletter,courses)}))},_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};const savebutton=document.getElementById("ts_usersettings_savebutton"),alltimebutton=document.querySelectorAll(".ts_all_time_button"),futureradiobuttons=document.querySelectorAll(".ts_future_time_button"),pastradiobuttons=document.querySelectorAll(".ts_past_time_button"),letter_checkboxes=document.querySelectorAll(".ts_letter_checkbox"),course_checkboxes=document.querySelectorAll(".ts_course_checkbox");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}}function converttimetoid(time,future){switch(time){case"15778463":return"ts_time_all";case"172800":return future?"ts_time_next_twodays":"ts_time_past_twodays";case"432000":return future?"ts_time_next_fivedays":"ts_time_last_fivedays";case"604800":return future?"ts_time_next_week":"ts_time_last_week";case"2592000":return future?"ts_time_next_month":"ts_time_last_month"}}})); + +//# sourceMappingURL=usersettings_save.min.js.map \ No newline at end of file diff --git a/amd/build/db/usersettings_save.min.js.map b/amd/build/db/usersettings_save.min.js.map new file mode 100644 index 0000000..43aec04 --- /dev/null +++ b/amd/build/db/usersettings_save.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"usersettings_save.min.js","sources":["../../src/db/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/db/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 letter_checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n// Get the checkboxes from the course filter.\nconst course_checkboxes = document.querySelectorAll('.ts_course_checkbox');\n\n/**\n * Init function. This functions adapts the filter settings to the user settings from the database. If the user changes settings\n * and clicks the save button, the settings are stored in the database.\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 let courses = collectcoursesettings(settingsfromdb.courses);\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'], courses);\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 * @param {string} courses\n * @returns {Promise<*>}\n */\nfunction saveusersettings(userid, timefilterpast, timefilterfuture, basicletter, completionletter, postletter, courses) {\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 courses: courses,\n },\n };\n result = Ajax.call([data]);\n\n // Make the clicked button green by adding a class and remove it afterward.\n savebutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n setTimeout(function() {\n savebutton.classList.remove('bg-success');\n savebutton.classList.remove('text-white');\n }, 1500);\n\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 alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n });\n futureradiobuttons.forEach(function(button) {\n if (button.id === futurebuttonid) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n }\n });\n pastradiobuttons.forEach(function(button) {\n if (button.id === pastbuttonid) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\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.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n });\n futureradiobuttons.forEach(function(button) {\n button.checked = false;\n });\n pastradiobuttons.forEach(function(button) {\n button.checked = false;\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 letter_checkboxes.forEach(function(checkbox) {\n let basiclettercheck = checkbox.id === 'basicletter' && settingsfromdb.basicletter === \"0\";\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 // Third step: set the course filter settings.\n let coursessettings = JSON.parse(settingsfromdb.courses);\n\n course_checkboxes.forEach(function(checkbox) {\n let courseid = Number(checkbox.dataset.courseid);\n if (coursessettings.hasOwnProperty(courseid)) {\n // If the setting is false, uncheck the checkbox.\n if (!coursessettings[courseid] && checkbox.checked) {\n checkbox.click();\n }\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 letter_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 }\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 * Collects and updates the course filter settings.\n * Ensures previous settings are retained even if a course does not show notifications temporarily..\n *\n * @param {?string} coursesettingsfromdb\n * @returns {string}\n */\nfunction collectcoursesettings(coursesettingsfromdb) {\n // Check if the course settings have been set in the past.\n let settings = coursesettingsfromdb ? JSON.parse(coursesettingsfromdb) : {};\n\n // Build a JSON in the format courseid => coursename.\n course_checkboxes.forEach(function(checkbox) {\n settings[Number(checkbox.dataset.courseid)] = checkbox.checked;\n });\n\n // Return a string version of the settings.\n return JSON.stringify(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.checked || 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.checked || 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.checked || 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":["userid","settingsfromdb","futurebuttonid","converttimetoid","timefilterfuture","pastbuttonid","timefilterpast","alltimebutton","forEach","checked","futureradiobuttons","button","id","parentNode","classList","add","dispatchEvent","Event","pastradiobuttons","letter_checkboxes","checkbox","basiclettercheck","basicletter","completionlettercheck","completionletter","postlettercheck","postletter","click","coursessettings","JSON","parse","courses","course_checkboxes","courseid","Number","dataset","hasOwnProperty","executeusersettings","savebutton","addEventListener","async","timespans","settings","timepast","timefuture","settingsset","contains","convertidtotime","collecttimefiltersettings","letterfilter","collectletterfiltersettings","coursesettingsfromdb","stringify","collectcoursesettings","result","data","methodname","args","Ajax","call","setTimeout","remove","saveusersettings","document","getElementById","querySelectorAll","time","future"],"mappings":"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"} \ No newline at end of file diff --git a/amd/build/filter/coursefilter.min.js b/amd/build/filter/coursefilter.min.js new file mode 100644 index 0000000..76a03e7 --- /dev/null +++ b/amd/build/filter/coursefilter.min.js @@ -0,0 +1,14 @@ +define("block_townsquare/filter/coursefilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){checkboxes.forEach((function(checkbox){checkbox.addEventListener("change",(function(){const courseid=Number(checkbox.dataset.courseid);document.querySelectorAll(".townsquare_letter").forEach((function(letter){let letterCourseId=Number(letter.querySelector(".townsquareletter_course").dataset.courseid);courseid===letterCourseId&&(checkbox.checked?letter.classList.add("ts_coursefilter_approved"):letter.classList.remove("ts_coursefilter_approved"))}))}))}))}; +/** + * JavaScript for the course filter + * + * This file implements 1 functionality: + * - Checks the checkboxes of the course filter and hides content from courses if the checkbox is not checked. + * + * @module block_townsquare/filter/coursefilter + * @copyright 2024 Tamaro Walter + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const checkboxes=document.querySelectorAll(".ts_course_checkbox")})); + +//# sourceMappingURL=coursefilter.min.js.map \ No newline at end of file diff --git a/amd/build/filter/coursefilter.min.js.map b/amd/build/filter/coursefilter.min.js.map new file mode 100644 index 0000000..09e7297 --- /dev/null +++ b/amd/build/filter/coursefilter.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"coursefilter.min.js","sources":["../../src/filter/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/filter/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. Adds an event listener to the course filter checkboxes. This is part of the content filtering functionality.\n * Every checkbox represents one course that shows content in Town square.\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 = Number(checkbox.dataset.courseid);\n\n // Get all letters.\n const letters = document.querySelectorAll('.townsquare_letter');\n\n // Loop through each letter and mark it as \"approved\" or not based on checkbox state and the letter id.\n letters.forEach(function(letter) {\n let letterCourseId = Number(letter.querySelector('.townsquareletter_course').dataset.courseid);\n\n if (courseid === letterCourseId) {\n if (checkbox.checked) {\n letter.classList.add('ts_coursefilter_approved'); // Mark the letter as \"approved\".\n } else {\n letter.classList.remove('ts_coursefilter_approved'); // Mark the letter as \"not approved\".\n }\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","courseid","Number","dataset","document","querySelectorAll","letter","letterCourseId","querySelector","checked","classList","add","remove"],"mappings":"+JAkCIA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,iBAE1BC,SAAWC,OAAOH,SAASI,QAAQF,UAGzBG,SAASC,iBAAiB,sBAGlCP,SAAQ,SAASQ,YACjBC,eAAiBL,OAAOI,OAAOE,cAAc,4BAA4BL,QAAQF,UAEjFA,WAAaM,iBACTR,SAASU,QACTH,OAAOI,UAAUC,IAAI,4BAErBL,OAAOI,UAAUE,OAAO;;;;;;;;;;;MAvB1Cf,WAAaO,SAASC,iBAAiB"} \ No newline at end of file diff --git a/amd/build/filter/filtercontroller.min.js b/amd/build/filter/filtercontroller.min.js new file mode 100644 index 0000000..412f1ec --- /dev/null +++ b/amd/build/filter/filtercontroller.min.js @@ -0,0 +1,11 @@ +define("block_townsquare/filter/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){const observer=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",function(letter){const group=letter.closest(".ts-lettergroup");if(!group)return;const letters=group.querySelectorAll(".ts-letter-box > *"),anyVisible=Array.from(letters).some((el=>el.classList.contains("ts_coursefilter_approved")&&el.classList.contains("ts_timefilter_approved")&&el.classList.contains("ts_letterfilter_approved")));group.style.display=anyVisible?"block":"none"}(letter)}}))}));observer.observe(letter,{attributes:!0})}))}; +/** + * JavaScript to show/hide letters based on all filters + * + * @module block_townsquare/filter/filtercontroller + * @copyright 2024 Tamaro Walter + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const letters=document.querySelectorAll(".townsquare_letter")})); + +//# sourceMappingURL=filtercontroller.min.js.map \ No newline at end of file diff --git a/amd/build/filter/filtercontroller.min.js.map b/amd/build/filter/filtercontroller.min.js.map new file mode 100644 index 0000000..1389ae2 --- /dev/null +++ b/amd/build/filter/filtercontroller.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"filtercontroller.min.js","sources":["../../src/filter/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 * @module block_townsquare/filter/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. Controls the visibility of letters based on the approval of all filters.\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 approve the letter, show the letter.\n letter.style.display = (coursefilter && timefilter && letterfilter) ? 'block' : 'none';\n\n // Check if the letters group should be visible or not.\n updatelettergroup(letter);\n }\n });\n });\n\n observer.observe(letter, {attributes: true});\n });\n}\n\n/**\n * Helper function that checks if a letter group should still be visible. Is used if a filter is applied\n * that could change the visibility of one letter and therefore the letters group.\n * @param {HTMLElement} letter\n */\nfunction updatelettergroup(letter) {\n // Get the letters group.\n const group = letter.closest('.ts-lettergroup');\n if (!group) {\n return;\n }\n\n // Check every group letters visibility.\n const letters = group.querySelectorAll('.ts-letter-box > *');\n const anyVisible = Array.from(letters).some(el =>\n el.classList.contains('ts_coursefilter_approved') &&\n el.classList.contains('ts_timefilter_approved') &&\n el.classList.contains('ts_letterfilter_approved')\n );\n\n // Group only gets shown if at least one element is visible.\n group.style.display = anyVisible ? 'block' : 'none';\n}\n"],"names":["letters","forEach","letter","classList","add","observer","MutationObserver","mutations","mutation","attributeName","coursefilter","contains","timefilter","letterfilter","style","display","group","closest","querySelectorAll","anyVisible","Array","from","some","el","updatelettergroup","observe","attributes","document"],"mappings":"mKA+BIA,QAAQC,SAAQ,SAASC,QACrBA,OAAOC,UAAUC,IAAI,4BACrBF,OAAOC,UAAUC,IAAI,0BACrBF,OAAOC,UAAUC,IAAI,+BAIzBJ,QAAQC,SAAQ,SAASC,cACfG,SAAW,IAAIC,kBAAiB,SAASC,WAC3CA,UAAUN,SAAQ,SAASO,aACQ,UAA3BA,SAASC,cAA2B,KAEhCC,aAAeR,OAAOC,UAAUQ,SAAS,4BACzCC,WAAaV,OAAOC,UAAUQ,SAAS,0BACvCE,aAAeX,OAAOC,UAAUQ,SAAS,4BAG7CT,OAAOY,MAAMC,QAAWL,cAAgBE,YAAcC,aAAgB,QAAU,gBAiBzEX,cAEjBc,MAAQd,OAAOe,QAAQ,uBACxBD,mBAKChB,QAAUgB,MAAME,iBAAiB,sBACjCC,WAAaC,MAAMC,KAAKrB,SAASsB,MAAKC,IACxCA,GAAGpB,UAAUQ,SAAS,6BACtBY,GAAGpB,UAAUQ,SAAS,2BACtBY,GAAGpB,UAAUQ,SAAS,8BAI1BK,MAAMF,MAAMC,QAAUI,WAAa,QAAU,OA9B7BK,CAAkBtB,eAK9BG,SAASoB,QAAQvB,OAAQ,CAACwB,YAAY;;;;;;;;MAhCxC1B,QAAU2B,SAAST,iBAAiB"} \ No newline at end of file diff --git a/amd/build/filter/letterfilter.min.js b/amd/build/filter/letterfilter.min.js new file mode 100644 index 0000000..8ec5833 --- /dev/null +++ b/amd/build/filter/letterfilter.min.js @@ -0,0 +1,11 @@ +define("block_townsquare/filter/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).forEach((function(letter){checkbox.checked?letter.classList.add("ts_letterfilter_approved"):letter.classList.remove("ts_letterfilter_approved")}))}))}))}; +/** + * JavaScript for the letter filter + * + * @module block_townsquare/filter/letterfilter + * @copyright 2024 Tamaro Walter + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +const checkboxes=document.querySelectorAll(".ts_letter_checkbox")})); + +//# sourceMappingURL=letterfilter.min.js.map \ No newline at end of file diff --git a/amd/build/filter/letterfilter.min.js.map b/amd/build/filter/letterfilter.min.js.map new file mode 100644 index 0000000..75cbd0a --- /dev/null +++ b/amd/build/filter/letterfilter.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"letterfilter.min.js","sources":["../../src/filter/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 * @module block_townsquare/filter/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. Adds an event listener to the letter filter checkboxes. This is part of the content filtering functionality.\n * Every checkbox represents a kind of letter (posts, activity completions, basic notifications) that shows content in Town square.\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 associate with the checkbox.\n const letters = document.querySelectorAll('.townsquare_letter.' + lettername);\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 \"approved\".\n } else {\n letter.classList.remove('ts_letterfilter_approved'); // Mark the letter as \"not approved\".\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","lettername","id","document","querySelectorAll","letter","checked","classList","add","remove"],"mappings":"+JA+BIA,WAAWC,SAAQ,SAASC,UACxBA,SAASC,iBAAiB,UAAU,iBAE1BC,WAAaF,SAASG,GAGZC,SAASC,iBAAiB,sBAAwBH,YAG1DH,SAAQ,SAASO,QACjBN,SAASO,QACTD,OAAOE,UAAUC,IAAI,4BAErBH,OAAOE,UAAUE,OAAO;;;;;;;;MApBtCZ,WAAaM,SAASC,iBAAiB"} \ No newline at end of file diff --git a/amd/build/filter/timefilter.min.js b/amd/build/filter/timefilter.min.js new file mode 100644 index 0000000..273b42e --- /dev/null +++ b/amd/build/filter/timefilter.min.js @@ -0,0 +1,14 @@ +define("block_townsquare/filter/timefilter",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){currenttime=(new Date).getTime()/1e3,alltimebutton.forEach((function(button){button.addEventListener("change",(function(){timestart=currenttime-convertidtotime(button.id),timeend=currenttime+convertidtotime(button.id),addstarttime=0,addendtime=0,futureradiobuttons.forEach((function(futureradiobutton){futureradiobutton.checked=!1,futureradiobutton.parentNode.classList.remove("active")})),pastradiobuttons.forEach((function(pastradiobutton){pastradiobutton.checked=!1,pastradiobutton.parentNode.classList.remove("active")})),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)}))})),futureradiobuttons.forEach((function(button){button.addEventListener("change",(function(){alltimebutton.forEach((function(alltimebutton){alltimebutton.checked=!1,alltimebutton.parentNode.classList.remove("active")})),timestart=currenttime,timeend=currenttime+convertidtotime(button.id),addstarttime=0,addendtime=0,pastradiobuttons.forEach((function(pastradiobutton){(pastradiobutton.checked||pastradiobutton.parentNode.classList.contains("active"))&&(addstarttime=currenttime-convertidtotime(pastradiobutton.id),addendtime=currenttime)})),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)}))})),pastradiobuttons.forEach((function(button){button.addEventListener("change",(function(){alltimebutton.forEach((function(alltimebutton){alltimebutton.checked=!1})),timestart=currenttime-convertidtotime(button.id),timeend=currenttime,addstarttime=0,addendtime=0,futureradiobuttons.forEach((function(futureradiobutton){(futureradiobutton.checked||futureradiobutton.parentNode.classList.contains("active"))&&(addstarttime=currenttime,addendtime=currenttime+convertidtotime(futureradiobutton.id))})),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)}))}))}; +/** + * JavaScript for the time filter + * + * This file implements 1 functionality: + * - Checks, which of the radio buttons is pressed and filters the content based on the time. + * + * @module block_townsquare/filter/timefilter + * @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").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/filter/timefilter.min.js.map b/amd/build/filter/timefilter.min.js.map new file mode 100644 index 0000000..b51ac73 --- /dev/null +++ b/amd/build/filter/timefilter.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"timefilter.min.js","sources":["../../src/filter/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/filter/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 kinds 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.\n const letters = document.querySelectorAll('.townsquare_letter');\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 // 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.checked || 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 });\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.checked || 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":"6JA2CIA,aAAc,IAAIC,MAAOC,UAAY,IAwCrCC,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,aAIhDG,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU,eAS3EF,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,WAAa,EACbO,iBAAiBf,SAAQ,SAASgB,kBAC1BA,gBAAgBL,SAAWK,gBAAgBJ,WAAWC,UAAUK,SAAS,aACzEX,aAAeX,YAAcQ,gBAAgBY,gBAAgBX,IAC7DG,WAAaZ,gBAKrBqB,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU,eAS3EI,iBAAiBf,SAAQ,SAASC,QAC9BA,OAAOC,iBAAiB,UAAU,WAE9BH,cAAcC,SAAQ,SAASD,eAC3BA,cAAcY,SAAU,KAI5BR,UAAYP,YAAcQ,gBAAgBH,OAAOI,IACjDC,QAAUV,YAGVW,aAAe,EACfC,WAAa,EACbC,mBAAmBT,SAAQ,SAASU,oBAC5BA,kBAAkBC,SAAWD,kBAAkBE,WAAWC,UAAUK,SAAS,aAC7EX,aAAeX,YACfY,WAAaZ,YAAcQ,gBAAgBM,kBAAkBL,QAKrEY,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU;;;;;;;;;;;MA1IzEZ,cAAgBoB,SAASC,iBAAiB,uBAC1CX,mBAAqBU,SAASC,iBAAiB,0BAC/CL,iBAAmBI,SAASC,iBAAiB,4BAG/CxB,YACAO,UACAG,QACAC,aACAC,oBAuBKS,cAAcI,UAAWC,QAASf,aAAcC,WAAYe,aAEjDJ,SAASC,iBAAiB,sBAGlCpB,SAAQ,SAASwB,YAGjBC,WAAaD,OAAOE,cAAc,0BAA0BrB,GAG3DkB,aAAgBE,YAAcJ,WAAaI,YAAcH,SACzDG,YAAclB,cAAgBkB,YAAcjB,WAC7CgB,OAAOX,UAAUc,IAAI,0BAErBH,OAAOX,UAAUC,OAAO,sCAqG3BV,gBAAgBC,WACbA,QACC,qBACM,aACN,2BACA,8BACM,WACN,4BACA,+BACM,UACN,wBACA,2BACM,WACN,yBACA,4BACM"} \ No newline at end of file diff --git a/amd/build/filtercontroller.min.js b/amd/build/filtercontroller.min.js deleted file mode 100644 index e84d240..0000000 --- a/amd/build/filtercontroller.min.js +++ /dev/null @@ -1,11 +0,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){const observer=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",function(letter){const group=letter.closest(".ts-lettergroup");if(!group)return;const letters=group.querySelectorAll(".ts-letter-box > *"),anyVisible=Array.from(letters).some(el=>el.classList.contains("ts_coursefilter_approved")&&el.classList.contains("ts_timefilter_approved")&&el.classList.contains("ts_letterfilter_approved"));group.style.display=anyVisible?"block":"none"}(letter)}})});observer.observe(letter,{attributes:!0})})}; -/** - * JavaScript to show/hide letters based on all filters - * - * @module block_townsquare/filtercontroller - * @copyright 2024 Tamaro Walter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -const letters=document.querySelectorAll(".townsquare_letter")}); - -//# sourceMappingURL=filtercontroller.min.js.map \ No newline at end of file diff --git a/amd/build/filtercontroller.min.js.map b/amd/build/filtercontroller.min.js.map deleted file mode 100644 index 0b65b52..0000000 --- a/amd/build/filtercontroller.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 * @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. Controls the visibility of letters based on the approval of all filters.\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 approve the letter, show the letter.\n letter.style.display = (coursefilter && timefilter && letterfilter) ? 'block' : 'none';\n\n // Check if the letters group should be visible or not.\n updatelettergroup(letter);\n }\n });\n });\n\n observer.observe(letter, {attributes: true});\n });\n}\n\n/**\n * Helper function that checks if a letter group should still be visible. Is used if a filter is applied\n * that could change the visibility of one letter and therefore the letters group.\n * @param {HTMLElement} letter\n */\nfunction updatelettergroup(letter) {\n // Get the letters group.\n const group = letter.closest('.ts-lettergroup');\n if (!group) {\n return;\n }\n\n // Check every group letters visibility.\n const letters = group.querySelectorAll('.ts-letter-box > *');\n const anyVisible = Array.from(letters).some(el =>\n el.classList.contains('ts_coursefilter_approved') &&\n el.classList.contains('ts_timefilter_approved') &&\n el.classList.contains('ts_letterfilter_approved')\n );\n\n // Group only gets shown if at least one element is visible.\n group.style.display = anyVisible ? 'block' : 'none';\n}"],"names":["letters","forEach","letter","classList","add","observer","MutationObserver","mutations","mutation","attributeName","coursefilter","contains","timefilter","letterfilter","style","display","group","closest","querySelectorAll","anyVisible","Array","from","some","el","updatelettergroup","observe","attributes","document"],"mappings":"gJA6BO,WAEHA,QAAQC,QAAQ,SAASC,QACrBA,OAAOC,UAAUC,IAAI,4BACrBF,OAAOC,UAAUC,IAAI,0BACrBF,OAAOC,UAAUC,IAAI,2BACzB,GAGAJ,QAAQC,QAAQ,SAASC,QACrB,MAAMG,SAAW,IAAIC,iBAAiB,SAASC,WAC3CA,UAAUN,QAAQ,SAASO,UACvB,GAA+B,UAA3BA,SAASC,cAA2B,CAEpC,IAAIC,aAAeR,OAAOC,UAAUQ,SAAS,4BACzCC,WAAaV,OAAOC,UAAUQ,SAAS,0BACvCE,aAAeX,OAAOC,UAAUQ,SAAS,4BAG7CT,OAAOY,MAAMC,QAAWL,cAAgBE,YAAcC,aAAgB,QAAU,OAiBpG,SAA2BX,QAEvB,MAAMc,MAAQd,OAAOe,QAAQ,mBAC7B,IAAKD,MACD,OAIJ,MAAMhB,QAAUgB,MAAME,iBAAiB,sBACjCC,WAAaC,MAAMC,KAAKrB,SAASsB,KAAKC,IACxCA,GAAGpB,UAAUQ,SAAS,6BACtBY,GAAGpB,UAAUQ,SAAS,2BACtBY,GAAGpB,UAAUQ,SAAS,6BAI1BK,MAAMF,MAAMC,QAAUI,WAAa,QAAU,MACjD,CA/BoBK,CAAkBtB,OACtB,CACJ,EACJ,GAEAG,SAASoB,QAAQvB,OAAQ,CAACwB,YAAY,GAC1C,EACJ;;;;;;;;AAlCA,MAAM1B,QAAU2B,SAAST,iBAAiB,qBA0DzC"} \ No newline at end of file diff --git a/amd/build/letterfilter.min.js b/amd/build/letterfilter.min.js deleted file mode 100644 index 54ac7d9..0000000 --- a/amd/build/letterfilter.min.js +++ /dev/null @@ -1,11 +0,0 @@ -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).forEach(function(letter){checkbox.checked?letter.classList.add("ts_letterfilter_approved"):letter.classList.remove("ts_letterfilter_approved")})})})}; -/** - * JavaScript for the letter filter - * - * @module block_townsquare/letterfilter - * @copyright 2024 Tamaro Walter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -const checkboxes=document.querySelectorAll(".ts_letter_checkbox")}); - -//# sourceMappingURL=letterfilter.min.js.map \ No newline at end of file diff --git a/amd/build/letterfilter.min.js.map b/amd/build/letterfilter.min.js.map deleted file mode 100644 index eba450e..0000000 --- a/amd/build/letterfilter.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 * @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. Adds an event listener to the letter filter checkboxes. This is part of the content filtering functionality.\n * Every checkbox represents a kind of letter (posts, activity completions, basic notifications) that shows content in Town square.\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 associate with the checkbox.\n const letters = document.querySelectorAll('.townsquare_letter.' + lettername);\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 \"approved\".\n } else {\n letter.classList.remove('ts_letterfilter_approved'); // Mark the letter as \"not approved\".\n }\n });\n });\n });\n}\n"],"names":["checkboxes","forEach","checkbox","addEventListener","lettername","id","document","querySelectorAll","letter","checked","classList","add","remove"],"mappings":"4IA8BO,WACHA,WAAWC,QAAQ,SAASC,UACxBA,SAASC,iBAAiB,SAAU,WAEhC,MAAMC,WAAaF,SAASG,GAGZC,SAASC,iBAAiB,sBAAwBH,YAG1DH,QAAQ,SAASO,QACjBN,SAASO,QACTD,OAAOE,UAAUC,IAAI,4BAErBH,OAAOE,UAAUE,OAAO,2BAEhC,EACJ,EACJ,EACJ;;;;;;;;AAzBA,MAAMZ,WAAaM,SAASC,iBAAiB,sBAyB5C"} \ No newline at end of file diff --git a/amd/build/lettergroup.min.js b/amd/build/lettergroup.min.js index 57bb9ed..24200a7 100644 --- a/amd/build/lettergroup.min.js +++ b/amd/build/lettergroup.min.js @@ -1,4 +1,4 @@ -define("block_townsquare/lettergroup",["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){letterboxes.forEach(element=>{element.style.maxHeight=`${element.scrollHeight}px`,element.setAttribute("expanded","true")}),document.addEventListener("click",e=>{const group=e.target.closest(Selectors.actions.collapsegroup);if(group){const icon=group.querySelector("i");let groupid=group.dataset.groupid;letterboxes.forEach(element=>{element.dataset.groupid===groupid&&("true"===element.getAttribute("expanded")?(icon.classList.remove("fa-chevron-down"),icon.classList.add("fa-chevron-up"),element.style.maxHeight="0px",element.setAttribute("expanded","false")):(icon.classList.remove("fa-chevron-up"),icon.classList.add("fa-chevron-down"),element.style.maxHeight=`${element.scrollHeight}px`,element.setAttribute("expanded","true")))})}})}; +define("block_townsquare/lettergroup",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){letterboxes.forEach((element=>{element.style.maxHeight="".concat(element.scrollHeight,"px"),element.setAttribute("expanded","true")})),document.addEventListener("click",(e=>{const group=e.target.closest(Selectors_actions.collapsegroup);if(group){const icon=group.querySelector("i");let groupid=group.dataset.groupid;letterboxes.forEach((element=>{element.dataset.groupid===groupid&&("true"===element.getAttribute("expanded")?(icon.classList.remove("fa-chevron-down"),icon.classList.add("fa-chevron-up"),element.style.maxHeight="0px",element.setAttribute("expanded","false")):(icon.classList.remove("fa-chevron-up"),icon.classList.add("fa-chevron-down"),element.style.maxHeight="".concat(element.scrollHeight,"px"),element.setAttribute("expanded","true")))}))}}))}; /** * JavaScript for the letter group. * @@ -6,6 +6,6 @@ define("block_townsquare/lettergroup",["exports"],function(_exports){Object.defi * @copyright 2025 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const letterboxes=document.getElementsByClassName("ts-letter-box"),Selectors={actions:{collapsegroup:'[data-action="block_townsquare/collapse_group"]'}}}); +const letterboxes=document.getElementsByClassName("ts-letter-box"),Selectors_actions={collapsegroup:'[data-action="block_townsquare/collapse_group"]'}})); //# sourceMappingURL=lettergroup.min.js.map \ No newline at end of file diff --git a/amd/build/lettergroup.min.js.map b/amd/build/lettergroup.min.js.map index ce5a3fc..cc93324 100644 --- a/amd/build/lettergroup.min.js.map +++ b/amd/build/lettergroup.min.js.map @@ -1 +1 @@ -{"version":3,"file":"lettergroup.min.js","sources":["../src/lettergroup.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 group.\n *\n * @module block_townsquare/lettergroup\n * @copyright 2025 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst letterboxes = document.getElementsByClassName('ts-letter-box');\n\nconst Selectors = {\n actions: {\n collapsegroup: '[data-action=\"block_townsquare/collapse_group\"]',\n },\n};\n\n/**\n * Init function. Adds event listener to orientation marker of letter group to enable\n * collapsing a letter group.\n */\nexport function init() {\n letterboxes.forEach(\n (element) => {\n element.style.maxHeight = `${element.scrollHeight}px`;\n element.setAttribute('expanded', 'true');\n }\n );\n\n document.addEventListener('click', e => {\n const group = e.target.closest(Selectors.actions.collapsegroup);\n if (group) {\n const icon = group.querySelector('i');\n let groupid = group.dataset.groupid;\n letterboxes.forEach(\n (element) => {\n if (element.dataset.groupid === groupid) {\n if (element.getAttribute('expanded') === 'true') {\n icon.classList.remove('fa-chevron-down');\n icon.classList.add('fa-chevron-up');\n element.style.maxHeight = '0px';\n element.setAttribute('expanded', 'false');\n } else {\n icon.classList.remove('fa-chevron-up');\n icon.classList.add('fa-chevron-down');\n element.style.maxHeight = `${element.scrollHeight}px`;\n element.setAttribute('expanded', 'true');\n }\n }\n }\n );\n }\n });\n}"],"names":["letterboxes","forEach","element","style","maxHeight","scrollHeight","setAttribute","document","addEventListener","e","group","target","closest","Selectors","actions","collapsegroup","icon","querySelector","groupid","dataset","getAttribute","classList","remove","add","getElementsByClassName"],"mappings":"2IAmCO,WACHA,YAAYC,QACPC,UACGA,QAAQC,MAAMC,UAAY,GAAGF,QAAQG,iBACrCH,QAAQI,aAAa,WAAY,UAIzCC,SAASC,iBAAiB,QAASC,IAC/B,MAAMC,MAAQD,EAAEE,OAAOC,QAAQC,UAAUC,QAAQC,eACjD,GAAIL,MAAO,CACP,MAAMM,KAAON,MAAMO,cAAc,KACjC,IAAIC,QAAUR,MAAMS,QAAQD,QAC5BlB,YAAYC,QACPC,UACOA,QAAQiB,QAAQD,UAAYA,UACa,SAArChB,QAAQkB,aAAa,aACrBJ,KAAKK,UAAUC,OAAO,mBACtBN,KAAKK,UAAUE,IAAI,iBACnBrB,QAAQC,MAAMC,UAAY,MAC1BF,QAAQI,aAAa,WAAY,WAEjCU,KAAKK,UAAUC,OAAO,iBACtBN,KAAKK,UAAUE,IAAI,mBACnBrB,QAAQC,MAAMC,UAAY,GAAGF,QAAQG,iBACrCH,QAAQI,aAAa,WAAY,WAKrD,GAER;;;;;;;;AA5CA,MAAMN,YAAcO,SAASiB,uBAAuB,iBAE9CX,UAAY,CACdC,QAAS,CACLC,cAAe,mDAwCtB"} \ No newline at end of file +{"version":3,"file":"lettergroup.min.js","sources":["../src/lettergroup.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 group.\n *\n * @module block_townsquare/lettergroup\n * @copyright 2025 Tamaro Walter\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst letterboxes = document.getElementsByClassName('ts-letter-box');\n\nconst Selectors = {\n actions: {\n collapsegroup: '[data-action=\"block_townsquare/collapse_group\"]',\n },\n};\n\n/**\n * Init function. Adds event listener to orientation marker of letter group to enable\n * collapsing a letter group.\n */\nexport function init() {\n letterboxes.forEach(\n (element) => {\n element.style.maxHeight = `${element.scrollHeight}px`;\n element.setAttribute('expanded', 'true');\n }\n );\n\n document.addEventListener('click', e => {\n const group = e.target.closest(Selectors.actions.collapsegroup);\n if (group) {\n const icon = group.querySelector('i');\n let groupid = group.dataset.groupid;\n letterboxes.forEach(\n (element) => {\n if (element.dataset.groupid === groupid) {\n if (element.getAttribute('expanded') === 'true') {\n icon.classList.remove('fa-chevron-down');\n icon.classList.add('fa-chevron-up');\n element.style.maxHeight = '0px';\n element.setAttribute('expanded', 'false');\n } else {\n icon.classList.remove('fa-chevron-up');\n icon.classList.add('fa-chevron-down');\n element.style.maxHeight = `${element.scrollHeight}px`;\n element.setAttribute('expanded', 'true');\n }\n }\n }\n );\n }\n });\n}\n"],"names":["letterboxes","forEach","element","style","maxHeight","scrollHeight","setAttribute","document","addEventListener","e","group","target","closest","Selectors","collapsegroup","icon","querySelector","groupid","dataset","getAttribute","classList","remove","add","getElementsByClassName"],"mappings":"uJAoCIA,YAAYC,SACPC,UACGA,QAAQC,MAAMC,oBAAeF,QAAQG,mBACrCH,QAAQI,aAAa,WAAY,WAIzCC,SAASC,iBAAiB,SAASC,UACzBC,MAAQD,EAAEE,OAAOC,QAAQC,kBAAkBC,kBAC7CJ,MAAO,OACDK,KAAOL,MAAMM,cAAc,SAC7BC,QAAUP,MAAMQ,QAAQD,QAC5BjB,YAAYC,SACPC,UACOA,QAAQgB,QAAQD,UAAYA,UACa,SAArCf,QAAQiB,aAAa,aACrBJ,KAAKK,UAAUC,OAAO,mBACtBN,KAAKK,UAAUE,IAAI,iBACnBpB,QAAQC,MAAMC,UAAY,MAC1BF,QAAQI,aAAa,WAAY,WAEjCS,KAAKK,UAAUC,OAAO,iBACtBN,KAAKK,UAAUE,IAAI,mBACnBpB,QAAQC,MAAMC,oBAAeF,QAAQG,mBACrCH,QAAQI,aAAa,WAAY;;;;;;;;MArCvDN,YAAcO,SAASgB,uBAAuB,iBAE9CV,kBACO,CACLC,cAAe"} \ No newline at end of file diff --git a/amd/build/postletter.min.js b/amd/build/postletter.min.js index 419033f..fa84b9a 100644 --- a/amd/build/postletter.min.js +++ b/amd/build/postletter.min.js @@ -1,4 +1,4 @@ -define("block_townsquare/postletter",["exports","core/str","core/prefetch"],function(_exports,_str,_prefetch){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){(0,_prefetch.prefetchStrings)("moodle",["showmore","showless"]),contentElements.forEach(element=>{element.clientHeight>=90?buttons[element.id].setAttribute("showmore","true"):buttons[element.id].style.display="none"}),addEventListener()}; +define("block_townsquare/postletter",["exports","core/str","core/prefetch"],(function(_exports,_str,_prefetch){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){(0,_prefetch.prefetchStrings)("moodle",["showmore","showless"]),contentElements.forEach((element=>{element.clientHeight>=90?buttons[element.id].setAttribute("showmore","true"):buttons[element.id].style.display="none"})),addEventListener()}; /** * JavaScript for the post letter * @@ -6,6 +6,6 @@ define("block_townsquare/postletter",["exports","core/str","core/prefetch"],func * @copyright 2023 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const contentElements=document.getElementsByClassName("postletter_message"),buttons=document.getElementsByClassName("townsquare_showmore"),Selectors_actions={seemorebutton:'[data-action="block_townsquare/showmore_button"]'};const addEventListener=()=>{document.addEventListener("click",e=>{if(e.target.closest(Selectors_actions.seemorebutton)){let letterid=e.target.id;contentElements.forEach(element=>{element.id==letterid&&("true"==buttons[letterid].getAttribute("showmore")?(element.classList.add("expanded"),changeButtonString(letterid,!1)):(element.classList.remove("expanded"),changeButtonString(letterid,!0)))})}})};async function changeButtonString(index,toshowmore){1==toshowmore?(buttons[index].textContent=await(0,_str.getString)("showmore","moodle"),buttons[index].setAttribute("showmore","true")):(buttons[index].textContent=await(0,_str.getString)("showless","moodle"),buttons[index].setAttribute("showmore","false"))}}); +const contentElements=document.getElementsByClassName("postletter_message"),buttons=document.getElementsByClassName("townsquare_showmore"),Selectors_actions={seemorebutton:'[data-action="block_townsquare/showmore_button"]'};const addEventListener=()=>{document.addEventListener("click",(e=>{if(e.target.closest(Selectors_actions.seemorebutton)){let letterid=e.target.id;contentElements.forEach((element=>{element.id==letterid&&("true"==buttons[letterid].getAttribute("showmore")?(element.classList.add("expanded"),changeButtonString(letterid,!1)):(element.classList.remove("expanded"),changeButtonString(letterid,!0)))}))}}))};async function changeButtonString(index,toshowmore){1==toshowmore?(buttons[index].textContent=await(0,_str.getString)("showmore","moodle"),buttons[index].setAttribute("showmore","true")):(buttons[index].textContent=await(0,_str.getString)("showless","moodle"),buttons[index].setAttribute("showmore","false"))}})); //# sourceMappingURL=postletter.min.js.map \ No newline at end of file diff --git a/amd/build/postletter.min.js.map b/amd/build/postletter.min.js.map index 93539d9..f8c412f 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 * @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');\n\nconst Selectors = {\n actions: {\n seemorebutton: '[data-action=\"block_townsquare/showmore_button\"]',\n },\n};\n\n/**\n * Init function. It limits the height of posts that are too long and adds a \"show more\" button to them if the user wants to see\n * the full text.\n */\nexport function init() {\n // Get the strings for the show more/show less button.\n prefetchStrings('moodle', ['showmore', 'showless',]);\n\n contentElements.forEach(\n (element) => {\n // Check if the div is too long.\n if (element.clientHeight >= 90) {\n // If the text is too long, show the showmore button.\n buttons[element.id].setAttribute('showmore', 'true');\n } else {\n // If the text is not too long, hide the showmore button.\n buttons[element.id].style.display = \"none\";\n }\n }\n );\n\n // Add event listeners for the show more Button.\n addEventListener();\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.classList.add(\"expanded\");\n changeButtonString(letterid, false);\n } else {\n element.classList.remove(\"expanded\");\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"],"names":["prefetchStrings","contentElements","forEach","element","clientHeight","buttons","id","setAttribute","style","display","addEventListener","document","getElementsByClassName","Selectors","seemorebutton","e","target","closest","letterid","getAttribute","classList","add","changeButtonString","remove","async","index","toshowmore","textContent","getString"],"mappings":"oLAuCO,YAEH,EAAAA,UAAAA,iBAAgB,SAAU,CAAC,WAAY,aAEvCC,gBAAgBC,QACXC,UAEOA,QAAQC,cAAgB,GAExBC,QAAQF,QAAQG,IAAIC,aAAa,WAAY,QAG7CF,QAAQF,QAAQG,IAAIE,MAAMC,QAAU,SAMhDC,kBACJ;;;;;;;;AAhCA,MAAMT,gBAAkBU,SAASC,uBAAuB,sBAClDP,QAAUM,SAASC,uBAAuB,uBAE1CC,kBACO,CACLC,cAAe,oDAgCvB,MAAMJ,iBAAmBA,KACrBC,SAASD,iBAAiB,QAASK,IAC/B,GAAIA,EAAEC,OAAOC,QAAQJ,kBAAkBC,eAAgB,CAEnD,IAAII,SAAWH,EAAEC,OAAOV,GACxBL,gBAAgBC,QACXC,UACOA,QAAQG,IAAMY,WACoC,QAA9Cb,QAAQa,UAAUC,aAAa,aAC/BhB,QAAQiB,UAAUC,IAAI,YACtBC,mBAAmBJ,UAAU,KAE7Bf,QAAQiB,UAAUG,OAAO,YACzBD,mBAAmBJ,UAAU,MAKjD,KASRM,eAAeF,mBAAmBG,MAAOC,YACnB,GAAdA,YACArB,QAAQoB,OAAOE,kBAAoB,EAAAC,KAASA,WAAC,WAAY,UACzDvB,QAAQoB,OAAOlB,aAAa,WAAY,UAExCF,QAAQoB,OAAOE,kBAAoB,EAAAC,KAASA,WAAC,WAAY,UACzDvB,QAAQoB,OAAOlB,aAAa,WAAY,SAEhD,CAAC"} \ 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 * @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');\n\nconst Selectors = {\n actions: {\n seemorebutton: '[data-action=\"block_townsquare/showmore_button\"]',\n },\n};\n\n/**\n * Init function. It limits the height of posts that are too long and adds a \"show more\" button to them if the user wants to see\n * the full text.\n */\nexport function init() {\n // Get the strings for the show more/show less button.\n prefetchStrings('moodle', ['showmore', 'showless',]);\n\n contentElements.forEach(\n (element) => {\n // Check if the div is too long.\n if (element.clientHeight >= 90) {\n // If the text is too long, show the showmore button.\n buttons[element.id].setAttribute('showmore', 'true');\n } else {\n // If the text is not too long, hide the showmore button.\n buttons[element.id].style.display = \"none\";\n }\n }\n );\n\n // Add event listeners for the show more Button.\n addEventListener();\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.classList.add(\"expanded\");\n changeButtonString(letterid, false);\n } else {\n element.classList.remove(\"expanded\");\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"],"names":["contentElements","forEach","element","clientHeight","buttons","id","setAttribute","style","display","addEventListener","document","getElementsByClassName","Selectors","seemorebutton","e","target","closest","letterid","getAttribute","classList","add","changeButtonString","remove","index","toshowmore","textContent"],"mappings":"8NAyCoB,SAAU,CAAC,WAAY,aAEvCA,gBAAgBC,SACXC,UAEOA,QAAQC,cAAgB,GAExBC,QAAQF,QAAQG,IAAIC,aAAa,WAAY,QAG7CF,QAAQF,QAAQG,IAAIE,MAAMC,QAAU,UAMhDC;;;;;;;;MA/BET,gBAAkBU,SAASC,uBAAuB,sBAClDP,QAAUM,SAASC,uBAAuB,uBAE1CC,kBACO,CACLC,cAAe,0DAgCjBJ,iBAAmB,KACrBC,SAASD,iBAAiB,SAASK,OAC3BA,EAAEC,OAAOC,QAAQJ,kBAAkBC,eAAgB,KAE/CI,SAAWH,EAAEC,OAAOV,GACxBL,gBAAgBC,SACXC,UACOA,QAAQG,IAAMY,WACoC,QAA9Cb,QAAQa,UAAUC,aAAa,aAC/BhB,QAAQiB,UAAUC,IAAI,YACtBC,mBAAmBJ,UAAU,KAE7Bf,QAAQiB,UAAUG,OAAO,YACzBD,mBAAmBJ,UAAU,4BAc1CI,mBAAmBE,MAAOC,YACnB,GAAdA,YACApB,QAAQmB,OAAOE,kBAAoB,kBAAU,WAAY,UACzDrB,QAAQmB,OAAOjB,aAAa,WAAY,UAExCF,QAAQmB,OAAOE,kBAAoB,kBAAU,WAAY,UACzDrB,QAAQmB,OAAOjB,aAAa,WAAY"} \ No newline at end of file diff --git a/amd/build/timefilter.min.js b/amd/build/timefilter.min.js deleted file mode 100644 index c313332..0000000 --- a/amd/build/timefilter.min.js +++ /dev/null @@ -1,14 +0,0 @@ -define("block_townsquare/timefilter",["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){currenttime=(new Date).getTime()/1e3,alltimebutton.forEach(function(button){button.addEventListener("change",function(){timestart=currenttime-convertidtotime(button.id),timeend=currenttime+convertidtotime(button.id),addstarttime=0,addendtime=0,futureradiobuttons.forEach(function(futureradiobutton){futureradiobutton.checked=!1,futureradiobutton.parentNode.classList.remove("active")}),pastradiobuttons.forEach(function(pastradiobutton){pastradiobutton.checked=!1,pastradiobutton.parentNode.classList.remove("active")}),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)})}),futureradiobuttons.forEach(function(button){button.addEventListener("change",function(){alltimebutton.forEach(function(alltimebutton){alltimebutton.checked=!1,alltimebutton.parentNode.classList.remove("active")}),timestart=currenttime,timeend=currenttime+convertidtotime(button.id),addstarttime=0,addendtime=0,pastradiobuttons.forEach(function(pastradiobutton){(pastradiobutton.checked||pastradiobutton.parentNode.classList.contains("active"))&&(addstarttime=currenttime-convertidtotime(pastradiobutton.id),addendtime=currenttime)}),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)})}),pastradiobuttons.forEach(function(button){button.addEventListener("change",function(){alltimebutton.forEach(function(alltimebutton){alltimebutton.checked=!1}),timestart=currenttime-convertidtotime(button.id),timeend=currenttime,addstarttime=0,addendtime=0,futureradiobuttons.forEach(function(futureradiobutton){(futureradiobutton.checked||futureradiobutton.parentNode.classList.contains("active"))&&(addstarttime=currenttime,addendtime=currenttime+convertidtotime(futureradiobutton.id))}),executefilter(timestart,timeend,addstarttime,addendtime,button.checked)})})}; -/** - * JavaScript for the time filter - * - * This file implements 1 functionality: - * - Checks, which of the radio buttons is pressed and filters the content based on the time. - * - * @module block_townsquare/timefilter - * @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").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 deleted file mode 100644 index d3da864..0000000 --- a/amd/build/timefilter.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 kinds 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.\n const letters = document.querySelectorAll('.townsquare_letter');\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 // 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.checked || 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 });\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.checked || 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":"0IAyCO,WAEHA,aAAc,IAAIC,MAAOC,UAAY,IAwCrCC,cAAcC,QAAQ,SAASC,QAC3BA,OAAOC,iBAAiB,SAAU,WAE9BC,UAAYP,YAAcQ,gBAAgBH,OAAOI,IACjDC,QAAUV,YAAcQ,gBAAgBH,OAAOI,IAC/CE,aAAe,EACfC,WAAa,EAGbC,mBAAmBT,QAAQ,SAASU,mBAChCA,kBAAkBC,SAAU,EAC5BD,kBAAkBE,WAAWC,UAAUC,OAAO,SAClD,GACAC,iBAAiBf,QAAQ,SAASgB,iBAC9BA,gBAAgBL,SAAU,EAC1BK,gBAAgBJ,WAAWC,UAAUC,OAAO,SAChD,GAGAG,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU,QACvE,EACJ,GAOAF,mBAAmBT,QAAQ,SAASC,QAChCA,OAAOC,iBAAiB,SAAU,WAE9BH,cAAcC,QAAQ,SAASD,eAC3BA,cAAcY,SAAU,EACxBZ,cAAca,WAAWC,UAAUC,OAAO,SAC9C,GAGAX,UAAYP,YACZU,QAAUV,YAAcQ,gBAAgBH,OAAOI,IAG/CE,aAAe,EACfC,WAAa,EACbO,iBAAiBf,QAAQ,SAASgB,kBAC1BA,gBAAgBL,SAAWK,gBAAgBJ,WAAWC,UAAUK,SAAS,aACzEX,aAAeX,YAAcQ,gBAAgBY,gBAAgBX,IAC7DG,WAAaZ,YAErB,GAGAqB,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU,QACvE,EACJ,GAOAI,iBAAiBf,QAAQ,SAASC,QAC9BA,OAAOC,iBAAiB,SAAU,WAE9BH,cAAcC,QAAQ,SAASD,eAC3BA,cAAcY,SAAU,CAC5B,GAGAR,UAAYP,YAAcQ,gBAAgBH,OAAOI,IACjDC,QAAUV,YAGVW,aAAe,EACfC,WAAa,EACbC,mBAAmBT,QAAQ,SAASU,oBAC5BA,kBAAkBC,SAAWD,kBAAkBE,WAAWC,UAAUK,SAAS,aAC7EX,aAAeX,YACfY,WAAaZ,YAAcQ,gBAAgBM,kBAAkBL,IAErE,GAGAY,cAAcd,UAAWG,QAASC,aAAcC,WAAYP,OAAOU,QACvE,EACJ,EAtHJ;;;;;;;;;;;AAtBA,MAAMZ,cAAgBoB,SAASC,iBAAiB,uBAC1CX,mBAAqBU,SAASC,iBAAiB,0BAC/CL,iBAAmBI,SAASC,iBAAiB,wBAGnD,IAAIxB,YACAO,UACAG,QACAC,aACAC,WAuBJ,SAASS,cAAcI,UAAWC,QAASf,aAAcC,WAAYe,aAEjDJ,SAASC,iBAAiB,sBAGlCpB,QAAQ,SAASwB,QAGrB,IAAIC,WAAaD,OAAOE,cAAc,0BAA0BrB,GAG3DkB,aAAgBE,YAAcJ,WAAaI,YAAcH,SACzDG,YAAclB,cAAgBkB,YAAcjB,WAC7CgB,OAAOX,UAAUc,IAAI,0BAErBH,OAAOX,UAAUC,OAAO,yBAEhC,EACJ,CAkGA,SAASV,gBAAgBC,IACrB,OAAQA,IACJ,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,OAEnB,CAAC"} \ No newline at end of file diff --git a/amd/build/usersettings_reset.min.js b/amd/build/usersettings_reset.min.js deleted file mode 100644 index 0bf29fa..0000000 --- a/amd/build/usersettings_reset.min.js +++ /dev/null @@ -1,13 +0,0 @@ -define("block_townsquare/usersettings_reset",["exports","core/ajax"],function(_exports,_ajax){var e; -/** - * JavaScript to reset the user settings. - * - * This file implements 1 functionality: - * - If the "reset settings" button is pressed, reset all settings and delete the users database record. - * - * @module block_townsquare/usersettings_reset - * @copyright 2024 Tamaro Walter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(userid){resetbutton.addEventListener("click",async function(){const data={methodname:"block_townsquare_reset_usersettings",args:{userid:userid}};let result=_ajax.default.call([data]);resetbutton.classList.add("bg-success","text-white","ts_button_transition"),setTimeout(function(){resetbutton.classList.remove("bg-success"),resetbutton.classList.remove("text-white")},1500);const coursecheckboxes=document.querySelectorAll(".ts_course_checkbox"),lettercheckboxes=document.querySelectorAll(".ts_letter_checkbox"),alltimebutton=document.querySelectorAll(".ts_all_time_button");return coursecheckboxes.forEach(function(checkbox){checkbox.checked||checkbox.click()}),alltimebutton.forEach(function(button){button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change"))}),lettercheckboxes.forEach(function(checkbox){checkbox.checked||checkbox.click()}),result})},_ajax=(e=_ajax)&&e.__esModule?e:{default:e};const resetbutton=document.getElementById("ts_usersettings_resetbutton")}); - -//# sourceMappingURL=usersettings_reset.min.js.map \ No newline at end of file diff --git a/amd/build/usersettings_reset.min.js.map b/amd/build/usersettings_reset.min.js.map deleted file mode 100644 index c52da06..0000000 --- a/amd/build/usersettings_reset.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"usersettings_reset.min.js","sources":["../src/usersettings_reset.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 reset the user settings.\n *\n * This file implements 1 functionality:\n * - If the \"reset settings\" button is pressed, reset all settings and delete the users database record.\n *\n * @module block_townsquare/usersettings_reset\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 reset button for the user settings.\nconst resetbutton = document.getElementById('ts_usersettings_resetbutton');\n\n/**\n * Init function. This functions resets the user settings from the database.\n * @param {number} userid The id of the current user.\n */\nexport function init(userid) {\n // First step: delete user settings in database.\n\n // Add event listener to the reset button.\n resetbutton.addEventListener('click', async function() {\n // Set up for AJAX call.\n const data = {\n methodname: 'block_townsquare_reset_usersettings',\n args: {\n userid: userid,\n },\n };\n // Call the AJAX function.\n let result = Ajax.call([data]);\n\n // Make the clicked button green by adding a class and remove it afterward.\n resetbutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n setTimeout(function() {\n resetbutton.classList.remove('bg-success');\n resetbutton.classList.remove('text-white');\n }, 1500);\n\n // Second step: reset all active filters.\n const coursecheckboxes = document.querySelectorAll('.ts_course_checkbox');\n const lettercheckboxes = document.querySelectorAll('.ts_letter_checkbox');\n const alltimebutton = document.querySelectorAll('.ts_all_time_button');\n\n coursecheckboxes.forEach(function(checkbox) {\n if (!checkbox.checked) {\n checkbox.click();\n }\n });\n\n alltimebutton.forEach(function(button) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n });\n\n lettercheckboxes.forEach(function(checkbox) {\n if (!checkbox.checked) {\n checkbox.click();\n }\n });\n return result;\n });\n}\n"],"names":["e","userid","resetbutton","addEventListener","async","data","methodname","args","result","Ajax","default","call","classList","add","setTimeout","remove","coursecheckboxes","document","querySelectorAll","lettercheckboxes","alltimebutton","forEach","checkbox","checked","click","button","parentNode","dispatchEvent","Event","_ajax","__esModule","getElementById"],"mappings":"8FA0B6B,IAAAA;;;;;;;;;;2EAStB,SAAcC,QAIjBC,YAAYC,iBAAiB,QAASC,iBAElC,MAAMC,KAAO,CACTC,WAAY,sCACZC,KAAM,CACFN,OAAQA,SAIhB,IAAIO,OAASC,MAAIC,QAACC,KAAK,CAACN,OAGxBH,YAAYU,UAAUC,IAAI,aAAc,aAAc,wBACtDC,WAAW,WACPZ,YAAYU,UAAUG,OAAO,cAC7Bb,YAAYU,UAAUG,OAAO,aAChC,EAAE,MAGH,MAAMC,iBAAmBC,SAASC,iBAAiB,uBAC7CC,iBAAmBF,SAASC,iBAAiB,uBAC7CE,cAAgBH,SAASC,iBAAiB,uBAmBhD,OAjBAF,iBAAiBK,QAAQ,SAASC,UACzBA,SAASC,SACVD,SAASE,OAEjB,GAEAJ,cAAcC,QAAQ,SAASI,QAC3BA,OAAOF,SAAU,EACjBE,OAAOC,WAAWd,UAAUC,IAAI,UAChCY,OAAOE,cAAc,IAAIC,MAAM,UACnC,GAEAT,iBAAiBE,QAAQ,SAASC,UACzBA,SAASC,SACVD,SAASE,OAEjB,GACOhB,MACX,EACJ,EAvDAqB,OAA6B7B,EAA7B6B,QAA6B7B,EAAA8B,WAAA9B,EAAAU,CAAAA,QAAAV,GAG7B,MAAME,YAAce,SAASc,eAAe,8BAoD3C"} \ No newline at end of file diff --git a/amd/build/usersettings_save.min.js b/amd/build/usersettings_save.min.js deleted file mode 100644 index e0f4e39..0000000 --- a/amd/build/usersettings_save.min.js +++ /dev/null @@ -1,13 +0,0 @@ -define("block_townsquare/usersettings_save",["exports","core/ajax"],function(_exports,_ajax){var e; -/** - * JavaScript to save the user settings in the database. - * - * This file implements 1 functionality: - * - If the "save settings" button is pressed, store the settings in the database. - * - * @module block_townsquare/usersettings_save - * @copyright 2024 Tamaro Walter - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(userid,settingsfromdb){settingsfromdb&&function(settingsfromdb){let futurebuttonid=converttimetoid(settingsfromdb.timefilterfuture,!0),pastbuttonid=converttimetoid(settingsfromdb.timefilterpast,!1);"ts_time_all"!==futurebuttonid?(alltimebutton.forEach(function(alltimebutton){alltimebutton.checked=!1}),futureradiobuttons.forEach(function(button){button.id===futurebuttonid&&(button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change")))}),pastradiobuttons.forEach(function(button){button.id===pastbuttonid&&(button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change")))})):(alltimebutton.forEach(function(button){button.checked=!0,button.parentNode.classList.add("active"),button.dispatchEvent(new Event("change"))}),futureradiobuttons.forEach(function(button){button.checked=!1}),pastradiobuttons.forEach(function(button){button.checked=!1}));letter_checkboxes.forEach(function(checkbox){let basiclettercheck="basicletter"===checkbox.id&&"0"===settingsfromdb.basicletter,completionlettercheck="completionletter"===checkbox.id&&"0"===settingsfromdb.completionletter,postlettercheck="postletter"===checkbox.id&&"0"===settingsfromdb.postletter;(basiclettercheck||completionlettercheck||postlettercheck)&&checkbox.click()});let coursessettings=JSON.parse(settingsfromdb.courses);course_checkboxes.forEach(function(checkbox){let courseid=Number(checkbox.dataset.courseid);coursessettings.hasOwnProperty(courseid)&&!coursessettings[courseid]&&checkbox.checked&&checkbox.click()})}(settingsfromdb);savebutton.addEventListener("click",async function(){let timespans=function(){let settings={timepast:0,timefuture:0},settingsset=!1;if(alltimebutton.forEach(function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timepast=convertidtotime(button.id),settings.timefuture=convertidtotime(button.id),settingsset=!0)}),settingsset)return settings;return futureradiobuttons.forEach(function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timefuture=convertidtotime(button.id))}),pastradiobuttons.forEach(function(button){(button.checked||button.parentNode.classList.contains("active"))&&(settings.timepast=convertidtotime(button.id))}),settings}(),letterfilter=function(){let settings={basicletter:0,completionletter:0,postletter:0};return letter_checkboxes.forEach(function(checkbox){if(checkbox.checked)switch(checkbox.id){case"basicletter":settings.basicletter=1;break;case"completionletter":settings.completionletter=1;break;case"postletter":settings.postletter=1}}),settings}(),courses=function(coursesettingsfromdb){let settings=coursesettingsfromdb?JSON.parse(coursesettingsfromdb):{};return course_checkboxes.forEach(function(checkbox){settings[Number(checkbox.dataset.courseid)]=checkbox.checked}),JSON.stringify(settings)}(settingsfromdb.courses);await function(userid,timefilterpast,timefilterfuture,basicletter,completionletter,postletter,courses){let result;const data={methodname:"block_townsquare_record_usersettings",args:{userid:userid,timefilterpast:timefilterpast,timefilterfuture:timefilterfuture,basicletter:basicletter,completionletter:completionletter,postletter:postletter,courses:courses}};return result=_ajax.default.call([data]),savebutton.classList.add("bg-success","text-white","ts_button_transition"),setTimeout(function(){savebutton.classList.remove("bg-success"),savebutton.classList.remove("text-white")},1500),result}(userid,timespans.timepast,timespans.timefuture,letterfilter.basicletter,letterfilter.completionletter,letterfilter.postletter,courses)})},_ajax=(e=_ajax)&&e.__esModule?e:{default:e};const savebutton=document.getElementById("ts_usersettings_savebutton"),alltimebutton=document.querySelectorAll(".ts_all_time_button"),futureradiobuttons=document.querySelectorAll(".ts_future_time_button"),pastradiobuttons=document.querySelectorAll(".ts_past_time_button"),letter_checkboxes=document.querySelectorAll(".ts_letter_checkbox"),course_checkboxes=document.querySelectorAll(".ts_course_checkbox");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}}function converttimetoid(time,future){switch(time){case"15778463":return"ts_time_all";case"172800":return future?"ts_time_next_twodays":"ts_time_past_twodays";case"432000":return future?"ts_time_next_fivedays":"ts_time_last_fivedays";case"604800":return future?"ts_time_next_week":"ts_time_last_week";case"2592000":return future?"ts_time_next_month":"ts_time_last_month"}}}); - -//# sourceMappingURL=usersettings_save.min.js.map \ No newline at end of file diff --git a/amd/build/usersettings_save.min.js.map b/amd/build/usersettings_save.min.js.map deleted file mode 100644 index 8060dea..0000000 --- a/amd/build/usersettings_save.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 letter_checkboxes = document.querySelectorAll('.ts_letter_checkbox');\n\n// Get the checkboxes from the course filter.\nconst course_checkboxes = document.querySelectorAll('.ts_course_checkbox');\n\n/**\n * Init function. This functions adapts the filter settings to the user settings from the database. If the user changes settings\n * and clicks the save button, the settings are stored in the database.\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 let courses = collectcoursesettings(settingsfromdb.courses);\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'], courses);\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 * @param {string} courses\n * @returns {Promise<*>}\n */\nfunction saveusersettings(userid, timefilterpast, timefilterfuture, basicletter, completionletter, postletter, courses) {\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 courses: courses,\n },\n };\n result = Ajax.call([data]);\n\n // Make the clicked button green by adding a class and remove it afterward.\n savebutton.classList.add('bg-success', 'text-white', 'ts_button_transition');\n setTimeout(function() {\n savebutton.classList.remove('bg-success');\n savebutton.classList.remove('text-white');\n }, 1500);\n\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 alltimebutton.forEach(function(alltimebutton) {\n alltimebutton.checked = false;\n });\n futureradiobuttons.forEach(function(button) {\n if (button.id === futurebuttonid) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n }\n });\n pastradiobuttons.forEach(function(button) {\n if (button.id === pastbuttonid) {\n button.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\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.checked = true;\n button.parentNode.classList.add('active');\n button.dispatchEvent(new Event('change'));\n });\n futureradiobuttons.forEach(function(button) {\n button.checked = false;\n });\n pastradiobuttons.forEach(function(button) {\n button.checked = false;\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 letter_checkboxes.forEach(function(checkbox) {\n let basiclettercheck = checkbox.id === 'basicletter' && settingsfromdb.basicletter === \"0\";\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 // Third step: set the course filter settings.\n let coursessettings = JSON.parse(settingsfromdb.courses);\n\n course_checkboxes.forEach(function(checkbox) {\n let courseid = Number(checkbox.dataset.courseid);\n if (coursessettings.hasOwnProperty(courseid)) {\n // If the setting is false, uncheck the checkbox.\n if (!coursessettings[courseid] && checkbox.checked) {\n checkbox.click();\n }\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 letter_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 }\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 * Collects and updates the course filter settings.\n * Ensures previous settings are retained even if a course does not show notifications temporarily..\n *\n * @param {?string} coursesettingsfromdb\n * @returns {string}\n */\nfunction collectcoursesettings(coursesettingsfromdb) {\n // Check if the course settings have been set in the past.\n let settings = coursesettingsfromdb ? JSON.parse(coursesettingsfromdb) : {};\n\n // Build a JSON in the format courseid => coursename.\n course_checkboxes.forEach(function(checkbox) {\n settings[Number(checkbox.dataset.courseid)] = checkbox.checked;\n });\n\n // Return a string version of the settings.\n return JSON.stringify(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.checked || 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.checked || 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.checked || 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":["e","userid","settingsfromdb","futurebuttonid","converttimetoid","timefilterfuture","pastbuttonid","timefilterpast","alltimebutton","forEach","checked","futureradiobuttons","button","id","parentNode","classList","add","dispatchEvent","Event","pastradiobuttons","letter_checkboxes","checkbox","basiclettercheck","basicletter","completionlettercheck","completionletter","postlettercheck","postletter","click","coursessettings","JSON","parse","courses","course_checkboxes","courseid","Number","dataset","hasOwnProperty","executeusersettings","savebutton","addEventListener","async","timespans","settings","timepast","timefuture","settingsset","contains","convertidtotime","collecttimefiltersettings","letterfilter","collectletterfiltersettings","coursesettingsfromdb","stringify","collectcoursesettings","result","data","methodname","args","Ajax","call","setTimeout","remove","saveusersettings","_ajax","__esModule","default","document","getElementById","querySelectorAll","time","future"],"mappings":"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"} \ No newline at end of file diff --git a/amd/src/usersettings_reset.js b/amd/src/db/usersettings_reset.js similarity index 98% rename from amd/src/usersettings_reset.js rename to amd/src/db/usersettings_reset.js index f6ade39..4d96e95 100644 --- a/amd/src/usersettings_reset.js +++ b/amd/src/db/usersettings_reset.js @@ -19,7 +19,7 @@ * This file implements 1 functionality: * - If the "reset settings" button is pressed, reset all settings and delete the users database record. * - * @module block_townsquare/usersettings_reset + * @module block_townsquare/db/usersettings_reset * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/usersettings_save.js b/amd/src/db/usersettings_save.js similarity index 99% rename from amd/src/usersettings_save.js rename to amd/src/db/usersettings_save.js index 9b39934..e278cb5 100644 --- a/amd/src/usersettings_save.js +++ b/amd/src/db/usersettings_save.js @@ -19,7 +19,7 @@ * This file implements 1 functionality: * - If the "save settings" button is pressed, store the settings in the database. * - * @module block_townsquare/usersettings_save + * @module block_townsquare/db/usersettings_save * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/coursefilter.js b/amd/src/filter/coursefilter.js similarity index 97% rename from amd/src/coursefilter.js rename to amd/src/filter/coursefilter.js index a7c49cb..67885ae 100644 --- a/amd/src/coursefilter.js +++ b/amd/src/filter/coursefilter.js @@ -19,7 +19,7 @@ * This file implements 1 functionality: * - Checks the checkboxes of the course filter and hides content from courses if the checkbox is not checked. * - * @module block_townsquare/coursefilter + * @module block_townsquare/filter/coursefilter * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/filtercontroller.js b/amd/src/filter/filtercontroller.js similarity index 98% rename from amd/src/filtercontroller.js rename to amd/src/filter/filtercontroller.js index ad6a6cd..f3e45a7 100644 --- a/amd/src/filtercontroller.js +++ b/amd/src/filter/filtercontroller.js @@ -16,7 +16,7 @@ /** * JavaScript to show/hide letters based on all filters * - * @module block_townsquare/filtercontroller + * @module block_townsquare/filter/filtercontroller * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/letterfilter.js b/amd/src/filter/letterfilter.js similarity index 97% rename from amd/src/letterfilter.js rename to amd/src/filter/letterfilter.js index d964afa..f3fde78 100644 --- a/amd/src/letterfilter.js +++ b/amd/src/filter/letterfilter.js @@ -16,7 +16,7 @@ /** * JavaScript for the letter filter * - * @module block_townsquare/letterfilter + * @module block_townsquare/filter/letterfilter * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/amd/src/timefilter.js b/amd/src/filter/timefilter.js similarity index 99% rename from amd/src/timefilter.js rename to amd/src/filter/timefilter.js index ec759fe..ca15455 100644 --- a/amd/src/timefilter.js +++ b/amd/src/filter/timefilter.js @@ -19,7 +19,7 @@ * This file implements 1 functionality: * - Checks, which of the radio buttons is pressed and filters the content based on the time. * - * @module block_townsquare/timefilter + * @module block_townsquare/filter/timefilter * @copyright 2024 Tamaro Walter * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/block_townsquare.php b/block_townsquare.php index f3919de..e92a96f 100644 --- a/block_townsquare.php +++ b/block_townsquare.php @@ -52,14 +52,14 @@ public function get_content(): stdClass { $usersettings = $DB->get_record('block_townsquare_preferences', ['userid' => $USER->id]); // Load all javascripts. - $this->page->requires->js_call_amd('block_townsquare/postletter', 'init'); - $this->page->requires->js_call_amd('block_townsquare/coursefilter', 'init'); - $this->page->requires->js_call_amd('block_townsquare/timefilter', 'init'); - $this->page->requires->js_call_amd('block_townsquare/letterfilter', 'init'); - $this->page->requires->js_call_amd('block_townsquare/filtercontroller', 'init'); $this->page->requires->js_call_amd('block_townsquare/lettergroup', 'init'); - $this->page->requires->js_call_amd('block_townsquare/usersettings_save', 'init', [$USER->id, $usersettings]); - $this->page->requires->js_call_amd('block_townsquare/usersettings_reset', 'init', [$USER->id]); + $this->page->requires->js_call_amd('block_townsquare/postletter', 'init'); + $this->page->requires->js_call_amd('block_townsquare/filter/coursefilter', 'init'); + $this->page->requires->js_call_amd('block_townsquare/filter/filtercontroller', 'init'); + $this->page->requires->js_call_amd('block_townsquare/filter/letterfilter', 'init'); + $this->page->requires->js_call_amd('block_townsquare/filter/timefilter', 'init'); + $this->page->requires->js_call_amd('block_townsquare/db/usersettings_reset', 'init', [$USER->id]); + $this->page->requires->js_call_amd('block_townsquare/db/usersettings_save', 'init', [$USER->id, $usersettings]); return $this->content; }