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 |
* Javascript module for displaying feedback in a modal window
|
|
|
18 |
*
|
|
|
19 |
* @module gradereport_grader/feedback_modal
|
|
|
20 |
* @copyright 2023 Kevin Percy <kevin.percy@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
import Modal from 'core/modal';
|
|
|
24 |
import Notification from 'core/notification';
|
|
|
25 |
import ajax from 'core/ajax';
|
|
|
26 |
import Templates from 'core/templates';
|
|
|
27 |
|
|
|
28 |
const Selectors = {
|
|
|
29 |
showFeedback: '[data-action="feedback"]'
|
|
|
30 |
};
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Create the modal to display the feedback.
|
|
|
34 |
*
|
|
|
35 |
* @param {int} courseid
|
|
|
36 |
* @param {int} userid
|
|
|
37 |
* @param {int} itemid
|
|
|
38 |
* @returns {Promise}
|
|
|
39 |
*/
|
|
|
40 |
const getModal = async(courseid, userid, itemid) => {
|
|
|
41 |
let feedbackData;
|
|
|
42 |
|
|
|
43 |
try {
|
|
|
44 |
feedbackData = await fetchFeedback(courseid, userid, itemid);
|
|
|
45 |
} catch (e) {
|
|
|
46 |
return Promise.reject(e);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
return Modal.create({
|
|
|
50 |
removeOnClose: true,
|
|
|
51 |
large: true,
|
|
|
52 |
verticallyCentered: true,
|
|
|
53 |
})
|
|
|
54 |
.then(modal => {
|
|
|
55 |
const body = Templates.render('core_grades/feedback_modal', {
|
|
|
56 |
feedbacktext: feedbackData.feedbacktext,
|
|
|
57 |
user: {
|
|
|
58 |
picture: feedbackData.picture,
|
|
|
59 |
fullname: feedbackData.fullname,
|
|
|
60 |
additionalfield: feedbackData.additionalfield,
|
|
|
61 |
},
|
|
|
62 |
});
|
|
|
63 |
|
|
|
64 |
modal.setBody(body);
|
|
|
65 |
modal.setTitle(feedbackData.title);
|
|
|
66 |
modal.show();
|
|
|
67 |
|
|
|
68 |
return modal;
|
|
|
69 |
});
|
|
|
70 |
};
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Fetch the feedback data.
|
|
|
74 |
*
|
|
|
75 |
* @param {int} courseid
|
|
|
76 |
* @param {int} userid
|
|
|
77 |
* @param {int} itemid
|
|
|
78 |
* @returns {Promise}
|
|
|
79 |
*/
|
|
|
80 |
const fetchFeedback = (courseid, userid, itemid) => {
|
|
|
81 |
const request = {
|
|
|
82 |
methodname: 'core_grades_get_feedback',
|
|
|
83 |
args: {
|
|
|
84 |
courseid: courseid,
|
|
|
85 |
userid: userid,
|
|
|
86 |
itemid: itemid,
|
|
|
87 |
},
|
|
|
88 |
};
|
|
|
89 |
return ajax.call([request])[0];
|
|
|
90 |
};
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Register event listeners for the View Feedback links.
|
|
|
94 |
*/
|
|
|
95 |
const registerEventListeners = () => {
|
|
|
96 |
document.addEventListener('click', e => {
|
|
|
97 |
const showFeedbackTrigger = e.target.closest(Selectors.showFeedback);
|
|
|
98 |
if (showFeedbackTrigger) {
|
|
|
99 |
e.preventDefault();
|
|
|
100 |
|
|
|
101 |
const courseid = showFeedbackTrigger.dataset.courseid;
|
|
|
102 |
const userid = e.target.closest('tr').dataset.uid;
|
|
|
103 |
const itemid = e.target.closest('td').dataset.itemid;
|
|
|
104 |
|
|
|
105 |
getModal(courseid, userid, itemid)
|
|
|
106 |
.catch(Notification.exception);
|
|
|
107 |
}
|
|
|
108 |
});
|
|
|
109 |
};
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Initialize module
|
|
|
113 |
*/
|
|
|
114 |
export const init = () => {
|
|
|
115 |
registerEventListeners();
|
|
|
116 |
};
|