Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"coursecategory.min.js","sources":["../src/coursecategory.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Select course categories for LTI tool.\n *\n * @module     mod_lti/coursecategory\n * @copyright  2023 Jackson D'souza <jackson.dsouza@catalyst-eu.net>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      4.3\n */\n\ndefine([], function() {\n\n    document.addEventListener('click', event => {\n        const checkedbox = event.target.closest(\".lticoursecategories\");\n\n        if (checkedbox) {\n            // Get checkbox status.\n            const checkboxstatus = checkedbox.checked;\n\n            // Check / Uncheck all child category checkboxes based on selected checkbox status.\n            const categorycontainer = document.querySelector('#collapse' + checkedbox.value);\n            if (categorycontainer) {\n                const categorycontainercheckbox = categorycontainer.querySelectorAll('input[type=\"checkbox\"]');\n                for (let i = 0; i < categorycontainercheckbox.length; i++) {\n                    categorycontainercheckbox[i].checked = checkboxstatus;\n                }\n            }\n\n            const lticategorytree = document.querySelector('.modltitree');\n            const ltitreecheckbox = lticategorytree.querySelectorAll('input[type=\"checkbox\"]');\n            let listvalue = '';\n            for (let i = 0; i < ltitreecheckbox.length; i++) {\n                if (ltitreecheckbox[i].checked) {\n                    if (listvalue.length == 0) {\n                        listvalue = ltitreecheckbox[i].value;\n                    } else {\n                        listvalue = listvalue + ',' + ltitreecheckbox[i].value;\n                    }\n                }\n            }\n            document.querySelector('input[name=\"lti_coursecategories\"]').value = listvalue;\n        }\n    });\n\n    /**\n     * Get parent elements with class = accordion.\n     *\n     * @method getParents\n     * @private\n     * @param {string} elem DOM element.\n     * @return {array} Parent elements.\n     */\n    function getParents(elem) {\n        // Set up a parent array\n        const parents = [];\n\n        // Push each parent element to the array\n        for (; elem && elem !== document; elem = elem.parentNode) {\n            if (elem.classList.contains('accordion-group')) {\n                parents.push(elem);\n            }\n        }\n\n        // Return our parent array\n        return parents;\n    }\n\n    return /** @alias module:mod_lti/coursecategory */ {\n\n        /**\n         * Initialise this module.\n         * Loop through checkbox form elements starting with #cat-{N} and set it to checked\n         * if {N} is found in the Selected category(s) list. Show / Hide the parent UL element.\n         *\n         * @param {string} selectedcategories Selected category(s).\n         */\n        init: function(selectedcategories) {\n            if (selectedcategories.length) {\n                const separator = \",\";\n                const values = selectedcategories.split(separator);\n\n                for (let i = 0; i < values.length; i++) {\n                    const categoryid = document.getElementById(\"cat-\" + values[i]);\n                    if (categoryid.value !== 0) {\n                        categoryid.checked = true;\n                    }\n                    const parents = getParents(categoryid);\n                    parents.forEach(function(element) {\n                        const elem = element.querySelector('a.accordion-toggle');\n                        const elembody = element.querySelector('.accordion-body');\n\n                        if (elem && elem.classList.contains('collapsed')) {\n                            elem.classList.remove('collapsed');\n                        }\n                        if (elembody) {\n                            elembody.classList.remove('collapse');\n                            elembody.classList.add('show');\n                        }\n                    });\n                }\n            }\n        }\n    };\n});"],"names":["define","getParents","elem","parents","document","parentNode","classList","contains","push","addEventListener","event","checkedbox","target","closest","checkboxstatus","checked","categorycontainer","querySelector","value","categorycontainercheckbox","querySelectorAll","i","length","ltitreecheckbox","listvalue","init","selectedcategories","separator","values","split","categoryid","getElementById","forEach","element","elembody","remove","add"],"mappings":";;;;;;;;AAwBAA,gCAAO,IAAI,oBA0CEC,WAAWC,YAEVC,QAAU,QAGTD,MAAQA,OAASE,SAAUF,KAAOA,KAAKG,WACtCH,KAAKI,UAAUC,SAAS,oBACxBJ,QAAQK,KAAKN,aAKdC,eApDXC,SAASK,iBAAiB,SAASC,cACzBC,WAAaD,MAAME,OAAOC,QAAQ,2BAEpCF,WAAY,OAENG,eAAiBH,WAAWI,QAG5BC,kBAAoBZ,SAASa,cAAc,YAAcN,WAAWO,UACtEF,kBAAmB,OACbG,0BAA4BH,kBAAkBI,iBAAiB,8BAChE,IAAIC,EAAI,EAAGA,EAAIF,0BAA0BG,OAAQD,IAClDF,0BAA0BE,GAAGN,QAAUD,qBAKzCS,gBADkBnB,SAASa,cAAc,eACPG,iBAAiB,8BACrDI,UAAY,OACX,IAAIH,EAAI,EAAGA,EAAIE,gBAAgBD,OAAQD,IACpCE,gBAAgBF,GAAGN,UAEfS,UADoB,GAApBA,UAAUF,OACEC,gBAAgBF,GAAGH,MAEnBM,UAAY,IAAMD,gBAAgBF,GAAGH,OAI7Dd,SAASa,cAAc,sCAAsCC,MAAQM,cA2B1B,CAS/CC,KAAM,SAASC,uBACPA,mBAAmBJ,OAAQ,OACrBK,UAAY,IACZC,OAASF,mBAAmBG,MAAMF,eAEnC,IAAIN,EAAI,EAAGA,EAAIO,OAAON,OAAQD,IAAK,OAC9BS,WAAa1B,SAAS2B,eAAe,OAASH,OAAOP,IAClC,IAArBS,WAAWZ,QACXY,WAAWf,SAAU,GAETd,WAAW6B,YACnBE,SAAQ,SAASC,eACf/B,KAAO+B,QAAQhB,cAAc,sBAC7BiB,SAAWD,QAAQhB,cAAc,mBAEnCf,MAAQA,KAAKI,UAAUC,SAAS,cAChCL,KAAKI,UAAU6B,OAAO,aAEtBD,WACAA,SAAS5B,UAAU6B,OAAO,YAC1BD,SAAS5B,UAAU8B,IAAI"}