1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
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.
|
|
|
7 |
//
|
|
|
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.
|
|
|
12 |
//
|
|
|
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/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Module to enable inline editing of a comptency grade.
|
|
|
18 |
*
|
|
|
19 |
* @module report_competency/grading_popup
|
|
|
20 |
* @copyright 2015 Damyon Wiese
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'core/templates', 'tool_lp/dialogue'],
|
|
|
25 |
function($, notification, str, ajax, log, templates, Dialogue) {
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* GradingPopup
|
|
|
29 |
*
|
|
|
30 |
* @class report_competency/grading_popup
|
|
|
31 |
* @param {String} regionSelector The regionSelector
|
|
|
32 |
* @param {String} userCompetencySelector The userCompetencySelector
|
|
|
33 |
*/
|
|
|
34 |
var GradingPopup = function(regionSelector, userCompetencySelector) {
|
|
|
35 |
this._regionSelector = regionSelector;
|
|
|
36 |
this._userCompetencySelector = userCompetencySelector;
|
|
|
37 |
|
|
|
38 |
$(this._regionSelector).on('click', this._userCompetencySelector, this._handleClick.bind(this));
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Get the data from the clicked cell and open the popup.
|
|
|
43 |
*
|
|
|
44 |
* @method _handleClick
|
|
|
45 |
* @param {Event} e The event
|
|
|
46 |
*/
|
|
|
47 |
GradingPopup.prototype._handleClick = function(e) {
|
|
|
48 |
var cell = $(e.target).closest(this._userCompetencySelector);
|
|
|
49 |
var competencyId = $(cell).data('competencyid');
|
|
|
50 |
var courseId = $(cell).data('courseid');
|
|
|
51 |
var userId = $(cell).data('userid');
|
|
|
52 |
|
|
|
53 |
log.debug('Clicked on cell: competencyId=' + competencyId + ', courseId=' + courseId + ', userId=' + userId);
|
|
|
54 |
|
|
|
55 |
var requests = ajax.call([{
|
|
|
56 |
methodname: 'tool_lp_data_for_user_competency_summary_in_course',
|
|
|
57 |
args: {userid: userId, competencyid: competencyId, courseid: courseId},
|
|
|
58 |
}, {
|
|
|
59 |
methodname: 'core_competency_user_competency_viewed_in_course',
|
|
|
60 |
args: {userid: userId, competencyid: competencyId, courseid: courseId},
|
|
|
61 |
}]);
|
|
|
62 |
|
|
|
63 |
$.when(requests[0], requests[1])
|
|
|
64 |
.then(this._contextLoaded.bind(this))
|
|
|
65 |
.catch(notification.exception);
|
|
|
66 |
};
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* We loaded the context, now render the template.
|
|
|
70 |
*
|
|
|
71 |
* @method _contextLoaded
|
|
|
72 |
* @param {Object} context
|
|
|
73 |
* @returns {Promise}
|
|
|
74 |
*/
|
|
|
75 |
GradingPopup.prototype._contextLoaded = function(context) {
|
|
|
76 |
// We have to display user info in popup.
|
|
|
77 |
context.displayuser = true;
|
|
|
78 |
|
|
|
79 |
M.util.js_pending('report_competency/grading_popup:_contextLoaded');
|
|
|
80 |
|
|
|
81 |
return $.when(
|
|
|
82 |
str.get_string('usercompetencysummary', 'report_competency'),
|
|
|
83 |
templates.render('tool_lp/user_competency_summary_in_course', context)
|
|
|
84 |
)
|
|
|
85 |
.then(function(title, templateData) {
|
|
|
86 |
return new Dialogue(
|
|
|
87 |
title,
|
|
|
88 |
templateData[0],
|
|
|
89 |
function() {
|
|
|
90 |
templates.runTemplateJS(templateData[1]);
|
|
|
91 |
M.util.js_complete('report_competency/grading_popup:_contextLoaded');
|
|
|
92 |
},
|
|
|
93 |
this._refresh.bind(this),
|
|
|
94 |
true
|
|
|
95 |
);
|
|
|
96 |
}.bind(this));
|
|
|
97 |
};
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Refresh the page.
|
|
|
101 |
*
|
|
|
102 |
* @method _refresh
|
|
|
103 |
* @returns {Promise}
|
|
|
104 |
*/
|
|
|
105 |
GradingPopup.prototype._refresh = function() {
|
|
|
106 |
var region = $(this._regionSelector);
|
|
|
107 |
var courseId = region.data('courseid');
|
|
|
108 |
var moduleId = region.data('moduleid');
|
|
|
109 |
var userId = region.data('userid');
|
|
|
110 |
|
|
|
111 |
// The module id is expected to be an integer, so don't pass empty string.
|
|
|
112 |
if (moduleId === '') {
|
|
|
113 |
moduleId = 0;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
return ajax.call([{
|
|
|
117 |
methodname: 'report_competency_data_for_report',
|
|
|
118 |
args: {courseid: courseId, userid: userId, moduleid: moduleId},
|
|
|
119 |
done: this._pageContextLoaded.bind(this),
|
|
|
120 |
fail: notification.exception
|
|
|
121 |
}]);
|
|
|
122 |
};
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* We loaded the context, now render the template.
|
|
|
126 |
*
|
|
|
127 |
* @method _pageContextLoaded
|
|
|
128 |
* @param {Object} context
|
|
|
129 |
*/
|
|
|
130 |
GradingPopup.prototype._pageContextLoaded = function(context) {
|
|
|
131 |
templates.render('report_competency/report', context)
|
|
|
132 |
.then(function(html, js) {
|
|
|
133 |
templates.replaceNode(this._regionSelector, html, js);
|
|
|
134 |
|
|
|
135 |
return;
|
|
|
136 |
}.bind(this))
|
|
|
137 |
.catch(notification.exception);
|
|
|
138 |
};
|
|
|
139 |
|
|
|
140 |
/** @property {String} The selector for the region with the user competencies */
|
|
|
141 |
GradingPopup.prototype._regionSelector = null;
|
|
|
142 |
/** @property {String} The selector for the region with a single user competencies */
|
|
|
143 |
GradingPopup.prototype._userCompetencySelector = null;
|
|
|
144 |
|
|
|
145 |
return GradingPopup;
|
|
|
146 |
});
|