Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"templateactions.min.js","sources":["../src/templateactions.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 * Handle actions on learning plan templates via ajax.\n *\n * @module     tool_lp/templateactions\n * @copyright  2015 Damyon Wiese <damyon@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/ajax', 'core/notification', 'core/str', 'tool_lp/actionselector'],\n       function($, templates, ajax, notification, str, Actionselector) {\n    // Private variables and functions.\n\n    /** @var {Number} pagecontextid The id of the context */\n    var pagecontextid = 0;\n\n    /** @var {Number} templateid The id of the template */\n    var templateid = 0;\n\n    /** @var {Boolean} Action to apply to plans when deleting a template */\n    var deleteplans = true;\n\n    /**\n     * Callback to replace the dom element with the rendered template.\n     *\n     * @method updatePage\n     * @param {String} newhtml The new html to insert.\n     * @param {String} newjs The new js to run.\n     */\n    var updatePage = function(newhtml, newjs) {\n        $('[data-region=\"managetemplates\"]').replaceWith(newhtml);\n        templates.runTemplateJS(newjs);\n    };\n\n    /**\n     * Callback to render the page template again and update the page.\n     *\n     * @method reloadList\n     * @param {Object} context The context for the template.\n     */\n    var reloadList = function(context) {\n        templates.render('tool_lp/manage_templates_page', context)\n            .done(updatePage)\n            .fail(notification.exception);\n    };\n\n    /**\n     * Delete a template and reload the page.\n     * @method doDelete\n     */\n    var doDelete = function() {\n\n        // We are chaining ajax requests here.\n        var requests = ajax.call([{\n            methodname: 'core_competency_delete_template',\n            args: {id: templateid,\n                    deleteplans: deleteplans}\n        }, {\n            methodname: 'tool_lp_data_for_templates_manage_page',\n            args: {\n                pagecontext: {\n                    contextid: pagecontextid\n                }\n            }\n        }]);\n        requests[1].done(reloadList).fail(notification.exception);\n    };\n\n    /**\n     * Duplicate a template and reload the page.\n     * @method doDuplicate\n     * @param {Event} e\n     */\n    var doDuplicate = function(e) {\n        e.preventDefault();\n\n        templateid = $(this).attr('data-templateid');\n\n        // We are chaining ajax requests here.\n        var requests = ajax.call([{\n            methodname: 'core_competency_duplicate_template',\n            args: {id: templateid}\n        }, {\n            methodname: 'tool_lp_data_for_templates_manage_page',\n            args: {\n                pagecontext: {\n                    contextid: pagecontextid\n                }\n            }\n        }]);\n        requests[1].done(reloadList).fail(notification.exception);\n    };\n\n    /**\n     * Handler for \"Delete learning plan template\" actions.\n     * @method confirmDelete\n     * @param {Event} e\n     */\n    var confirmDelete = function(e) {\n        e.preventDefault();\n\n        var id = $(this).attr('data-templateid');\n        templateid = id;\n        deleteplans = true;\n\n        var requests = ajax.call([{\n            methodname: 'core_competency_read_template',\n            args: {id: templateid}\n        }, {\n            methodname: 'core_competency_template_has_related_data',\n            args: {id: templateid}\n        }]);\n\n        requests[0].done(function(template) {\n            requests[1].done(function(templatehasrelateddata) {\n                if (templatehasrelateddata) {\n                    str.get_strings([\n                        {key: 'deletetemplate', component: 'tool_lp', param: template.shortname},\n                        {key: 'deletetemplatewithplans', component: 'tool_lp'},\n                        {key: 'deleteplans', component: 'tool_lp'},\n                        {key: 'unlinkplanstemplate', component: 'tool_lp'},\n                        {key: 'confirm', component: 'moodle'},\n                        {key: 'cancel', component: 'moodle'}\n                    ]).done(function(strings) {\n                        var actions = [{'text': strings[2], 'value': 'delete'},\n                                       {'text': strings[3], 'value': 'unlink'}];\n                        var actionselector = new Actionselector(\n                                strings[0], // Title.\n                                strings[1], // Message\n                                actions, // Radio button options.\n                                strings[4], // Confirm.\n                                strings[5]); // Cancel.\n                        actionselector.display();\n                        actionselector.on('save', function(e, data) {\n                            if (data.action != 'delete') {\n                                deleteplans = false;\n                            }\n                            doDelete();\n                        });\n                    }).fail(notification.exception);\n                } else {\n                    str.get_strings([\n                        {key: 'confirm', component: 'moodle'},\n                        {key: 'deletetemplate', component: 'tool_lp', param: template.shortname},\n                        {key: 'delete', component: 'moodle'},\n                        {key: 'cancel', component: 'moodle'}\n                    ]).done(function(strings) {\n                        notification.confirm(\n                        strings[0], // Confirm.\n                        strings[1], // Delete learning plan template X?\n                        strings[2], // Delete.\n                        strings[3], // Cancel.\n                        doDelete\n                        );\n                    }).fail(notification.exception);\n                }\n            }).fail(notification.exception);\n        }).fail(notification.exception);\n\n    };\n\n    return /** @alias module:tool_lp/templateactions */ {\n        // Public variables and functions.\n        /**\n         * Expose the event handler for the delete.\n         * @method deleteHandler\n         * @param {Event} e\n         */\n        deleteHandler: confirmDelete,\n\n        /**\n         * Expose the event handler for the duplicate.\n         * @method duplicateHandler\n         * @param {Event} e\n         */\n        duplicateHandler: doDuplicate,\n\n        /**\n         * Initialise the module.\n         * @method init\n         * @param {Number} contextid The context id of the page.\n         */\n        init: function(contextid) {\n            pagecontextid = contextid;\n        }\n    };\n});\n"],"names":["define","$","templates","ajax","notification","str","Actionselector","pagecontextid","templateid","deleteplans","updatePage","newhtml","newjs","replaceWith","runTemplateJS","reloadList","context","render","done","fail","exception","doDelete","call","methodname","args","id","pagecontext","contextid","deleteHandler","e","preventDefault","this","attr","requests","template","templatehasrelateddata","get_strings","key","component","param","shortname","strings","actions","actionselector","display","on","data","action","confirm","duplicateHandler","init"],"mappings":";;;;;;;AAsBAA,iCAAO,CAAC,SAAU,iBAAkB,YAAa,oBAAqB,WAAY,2BAC3E,SAASC,EAAGC,UAAWC,KAAMC,aAAcC,IAAKC,oBAI/CC,cAAgB,EAGhBC,WAAa,EAGbC,aAAc,EASdC,WAAa,SAASC,QAASC,OAC/BX,EAAE,mCAAmCY,YAAYF,SACjDT,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