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 * Grading panel for gradingform_rubric.
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
25 import {call as fetchMany} from 'core/ajax';
26 import {normaliseResult} from 'core_grades/grades/grader/gradingpanel/normalise';
27 import {compareData} from 'core_grades/grades/grader/gradingpanel/comparison';
29 // Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send()
30 import jQuery from 'jquery';
33 * For a given component, contextid, itemname & gradeduserid we can fetch the currently assigned grade.
35 * @param {String} component
36 * @param {Number} contextid
37 * @param {String} itemname
38 * @param {Number} gradeduserid
42 export const fetchCurrentGrade = (component, contextid, itemname, gradeduserid) => {
44 methodname: `gradingform_rubric_grader_gradingpanel_fetch`,
55 * For a given component, contextid, itemname & gradeduserid we can store the currently assigned grade in a given form.
57 * @param {String} component
58 * @param {Number} contextid
59 * @param {String} itemname
60 * @param {Number} gradeduserid
61 * @param {HTMLElement} rootNode
62 * @param {Boolean} notifyuser
66 export const storeCurrentGrade = async(component, contextid, itemname, gradeduserid, rootNode, notifyuser = false) => {
67 const form = rootNode.querySelector('form');
69 if (compareData(form) === true) {
70 return normaliseResult(await fetchMany([{
71 methodname: `gradingform_rubric_grader_gradingpanel_store`,
77 formdata: jQuery(form).serialize(),