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 * Module to enable inline editing of a comptency grade.
19 * @package report_competency
20 * @copyright 2015 Damyon Wiese
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'core/templates', 'tool_lp/dialogue'],
25 function($, notification, str, ajax, log, templates, Dialogue) {
30 * @param {String} The regionSelector
31 * @param {String} The userCompetencySelector
33 var GradingPopup = function(regionSelector, userCompetencySelector) {
34 this._regionSelector = regionSelector;
35 this._userCompetencySelector = userCompetencySelector;
37 $(this._regionSelector).on('click', this._userCompetencySelector, this._handleClick.bind(this));
41 * Get the data from the clicked cell and open the popup.
43 * @method _handleClick
46 GradingPopup.prototype._handleClick = function(e) {
47 var cell = $(e.target).closest(this._userCompetencySelector);
48 var competencyId = $(cell).data('competencyid');
49 var courseId = $(cell).data('courseid');
50 var userId = $(cell).data('userid');
52 log.debug('Clicked on cell: competencyId=' + competencyId + ', courseId=' + courseId + ', userId=' + userId);
54 var requests = ajax.call([{
55 methodname : 'tool_lp_data_for_user_competency_summary_in_course',
56 args: { userid: userId, competencyid: competencyId, courseid: courseId },
57 done: this._contextLoaded.bind(this),
58 fail: notification.exception
61 // Log the user competency viewed in course event.
62 requests[0].then(function(){
64 methodname : 'core_competency_user_competency_viewed_in_course',
65 args: { userid: userId, competencyid: competencyId, courseid: courseId },
66 fail: notification.exception
72 * We loaded the context, now render the template.
74 * @method _contextLoaded
75 * @param {Object} context
77 GradingPopup.prototype._contextLoaded = function(context) {
79 // We have to display user info in popup.
80 context.displayuser = true;
81 templates.render('tool_lp/user_competency_summary_in_course', context).done(function(html, js) {
82 str.get_string('usercompetencysummary', 'report_competency').done(function(title) {
83 (new Dialogue(title, html, templates.runTemplateJS.bind(templates, js), self._refresh.bind(self), true));
84 }).fail(notification.exception);
85 }).fail(notification.exception);
93 GradingPopup.prototype._refresh = function() {
94 var region = $(this._regionSelector);
95 var courseId = region.data('courseid');
96 var userId = region.data('userid');
99 methodname : 'report_competency_data_for_report',
100 args: { courseid: courseId, userid: userId },
101 done: this._pageContextLoaded.bind(this),
102 fail: notification.exception
107 * We loaded the context, now render the template.
109 * @method _pageContextLoaded
110 * @param {Object} context
112 GradingPopup.prototype._pageContextLoaded = function(context) {
114 templates.render('report_competency/report', context).done(function(html, js) {
115 templates.replaceNode(self._regionSelector, html, js);
116 }).fail(notification.exception);
119 /** @type {String} The selector for the region with the user competencies */
120 GradingPopup.prototype._regionSelector = null;
121 /** @type {String} The selector for the region with a single user competencies */
122 GradingPopup.prototype._userCompetencySelector = null;
124 return /** @alias module:report_competency/grading_popup */ GradingPopup;