Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"move.min.js","sources":["../../../../src/bulkactions/edit/tree/move.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 * Class that defines the bulk move action in the gradebook setup page.\n *\n * @module     core_grades/bulkactions/edit/tree/move\n * @copyright  2023 Mihail Geshoski <mihail@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport BulkAction from 'core/bulkactions/bulk_action';\nimport {get_string as getString} from 'core/str';\nimport ModalSaveCancel from 'core/modal_save_cancel';\nimport Templates from 'core/templates';\nimport Ajax from 'core/ajax';\nimport ModalEvents from 'core/modal_events';\nimport MoveOptionsTree from 'core_grades/bulkactions/edit/tree/move_options_tree';\n\n/** @constant {Object} The object containing the relevant selectors. */\nconst Selectors = {\n    editTreeForm: '#gradetreeform',\n    bulkMoveInput: 'input[name=\"bulkmove\"]',\n    bulkMoveAfterInput: 'input[name=\"moveafter\"]'\n};\n\nexport default class GradebookEditTreeBulkMove extends BulkAction {\n\n    /** @property {int|null} courseId The course ID. */\n    courseId = null;\n\n    /** @property {MoveOptionsTree|null} moveOptionsTree The move options tree object. */\n    moveOptionsTree = null;\n\n    /** @property {string|null} gradeTree The grade tree structure. */\n    gradeTree = null;\n\n    /**\n     * The class constructor.\n     *\n     * @param {int} courseId The course ID.\n     * @returns {void}\n     */\n    constructor(courseId) {\n        super();\n        this.courseId = courseId;\n    }\n\n    /**\n     * Defines the selector of the element that triggers the bulk move action.\n     *\n     * @returns {string} The bulk move action trigger selector.\n     */\n    getBulkActionTriggerSelector() {\n        return 'button[data-action=\"move\"]';\n    }\n\n    /**\n     * Defines the behavior once the bulk move action is triggered.\n     *\n     * @method executeBulkAction\n     * @returns {void}\n     */\n    async triggerBulkAction() {\n        const modal = await this.showModal();\n        this.registerCustomListenerEvents(modal);\n    }\n\n    /**\n     * Renders the bulk move action trigger element.\n     *\n     * @method renderBulkActionTrigger\n     * @returns {Promise} The bulk move action trigger promise\n     */\n    async renderBulkActionTrigger() {\n        return Templates.render('core_grades/bulkactions/edit/tree/bulk_move_trigger', {});\n    }\n\n    /**\n     * Register custom event listeners.\n     *\n     * @method registerCustomClickListenerEvents\n     * @param {Object} modal The modal object.\n     * @returns {void}\n     */\n    async registerCustomListenerEvents(modal) {\n        await modal.getBody();\n        // Initialize the move options tree once the modal is shown.\n        modal.getRoot().on(ModalEvents.shown, () => {\n            this.moveOptionsTree = new MoveOptionsTree(() => {\n                // Enable the 'Move' action button once something is selected.\n                modal.setButtonDisabled('save', false);\n            });\n        });\n        // Destroy the modal once it is hidden.\n        modal.getRoot().on(ModalEvents.hidden, () => {\n            modal.destroy();\n        });\n        // Define the move action event.\n        modal.getRoot().on(ModalEvents.save, () => {\n            // Make sure that a move option is selected.\n            if (this.moveOptionsTree && this.moveOptionsTree.selectedMoveOption) {\n                // Set the relevant form values.\n                document.querySelector(Selectors.bulkMoveInput).value = 1;\n                document.querySelector(Selectors.bulkMoveAfterInput).value = this.moveOptionsTree.selectedMoveOption.dataset.id;\n                // Submit the form.\n                document.querySelector(Selectors.editTreeForm).submit();\n            }\n        });\n    }\n\n    /**\n     * Fetch the grade tree structure for the current course.\n     *\n     * @method fetchGradeTree\n     * @returns {Promise} The grade tree promise\n     */\n    fetchGradeTree() {\n        const request = {\n            methodname: 'core_grades_get_grade_tree',\n            args: {\n                courseid: this.courseId,\n            },\n        };\n        return Ajax.call([request])[0];\n    }\n\n    /**\n     * Renders the bulk move modal body.\n     *\n     * @method renderModalBody\n     * @returns {Promise} The modal body promise\n     */\n    async renderModalBody() {\n        // We need to fetch the grade tree structure only once.\n        if (this.gradeTree === null) {\n            this.gradeTree = await this.fetchGradeTree();\n        }\n\n        return Templates.render('core_grades/bulkactions/edit/tree/bulk_move_grade_tree',\n            JSON.parse(this.gradeTree));\n    }\n\n    /**\n     * Show the bulk move modal.\n     *\n     * @method showModal\n     * @returns {Promise} The modal promise\n     */\n     async showModal() {\n        const modal = await ModalSaveCancel.create({\n            title: await getString('movesitems', 'grades'),\n            body: await this.renderModalBody(),\n            buttons: {\n                save: await getString('move')\n            },\n            large: true,\n        });\n        // Disable the 'Move' action button until something is selected.\n        modal.setButtonDisabled('save', true);\n        modal.show();\n\n        return modal;\n    }\n}\n"],"names":["Selectors","GradebookEditTreeBulkMove","BulkAction","constructor","courseId","getBulkActionTriggerSelector","modal","this","showModal","registerCustomListenerEvents","Templates","render","getBody","getRoot","on","ModalEvents","shown","moveOptionsTree","MoveOptionsTree","setButtonDisabled","hidden","destroy","save","selectedMoveOption","document","querySelector","value","dataset","id","submit","fetchGradeTree","request","methodname","args","courseid","Ajax","call","gradeTree","JSON","parse","ModalSaveCancel","create","title","body","renderModalBody","buttons","large","show"],"mappings":"i9BAgCMA,uBACY,iBADZA,wBAEa,yBAFbA,6BAGkB,gCAGHC,kCAAkCC,qBAiBnDC,YAAYC,kDAdD,6CAGO,uCAGN,WAUHA,SAAWA,SAQpBC,qCACW,6DAUDC,YAAcC,KAAKC,iBACpBC,6BAA6BH,8CAU3BI,mBAAUC,OAAO,sDAAuD,uCAUhDL,aACzBA,MAAMM,UAEZN,MAAMO,UAAUC,GAAGC,sBAAYC,OAAO,UAC7BC,gBAAkB,IAAIC,4BAAgB,KAEvCZ,MAAMa,kBAAkB,QAAQ,SAIxCb,MAAMO,UAAUC,GAAGC,sBAAYK,QAAQ,KACnCd,MAAMe,aAGVf,MAAMO,UAAUC,GAAGC,sBAAYO,MAAM,KAE7Bf,KAAKU,iBAAmBV,KAAKU,gBAAgBM,qBAE7CC,SAASC,cAAczB,yBAAyB0B,MAAQ,EACxDF,SAASC,cAAczB,8BAA8B0B,MAAQnB,KAAKU,gBAAgBM,mBAAmBI,QAAQC,GAE7GJ,SAASC,cAAczB,wBAAwB6B,aAW3DC,uBACUC,QAAU,CACZC,WAAY,6BACZC,KAAM,CACFC,SAAU3B,KAAKH,kBAGhB+B,cAAKC,KAAK,CAACL,UAAU,kCAWL,OAAnBxB,KAAK8B,iBACAA,gBAAkB9B,KAAKuB,kBAGzBpB,mBAAUC,OAAO,yDACpB2B,KAAKC,MAAMhC,KAAK8B,oCAUd/B,YAAckC,2BAAgBC,OAAO,CACvCC,YAAa,mBAAU,aAAc,UACrCC,WAAYpC,KAAKqC,kBACjBC,QAAS,CACLvB,WAAY,mBAAU,SAE1BwB,OAAO,WAGXxC,MAAMa,kBAAkB,QAAQ,GAChCb,MAAMyC,OAECzC"}