1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * Change the course competency settings in a popup.
19 * @module tool_lp/configurecoursecompetencysettings
21 * @copyright 2015 Damyon Wiese <damyon@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 function($, notification, Dialogue, str, ajax, templates) {
35 * @param {String} selector - selector for the links to open the dialogue.
37 var settingsMod = function(selector) {
38 $(selector).on('click', this.configureSettings.bind(this));
41 /** @type {Dialogue} Reference to the dialogue that we opened. */
42 settingsMod.prototype._dialogue = null;
45 * Open the configure settings dialogue.
48 * @method configureSettings
50 settingsMod.prototype.configureSettings = function(e) {
51 var courseid = $(e.target).closest('a').data('courseid');
52 var currentValue = $(e.target).closest('a').data('pushratingstouserplans');
55 settings: { pushratingstouserplans: currentValue }
59 templates.render('tool_lp/course_competency_settings', context).done(function(html) {
60 str.get_string('configurecoursecompetencysettings', 'tool_lp').done(function (title) {
61 this._dialogue = new Dialogue(
64 this.addListeners.bind(this)
66 }.bind(this)).fail(notification.exception);
67 }.bind(this)).fail(notification.exception);
72 * Add the save listener to the form.
74 * @method addSaveListener
76 settingsMod.prototype.addListeners = function() {
77 var save = this._find('[data-action="save"]');
78 save.on('click', this.saveSettings.bind(this));
79 var cancel = this._find('[data-action="cancel"]');
80 cancel.on('click', this.cancelChanges.bind(this));
87 * @method cancelChanges
89 settingsMod.prototype.cancelChanges = function(e) {
91 this._dialogue.close();
97 * @param {String} selector
100 settingsMod.prototype._find = function(selector) {
101 return $('[data-region="coursecompetencysettings"]').find(selector);
108 * @method saveSettings
110 settingsMod.prototype.saveSettings = function(e) {
113 var newValue = this._find('input[name="pushratingstouserplans"]:checked').val();
114 var courseId = this._find('input[name="courseid"]').val();
115 var settings = { pushratingstouserplans: newValue };
118 { methodname: 'core_competency_update_course_competency_settings',
119 args: { courseid: courseId, settings: settings } }
120 ])[0].done(function() {
121 this.refreshCourseCompetenciesPage();
122 }.bind(this)).fail(notification.exception);
127 * Refresh the course competencies page.
130 * @method saveSettings
132 settingsMod.prototype.refreshCourseCompetenciesPage = function() {
133 var courseId = this._find('input[name="courseid"]').val();
136 { methodname: 'tool_lp_data_for_course_competencies_page',
137 args: { courseid: courseId } }
138 ])[0].done(function(context) {
139 templates.render('tool_lp/course_competencies_page', context).done(function(html, js) {
140 $('[data-region="coursecompetenciespage"]').replaceWith(html);
141 templates.runTemplateJS(js);
142 this._dialogue.close();
143 }.bind(this)).fail(notification.exception);
144 }.bind(this)).fail(notification.exception);
148 return /** @alias module:tool_lp/configurecoursecompetencysettings */ settingsMod;