Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"selectedcourses.min.js","sources":["../src/selectedcourses.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 * Selected courses.\n *\n * @module     tool_dataprivacy/selectedcourses\n * @copyright  2021 The Open University\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      Moodle 4.3\n */\n\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\nimport ModalSaveCancel from 'core/modal_save_cancel';\nimport ModalEvents from 'core/modal_events';\nimport Fragment from 'core/fragment';\nimport {prefetchStrings} from 'core/prefetch';\nimport {getString} from 'core/str';\n\nprefetchStrings('tool_dataprivacy', [\n    'selectcourses',\n    'approverequest',\n    'errornoselectedcourse',\n]);\n\n/**\n * Selected Courses popup modal.\n *\n */\nexport default class SelectedCourses {\n    /**\n     * @var {String} contextId Context ID to load the fragment.\n     * @private\n     */\n    contextId = 0;\n\n    /**\n     * @var {String} requestId ID of data export request.\n     * @private\n     */\n    requestId = 0;\n\n    /**\n     * Constructor\n     *\n     * @param {String} contextId Context ID to load the fragment.\n     * @param {String} requestId ID of data export request.\n     */\n    constructor(contextId, requestId) {\n        this.contextId = contextId;\n        this.requestId = requestId;\n        // Now create the modal.\n        ModalSaveCancel.create({\n            title: getString('selectcourses', 'tool_dataprivacy'),\n            body: this.getBody({requestid: requestId}),\n            large: true,\n            removeOnClose: true,\n            buttons: {\n                save: getString('approverequest', 'tool_dataprivacy'),\n            },\n        }).then((modal) => {\n            this.modal = modal;\n\n            return modal;\n        }).then((modal) => {\n            // We catch the modal save event, and use it to submit the form inside the modal.\n            // Triggering a form submission will give JS validation scripts a chance to check for errors.\n            modal.getRoot().on(ModalEvents.save, this.submitForm.bind(this));\n\n            // We also catch the form submit event and use it to submit the form with ajax.\n            modal.getRoot().on('submit', 'form', this.submitFormAjax.bind(this));\n            modal.show();\n            return modal;\n        }).catch(Notification.exception);\n    }\n\n    /**\n     * Get body of modal.\n     *\n     * @method getBody\n     * @param {Object} formdata\n     * @private\n     * @return {Promise}\n     */\n    getBody(formdata) {\n        const params = formdata ? {jsonformdata: JSON.stringify(formdata)} : null;\n\n        // Get the content of the modal.\n        return Fragment.loadFragment('tool_dataprivacy', 'selectcourses_form', this.contextId, params);\n    }\n\n    /**\n     * This triggers a form submission, so that any mform elements can do final tricks before the form submission is processed.\n     *\n     * @method submitForm\n     * @param {Event} e Form submission event.\n     * @private\n     */\n    submitForm(e) {\n        e.preventDefault();\n        this.modal.getRoot().find('form').submit();\n    }\n\n    /**\n     * Submit select courses form using ajax.\n     *\n     * @method submitFormAjax\n     * @private\n     * @param {Event} e Form submission event.\n     */\n    submitFormAjax(e) {\n        e.preventDefault();\n\n        // Convert all the form elements values to a serialised string.\n        let formData = this.modal.getRoot().find('form').serialize();\n\n        if (formData.indexOf('coursecontextids') === -1) {\n            const customSelect = this.modal.getRoot().find('.custom-select');\n            const invalidText = this.modal.getRoot().find('.invalid-feedback');\n            customSelect.addClass('is-invalid');\n            invalidText.attr('style', 'display: block');\n            getString('errornoselectedcourse', 'tool_dataprivacy').then(value => {\n                invalidText.empty().append(value);\n                return;\n            }).catch(Notification.exception);\n            return;\n        }\n\n        Ajax.call([{\n            methodname: 'tool_dataprivacy_submit_selected_courses_form',\n            args: {requestid: this.requestId, jsonformdata: JSON.stringify(formData)},\n        }])[0]\n        .then((data) => {\n            if (data.warnings.length > 0) {\n                this.modal.setBody(this.getBody(formData));\n            } else {\n                this.modal.destroy();\n                document.location.reload();\n            }\n            return data;\n        })\n        .catch((error) => Notification.exception(error));\n    }\n}\n"],"names":["constructor","contextId","requestId","create","title","body","this","getBody","requestid","large","removeOnClose","buttons","save","then","modal","getRoot","on","ModalEvents","submitForm","bind","submitFormAjax","show","catch","Notification","exception","formdata","params","jsonformdata","JSON","stringify","Fragment","loadFragment","e","preventDefault","find","submit","formData","serialize","indexOf","customSelect","invalidText","addClass","attr","value","empty","append","call","methodname","args","data","warnings","length","setBody","destroy","document","location","reload","error"],"mappings":"02BAgCgB,mBAAoB,CAChC,gBACA,iBACA,wDA0BAA,YAAYC,UAAWC,4CAdX,oCAMA,QASHD,UAAYA,eACZC,UAAYA,qCAEDC,OAAO,CACnBC,OAAO,kBAAU,gBAAiB,oBAClCC,KAAMC,KAAKC,QAAQ,CAACC,UAAWN,YAC/BO,OAAO,EACPC,eAAe,EACfC,QAAS,CACLC,MAAM,kBAAU,iBAAkB,uBAEvCC,MAAMC,aACAA,MAAQA,MAENA,SACRD,MAAMC,QAGLA,MAAMC,UAAUC,GAAGC,sBAAYL,KAAMN,KAAKY,WAAWC,KAAKb,OAG1DQ,MAAMC,UAAUC,GAAG,SAAU,OAAQV,KAAKc,eAAeD,KAAKb,OAC9DQ,MAAMO,OACCP,SACRQ,MAAMC,sBAAaC,WAW1BjB,QAAQkB,gBACEC,OAASD,SAAW,CAACE,aAAcC,KAAKC,UAAUJ,WAAa,YAG9DK,kBAASC,aAAa,mBAAoB,qBAAsBzB,KAAKL,UAAWyB,QAU3FR,WAAWc,GACPA,EAAEC,sBACGnB,MAAMC,UAAUmB,KAAK,QAAQC,SAUtCf,eAAeY,GACXA,EAAEC,qBAGEG,SAAW9B,KAAKQ,MAAMC,UAAUmB,KAAK,QAAQG,gBAEH,IAA1CD,SAASE,QAAQ,oBAA4B,OACvCC,aAAejC,KAAKQ,MAAMC,UAAUmB,KAAK,kBACzCM,YAAclC,KAAKQ,MAAMC,UAAUmB,KAAK,4BAC9CK,aAAaE,SAAS,cACtBD,YAAYE,KAAK,QAAS,yCAChB,wBAAyB,oBAAoB7B,MAAK8B,QACxDH,YAAYI,QAAQC,OAAOF,UAE5BrB,MAAMC,sBAAaC,yBAIrBsB,KAAK,CAAC,CACPC,WAAY,gDACZC,KAAM,CAACxC,UAAWF,KAAKJ,UAAWyB,aAAcC,KAAKC,UAAUO,cAC/D,GACHvB,MAAMoC,OACCA,KAAKC,SAASC,OAAS,OAClBrC,MAAMsC,QAAQ9C,KAAKC,QAAQ6B,iBAE3BtB,MAAMuC,UACXC,SAASC,SAASC,UAEfP,QAEV3B,OAAOmC,OAAUlC,sBAAaC,UAAUiC"}