Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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