Commit | Line | Data |
---|---|---|
eb9df053 MM |
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 | * Grading panel for gradingform_rubric. | |
18 | * | |
19 | * @module gradingform_rubric/grades/grader/gradingpanel | |
20 | * @package gradingform_rubric | |
21 | * @copyright 2019 Mathew May <mathew.solutions> | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
25 | import {call as fetchMany} from 'core/ajax'; | |
26 | import {normaliseResult} from 'core_grades/grades/grader/gradingpanel/normalise'; | |
9769ba08 | 27 | import {compareData} from 'core_grades/grades/grader/gradingpanel/comparison'; |
eb9df053 MM |
28 | |
29 | ||
30 | // Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send() | |
31 | import jQuery from 'jquery'; | |
32 | ||
47919bbe MM |
33 | /** |
34 | * For a given component, contextid, itemname & gradeduserid we can fetch the currently assigned grade. | |
35 | * | |
36 | * @param {String} component | |
37 | * @param {Number} contextid | |
38 | * @param {String} itemname | |
39 | * @param {Number} gradeduserid | |
40 | * | |
41 | * @returns {Promise} | |
42 | */ | |
eb9df053 MM |
43 | export const fetchCurrentGrade = (component, contextid, itemname, gradeduserid) => { |
44 | return fetchMany([{ | |
45 | methodname: `gradingform_rubric_grader_gradingpanel_fetch`, | |
46 | args: { | |
47 | component, | |
48 | contextid, | |
49 | itemname, | |
50 | gradeduserid, | |
51 | }, | |
52 | }])[0]; | |
53 | }; | |
54 | ||
47919bbe MM |
55 | /** |
56 | * For a given component, contextid, itemname & gradeduserid we can store the currently assigned grade in a given form. | |
57 | * | |
58 | * @param {String} component | |
59 | * @param {Number} contextid | |
60 | * @param {String} itemname | |
61 | * @param {Number} gradeduserid | |
62 | * @param {HTMLElement} rootNode | |
63 | * | |
64 | * @returns {Promise} | |
65 | */ | |
eb9df053 MM |
66 | export const storeCurrentGrade = async(component, contextid, itemname, gradeduserid, rootNode) => { |
67 | const form = rootNode.querySelector('form'); | |
68 | ||
9769ba08 MM |
69 | if (compareData(form) === true) { |
70 | return normaliseResult(await fetchMany([{ | |
71 | methodname: `gradingform_rubric_grader_gradingpanel_store`, | |
72 | args: { | |
73 | component, | |
74 | contextid, | |
75 | itemname, | |
76 | gradeduserid, | |
77 | formdata: jQuery(form).serialize(), | |
78 | }, | |
79 | }])[0]); | |
80 | } else { | |
81 | return ''; | |
82 | } | |
eb9df053 | 83 | }; |