Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"refresh_ui.min.js","sources":["../src/refresh_ui.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 * Question bank UI refresh utility\n *\n * @module    core_question/refresh_ui\n * @copyright 2023 Catalyst IT Europe Ltd.\n * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Fragment from 'core/fragment';\nimport Templates from 'core/templates';\n\nexport default {\n    /**\n     * Reload the question bank UI, retaining the current filters and sort data.\n     *\n     * @param {Element} uiRoot The root element of the UI to be refreshed. Must contain \"component\", \"callback\" and \"contextid\" in\n     *     its data attributes, to be passed to the Fragment API.\n     * @param {URL} returnUrl The url of the current page, containing filter and sort parameters.\n     * @return {Promise} Resolved when the refresh is complete.\n     */\n    refresh: (uiRoot, returnUrl) => {\n        return new Promise((resolve, reject) => {\n            const fragmentData = uiRoot.dataset;\n            const viewData = {};\n            const sortData = {};\n            if (returnUrl) {\n                returnUrl.searchParams.forEach((value, key) => {\n                    // Match keys like 'sortdata[fieldname]' and convert them to an array,\n                    // because the fragment API doesn't like non-alphanum argument keys.\n                    const sortItem = key.match(/sortdata\\[([^\\]]+)\\]/);\n                    if (sortItem) {\n                        // The item returned by sortItem.pop() is the contents of the matching group, the field name.\n                        sortData[sortItem.pop()] = value;\n                    } else {\n                        viewData[key] = value;\n                    }\n                });\n            }\n            viewData.sortdata = JSON.stringify(sortData);\n            // We have to use then() there, as loadFragment doesn't appear to work with await.\n            Fragment.loadFragment(fragmentData.component, fragmentData.callback, fragmentData.contextid, viewData)\n                .then((html, js) => {\n                    Templates.replaceNode(uiRoot, html, js);\n                    resolve();\n                    return html;\n                })\n                .catch(reject);\n        });\n    }\n};\n"],"names":["refresh","uiRoot","returnUrl","Promise","resolve","reject","fragmentData","dataset","viewData","sortData","searchParams","forEach","value","key","sortItem","match","pop","sortdata","JSON","stringify","loadFragment","component","callback","contextid","then","html","js","replaceNode","catch"],"mappings":";;;;;;;4LA0Be,CASXA,QAAS,CAACC,OAAQC,YACP,IAAIC,SAAQ,CAACC,QAASC,gBACnBC,aAAeL,OAAOM,QACtBC,SAAW,GACXC,SAAW,GACbP,WACAA,UAAUQ,aAAaC,SAAQ,CAACC,MAAOC,aAG7BC,SAAWD,IAAIE,MAAM,wBACvBD,SAEAL,SAASK,SAASE,OAASJ,MAE3BJ,SAASK,KAAOD,SAI5BJ,SAASS,SAAWC,KAAKC,UAAUV,4BAE1BW,aAAad,aAAae,UAAWf,aAAagB,SAAUhB,aAAaiB,UAAWf,UACxFgB,MAAK,CAACC,KAAMC,yBACCC,YAAY1B,OAAQwB,KAAMC,IACpCtB,UACOqB,QAEVG,MAAMvB"}