// This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . /** * @module mod_meetletacbfree/featureaccess_matrix * @copyright 2026 MeetLet * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define([], function() { const bindMatrix = (matrix) => { if (!matrix || matrix.getAttribute('data-access-bound') === '1') { return; } matrix.setAttribute('data-access-bound', '1'); const setGroup = (checks, forceOn) => { const list = Array.from(checks).filter((el) => !el.disabled); if (!list.length) { return; } const turnOn = (typeof forceOn === 'boolean') ? forceOn : list.some((el) => !el.checked); list.forEach((el) => { if (el.checked !== turnOn) { el.checked = turnOn; el.dispatchEvent(new Event('change', {bubbles: true})); } }); }; matrix.addEventListener('click', (e) => { const btn = e.target.closest('[data-access-toggle]'); if (!btn || !matrix.contains(btn) || matrix.classList.contains('is-disabled')) { return; } e.preventDefault(); const mode = btn.getAttribute('data-access-toggle'); if (mode === 'row') { const role = btn.getAttribute('data-role'); setGroup(matrix.querySelectorAll('.meetlet-access-check[data-role="' + role + '"]')); } else if (mode === 'col') { const feature = btn.getAttribute('data-feature'); setGroup(matrix.querySelectorAll('.meetlet-access-check[data-feature="' + feature + '"]')); } }); }; const init = () => { document.querySelectorAll('[data-meetlet-access-matrix]').forEach(bindMatrix); }; return {init: init}; });