1{"version":3,"sources":["../src/frameworkactions.js"],"names":["define","$","templates","ajax","notification","str","pagecontextid","frameworkid","updatePage","newhtml","newjs","replaceWith","runTemplateJS","reloadList","context","render","done","fail","exception","doDuplicate","e","preventDefault","attr","requests","call","methodname","args","id","pagecontext","contextid","doDelete","success","req","framework","get_strings","key","component","param","shortname","strings","alert","confirmDelete","confirm","deleteHandler","duplicateHandler","init"],"mappings":"AAsBAA,OAAM,4BAAC,CAAC,QAAD,CAAW,gBAAX,CAA6B,WAA7B,CAA0C,mBAA1C,CAA+D,UAA/D,CAAD,CAA6E,SAASC,CAAT,CAAYC,CAAZ,CAAuBC,CAAvB,CAA6BC,CAA7B,CAA2CC,CAA3C,CAAgD,IAI3HC,CAAAA,CAAa,CAAG,CAJ2G,CAO3HC,CAAW,CAAG,CAP6G,CAe3HC,CAAU,CAAG,SAASC,CAAT,CAAkBC,CAAlB,CAAyB,CACtCT,CAAC,CAAC,sCAAD,CAAD,CAAwCU,WAAxC,CAAoDF,CAApD,EACAP,CAAS,CAACU,aAAV,CAAwBF,CAAxB,CACH,CAlB8H,CAyB3HG,CAAU,CAAG,SAASC,CAAT,CAAkB,CAC/BZ,CAAS,CAACa,MAAV,CAAiB,2CAAjB,CAA8DD,CAA9D,EACKE,IADL,CACUR,CADV,EAEKS,IAFL,CAEUb,CAAY,CAACc,SAFvB,CAGH,CA7B8H,CAoC3HC,CAAW,CAAG,SAASC,CAAT,CAAY,CAC1BA,CAAC,CAACC,cAAF,GAEAd,CAAW,CAAGN,CAAC,CAAC,IAAD,CAAD,CAAQqB,IAAR,CAAa,kBAAb,CAAd,CAGA,GAAIC,CAAAA,CAAQ,CAAGpB,CAAI,CAACqB,IAAL,CAAU,CAAC,CACtBC,UAAU,CAAE,gDADU,CAEtBC,IAAI,CAAE,CAACC,EAAE,CAAEpB,CAAL,CAFgB,CAAD,CAGtB,CACCkB,UAAU,CAAE,oDADb,CAECC,IAAI,CAAE,CACFE,WAAW,CAAE,CACTC,SAAS,CAA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B,CAiBH,CA9H8H,CAiI/H,MAAqD,CAQjDyB,aAAa,CAAEF,CARkC,CAejDG,gBAAgB,CAAEzB,CAf+B,CAsBjD0B,IAAI,CAAE,cAAShB,CAAT,CAAoB,CACtBvB,CAAa,CAAGuB,CACnB,CAxBgD,CA0BxD,CA3JK,CAAN","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"],"file":"frameworkactions.min.js"}