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 |
* Event handlers for the mod_lti mod_form.
|
|
|
18 |
*
|
|
|
19 |
* @module mod_lti/mod_form
|
|
|
20 |
* @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
"use strict";
|
|
|
25 |
|
|
|
26 |
import ContentItem from 'mod_lti/contentitem';
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Initialise module.
|
|
|
30 |
*
|
|
|
31 |
* @param {int} courseId the course id.
|
|
|
32 |
*/
|
|
|
33 |
const init = (courseId) => {
|
|
|
34 |
const contentItemButton = document.querySelector('[name="selectcontent"]');
|
|
|
35 |
|
|
|
36 |
if (!contentItemButton) {
|
|
|
37 |
return;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
contentItemButton.addEventListener('click', () => {
|
|
|
41 |
const contentItemUrl = contentItemButton.getAttribute('data-contentitemurl');
|
|
|
42 |
const contentItemId = document.querySelector('#hidden_typeid').value;
|
|
|
43 |
if (contentItemId) {
|
|
|
44 |
const title = document.querySelector('#id_name').value.trim();
|
|
|
45 |
const text = document.querySelector('#id_introeditor').value.trim();
|
|
|
46 |
const postData = {
|
|
|
47 |
id: contentItemId,
|
|
|
48 |
course: courseId,
|
|
|
49 |
title: title,
|
|
|
50 |
text: text
|
|
|
51 |
};
|
|
|
52 |
|
|
|
53 |
// The callback below is called after the content item has been returned and processed.
|
|
|
54 |
ContentItem.init(contentItemUrl, postData, (returnData) => {
|
|
|
55 |
if (!returnData.multiple) {
|
|
|
56 |
// The state of the grade checkbox has already been set by processContentItemReturnData() but that
|
|
|
57 |
// hasn't fired the click/change event required by formslib to show/hide the dependent grade fields.
|
|
|
58 |
// Fire it now.
|
|
|
59 |
const allowGrades = document.querySelector('#id_instructorchoiceacceptgrades');
|
|
|
60 |
let allowGradesChangeEvent = new Event('change');
|
|
|
61 |
allowGrades.dispatchEvent(allowGradesChangeEvent);
|
|
|
62 |
|
|
|
63 |
// If the tool is set to accept grades, make sure "Point" is selected.
|
|
|
64 |
if (allowGrades.checked) {
|
|
|
65 |
const gradeType = document.querySelector('#id_grade_modgrade_type');
|
|
|
66 |
gradeType.value = "point";
|
|
|
67 |
let gradeTypeChangeEvent = new Event('change');
|
|
|
68 |
gradeType.dispatchEvent(gradeTypeChangeEvent);
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
});
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
export default {
|
|
|
77 |
init: init
|
|
|
78 |
};
|