Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"course_competency_settings.min.js","sources":["../src/course_competency_settings.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 * Change the course competency settings in a popup.\n *\n * @module     tool_lp/course_competency_settings\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',\n        'core/notification',\n        'tool_lp/dialogue',\n        'core/str',\n        'core/ajax',\n        'core/templates',\n        'core/pending'\n        ],\n       function($, notification, Dialogue, str, ajax, templates, Pending) {\n\n    /**\n     * Constructor\n     *\n     * @param {String} selector - selector for the links to open the dialogue.\n     */\n    var settingsMod = function(selector) {\n        $(selector).on('click', this.configureSettings.bind(this));\n    };\n\n    /** @property {Dialogue} Reference to the dialogue that we opened. */\n    settingsMod.prototype._dialogue = null;\n\n    /**\n     * Open the configure settings dialogue.\n     *\n     * @param {Event} e\n     * @method configureSettings\n     */\n    settingsMod.prototype.configureSettings = function(e) {\n        var pendingPromise = new Pending();\n        var courseid = $(e.target).closest('a').data('courseid');\n        var currentValue = $(e.target).closest('a').data('pushratingstouserplans');\n        var context = {\n            courseid: courseid,\n            settings: {pushratingstouserplans: currentValue}\n        };\n        e.preventDefault();\n\n        $.when(\n            str.get_string('configurecoursecompetencysettings', 'tool_lp'),\n            templates.render('tool_lp/course_competency_settings', context),\n        )\n        .then(function(title, templateResult) {\n            this._dialogue = new Dialogue(\n                title,\n                templateResult[0],\n                this.addListeners.bind(this)\n            );\n\n            return this._dialogue;\n        }.bind(this))\n        .then(pendingPromise.resolve)\n        .catch(notification.exception);\n    };\n\n    /**\n     * Add the save listener to the form.\n     *\n     * @method addSaveListener\n     */\n    settingsMod.prototype.addListeners = function() {\n        var save = this._find('[data-action=\"save\"]');\n        save.on('click', this.saveSettings.bind(this));\n        var cancel = this._find('[data-action=\"cancel\"]');\n        cancel.on('click', this.cancelChanges.bind(this));\n    };\n\n    /**\n     * Cancel the changes.\n     *\n     * @param {Event} e\n     * @method cancelChanges\n     */\n    settingsMod.prototype.cancelChanges = function(e) {\n        e.preventDefault();\n        this._dialogue.close();\n    };\n\n    /**\n     * Cancel the changes.\n     *\n     * @param {String} selector\n     * @return {JQuery}\n     */\n    settingsMod.prototype._find = function(selector) {\n        return $('[data-region=\"coursecompetencysettings\"]').find(selector);\n    };\n\n    /**\n     * Save the settings.\n     *\n     * @param {Event} e\n     * @method saveSettings\n     */\n    settingsMod.prototype.saveSettings = function(e) {\n        var pendingPromise = new Pending();\n        e.preventDefault();\n\n        var newValue = this._find('input[name=\"pushratingstouserplans\"]:checked').val();\n        var courseId = this._find('input[name=\"courseid\"]').val();\n        var settings = {pushratingstouserplans: newValue};\n\n        ajax.call([\n            {methodname: 'core_competency_update_course_competency_settings',\n              args: {courseid: courseId, settings: settings}}\n        ])[0]\n        .then(function() {\n            return this.refreshCourseCompetenciesPage();\n        }.bind(this))\n        .then(pendingPromise.resolve)\n        .catch(notification.exception);\n\n    };\n\n    /**\n     * Refresh the course competencies page.\n     *\n     * @method saveSettings\n     */\n    settingsMod.prototype.refreshCourseCompetenciesPage = function() {\n        var courseId = this._find('input[name=\"courseid\"]').val();\n        var pendingPromise = new Pending();\n\n        ajax.call([\n            {methodname: 'tool_lp_data_for_course_competencies_page',\n              args: {courseid: courseId, moduleid: 0}}\n        ])[0]\n        .then(function(context) {\n            return templates.render('tool_lp/course_competencies_page', context);\n        })\n        .then(function(html, js) {\n            templates.replaceNode($('[data-region=\"coursecompetenciespage\"]'), html, js);\n            this._dialogue.close();\n\n            return;\n        }.bind(this))\n        .then(pendingPromise.resolve)\n        .catch(notification.exception);\n    };\n\n    return /** @alias module:tool_lp/configurecoursecompetencysettings */ settingsMod;\n});\n"],"names":["define","$","notification","Dialogue","str","ajax","templates","Pending","settingsMod","selector","on","this","configureSettings","bind","prototype","_dialogue","e","pendingPromise","context","courseid","target","closest","data","settings","pushratingstouserplans","preventDefault","when","get_string","render","then","title","templateResult","addListeners","resolve","catch","exception","_find","saveSettings","cancelChanges","close","find","newValue","val","courseId","call","methodname","args","refreshCourseCompetenciesPage","moduleid","html","js","replaceNode"],"mappings":";;;;;;;AAsBAA,4CAAO,CAAC,SACA,oBACA,mBACA,WACA,YACA,iBACA,iBAED,SAASC,EAAGC,aAAcC,SAAUC,IAAKC,KAAMC,UAAWC,aAOzDC,YAAc,SAASC,UACvBR,EAAEQ,UAAUC,GAAG,QAASC,KAAKC,kBAAkBC,KAAKF,eAIxDH,YAAYM,UAAUC,UAAY,KAQlCP,YAAYM,UAAUF,kBAAoB,SAASI,OAC3CC,eAAiB,IAAIV,QAGrBW,QAAU,CACVC,SAHWlB,EAAEe,EAAEI,QAAQC,QAAQ,KAAKC,KAAK,YAIzCC,SAAU,CAACC,uBAHIvB,EAAEe,EAAEI,QAAQC,QAAQ,KAAKC,KAAK,4BAKjDN,EAAES,iBAEFxB,EAAEyB,KACEtB,IAAIuB,WAAW,oCAAqC,WACpDrB,UAAUsB,OAAO,qCAAsCV,UAE1DW,KAAK,SAASC,MAAOC,4BACbhB,UAAY,IAAIZ,SACjB2B,MACAC,eAAe,GACfpB,KAAKqB,aAAanB,KAAKF,OAGpBA,KAAKI,WACdF,KAAKF,OACNkB,KAAKZ,eAAegB,SACpBC,MAAMhC,aAAaiC,YAQxB3B,YAAYM,UAAUkB,aAAe,WACtBrB,KAAKyB,MAAM,wBACjB1B,GAAG,QAASC,KAAK0B,aAAaxB,KAAKF,OAC3BA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