Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"frameworkactions.min.js","sources":["../src/frameworkactions.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 * Competency frameworks actions via ajax.\n *\n * @module     tool_lp/frameworkactions\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'], function($, templates, ajax, notification, str) {\n    // Private variables and functions.\n\n    /** @var {Number} pagecontextid The id of the context */\n    var pagecontextid = 0;\n\n    /** @var {Number} frameworkid The id of the framework */\n    var frameworkid = 0;\n\n    /**\n     * Callback to replace the dom element with the rendered template.\n     *\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=\"managecompetencies\"]').replaceWith(newhtml);\n        templates.runTemplateJS(newjs);\n    };\n\n    /**\n     * Callback to render the page template again and update the page.\n     *\n     * @param {Object} context The context for the template.\n     */\n    var reloadList = function(context) {\n        templates.render('tool_lp/manage_competency_frameworks_page', context)\n            .done(updatePage)\n            .fail(notification.exception);\n    };\n\n    /**\n     * Duplicate a framework and reload the page.\n     * @method doDuplicate\n     * @param {Event} e\n     */\n    var doDuplicate = function(e) {\n        e.preventDefault();\n\n        frameworkid = $(this).attr('data-frameworkid');\n\n        // We are chaining ajax requests here.\n        var requests = ajax.call([{\n            methodname: 'core_competency_duplicate_competency_framework',\n            args: {id: frameworkid}\n        }, {\n            methodname: 'tool_lp_data_for_competency_frameworks_manage_page',\n            args: {\n                pagecontext: {\n                    contextid: pagecontextid\n                }\n            }\n        }]);\n        requests[1].done(reloadList).fail(notification.exception);\n    };\n    /**\n     * Delete a framework and reload the page.\n     */\n    var doDelete = function() {\n\n        // We are chaining ajax requests here.\n        var requests = ajax.call([{\n            methodname: 'core_competency_delete_competency_framework',\n            args: {id: frameworkid}\n        }, {\n            methodname: 'tool_lp_data_for_competency_frameworks_manage_page',\n            args: {\n                pagecontext: {\n                    contextid: pagecontextid\n                }\n            }\n        }]);\n        requests[0].done(function(success) {\n            if (success === false) {\n                var req = ajax.call([{\n                    methodname: 'core_competency_read_competency_framework',\n                    args: {id: frameworkid}\n                }]);\n                req[0].done(function(framework) {\n                    str.get_strings([\n                        {key: 'frameworkcannotbedeleted', component: 'tool_lp', param: framework.shortname},\n                        {key: 'cancel', component: 'moodle'}\n                    ]).done(function(strings) {\n                        notification.alert(\n                            null,\n                            strings[0]\n                        );\n                    }).fail(notification.exception);\n                });\n            }\n        }).fail(notification.exception);\n        requests[1].done(reloadList).fail(notification.exception);\n    };\n\n    /**\n     * Handler for \"Delete competency framework\" actions.\n     * @param {Event} e\n     */\n    var confirmDelete = function(e) {\n        e.preventDefault();\n\n        var id = $(this).attr('data-frameworkid');\n        frameworkid = id;\n\n        var requests = ajax.call([{\n            methodname: 'core_competency_read_competency_framework',\n            args: {id: frameworkid}\n        }]);\n\n        requests[0].done(function(framework) {\n            str.get_strings([\n                {key: 'confirm', component: 'moodle'},\n                {key: 'deletecompetencyframework', component: 'tool_lp', param: framework.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 competency framework X?\n                    strings[2], // Delete.\n                    strings[3], // Cancel.\n                    doDelete\n                );\n            }).fail(notification.exception);\n        }).fail(notification.exception);\n\n    };\n\n\n    return /** @alias module:tool_lp/frameworkactions */ {\n        // Public variables and functions.\n\n        /**\n         * Expose the event handler for delete.\n         * @method deleteHandler\n         * @param {Event} e\n         */\n        deleteHandler: confirmDelete,\n\n        /**\n         * Expose the event handler for 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","pagecontextid","frameworkid","updatePage","newhtml","newjs","replaceWith","runTemplateJS","reloadList","context","render","done","fail","exception","doDelete","requests","call","methodname","args","id","pagecontext","contextid","success","framework","get_strings","key","component","param","shortname","strings","alert","deleteHandler","e","preventDefault","this","attr","confirm","duplicateHandler","init"],"mappings":";;;;;;;AAsBAA,kCAAO,CAAC,SAAU,iBAAkB,YAAa,oBAAqB,aAAa,SAASC,EAAGC,UAAWC,KAAMC,aAAcC,SAItHC,cAAgB,EAGhBC,YAAc,EAQdC,WAAa,SAASC,QAASC,OAC/BT,EAAE,sCAAsCU,YAAYF,SACpDP,UAAUU,cAAcF,QAQxBG,WAAa,SAASC,SACtBZ,UAAUa,OAAO,4CAA6CD,SACzDE,KAAKR,YACLS,KAAKb,aAAac,YA8BvBC,SAAW,eAGPC,SAAWjB,KAAKkB,KAAK,CAAC,CACtBC,WAAY,8CACZC,KAAM,CAACC,GAAIjB,cACZ,CACCe,WAAY,qDACZC,KAAM,CACFE,YAAa,CACTC,UAAWpB,mBAIvBc,SAAS,GAAGJ,MAAK,SAASW,UACN,IAAZA,SACUxB,KAAKkB,KAAK,CAAC,CACjBC,WAAY,4CACZC,KAAM,CAACC,GAAIjB,gBAEX,GAAGS,MAAK,SAASY,WACjBvB,IAAIwB,YAAY,CACZ,CAACC,IAAK,2BAA4BC,UAAW,UAAWC,MAAOJ,UAAUK,WACzE,CAACH,IAAK,SAAUC,UA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