From 8b04be120bd113d038276081930c55593a4bf892 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Tue, 5 Nov 2019 17:43:36 +0800 Subject: [PATCH] MDL-66958 core_grade: Only save scale on form change --- grade/amd/build/grades/grader/gradingpanel/scale.min.js | 2 +- .../amd/build/grades/grader/gradingpanel/scale.min.js.map | 2 +- grade/amd/src/grades/grader/gradingpanel/scale.js | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/grade/amd/build/grades/grader/gradingpanel/scale.min.js b/grade/amd/build/grades/grader/gradingpanel/scale.min.js index edb9c077cc1..3c3b6f2a84b 100644 --- a/grade/amd/build/grades/grader/gradingpanel/scale.min.js +++ b/grade/amd/build/grades/grader/gradingpanel/scale.min.js @@ -1,2 +1,2 @@ -define ("core_grades/grades/grader/gradingpanel/scale",["exports","./repository","jquery","./normalise"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.storeCurrentGrade=a.fetchCurrentGrade=void 0;c=function(a){return a&&a.__esModule?a:{default:a}}(c);a.fetchCurrentGrade=function fetchCurrentGrade(){return(0,b.fetchGrade)("scale").apply(void 0,arguments)};var e=function(a,e,f,g,h){var i=h.querySelector("form"),j=i.querySelector("select[name=\"grade\"]");if(!j.checkValidity()||!j.value.trim()){return d.invalidResult}return(0,b.saveGrade)("scale")(a,e,f,g,(0,c.default)(i).serialize())};a.storeCurrentGrade=e}); +define ("core_grades/grades/grader/gradingpanel/scale",["exports","./repository","core_grades/grades/grader/gradingpanel/comparison","jquery","./normalise"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.storeCurrentGrade=a.fetchCurrentGrade=void 0;d=function(a){return a&&a.__esModule?a:{default:a}}(d);a.fetchCurrentGrade=function fetchCurrentGrade(){return(0,b.fetchGrade)("scale").apply(void 0,arguments)};var f=function(a,f,g,h,i){var j=i.querySelector("form"),k=j.querySelector("select[name=\"grade\"]");if(!k.checkValidity()||!k.value.trim()){return e.invalidResult}if(!0===(0,c.compareData)(j)){return(0,b.saveGrade)("scale")(a,f,g,h,(0,d.default)(j).serialize())}else{return""}};a.storeCurrentGrade=f}); //# sourceMappingURL=scale.min.js.map diff --git a/grade/amd/build/grades/grader/gradingpanel/scale.min.js.map b/grade/amd/build/grades/grader/gradingpanel/scale.min.js.map index 7ceeb00a6fd..e79a065fa74 100644 --- a/grade/amd/build/grades/grader/gradingpanel/scale.min.js.map +++ b/grade/amd/build/grades/grader/gradingpanel/scale.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../../src/grades/grader/gradingpanel/scale.js"],"names":["fetchCurrentGrade","storeCurrentGrade","component","context","itemname","userId","rootNode","form","querySelector","grade","checkValidity","value","trim","invalidResult","serialize"],"mappings":"wOA0BA,uD,oBAGiC,QAApBA,CAAAA,iBAAoB,SAAa,iBAAW,OAAX,yBAAb,C,CAE1B,GAAMC,CAAAA,CAAiB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAqBC,CAArB,CAA+BC,CAA/B,CAAuCC,CAAvC,CAAoD,IAC3EC,CAAAA,CAAI,CAAGD,CAAQ,CAACE,aAAT,CAAuB,MAAvB,CADoE,CAE3EC,CAAK,CAAGF,CAAI,CAACC,aAAL,CAAmB,wBAAnB,CAFmE,CAIjF,GAAI,CAACC,CAAK,CAACC,aAAN,EAAD,EAA0B,CAACD,CAAK,CAACE,KAAN,CAAYC,IAAZ,EAA/B,CAAmD,CAC/C,MAAOC,gBACV,CAED,MAAO,gBAAU,OAAV,EAAmBX,CAAnB,CAA8BC,CAA9B,CAAuCC,CAAvC,CAAiDC,CAAjD,CAAyD,cAAOE,CAAP,EAAaO,SAAb,EAAzD,CACV,CATM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Grading panel for simple direct grading.\n *\n * @module core_grades/grades/grader/gradingpanel/scale\n * @package core_grades\n * @copyright 2019 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {saveGrade, fetchGrade} from './repository';\n// Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send()\nimport jQuery from 'jquery';\nimport {invalidResult} from './normalise';\n\nexport const fetchCurrentGrade = (...args) => fetchGrade('scale')(...args);\n\nexport const storeCurrentGrade = (component, context, itemname, userId, rootNode) => {\n const form = rootNode.querySelector('form');\n const grade = form.querySelector('select[name=\"grade\"]');\n\n if (!grade.checkValidity() || !grade.value.trim()) {\n return invalidResult;\n }\n\n return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize());\n};\n"],"file":"scale.min.js"} \ No newline at end of file +{"version":3,"sources":["../../../../src/grades/grader/gradingpanel/scale.js"],"names":["fetchCurrentGrade","storeCurrentGrade","component","context","itemname","userId","rootNode","form","querySelector","grade","checkValidity","value","trim","invalidResult","serialize"],"mappings":"8RA2BA,uD,oBAGiC,QAApBA,CAAAA,iBAAoB,SAAa,iBAAW,OAAX,yBAAb,C,CAE1B,GAAMC,CAAAA,CAAiB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAqBC,CAArB,CAA+BC,CAA/B,CAAuCC,CAAvC,CAAoD,IAC3EC,CAAAA,CAAI,CAAGD,CAAQ,CAACE,aAAT,CAAuB,MAAvB,CADoE,CAE3EC,CAAK,CAAGF,CAAI,CAACC,aAAL,CAAmB,wBAAnB,CAFmE,CAIjF,GAAI,CAACC,CAAK,CAACC,aAAN,EAAD,EAA0B,CAACD,CAAK,CAACE,KAAN,CAAYC,IAAZ,EAA/B,CAAmD,CAC/C,MAAOC,gBACV,CAED,GAAI,uBAAYN,CAAZ,CAAJ,CAAgC,CAC5B,MAAO,gBAAU,OAAV,EAAmBL,CAAnB,CAA8BC,CAA9B,CAAuCC,CAAvC,CAAiDC,CAAjD,CAAyD,cAAOE,CAAP,EAAaO,SAAb,EAAzD,CACV,CAFD,IAEO,CACH,MAAO,EACV,CACJ,CAbM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Grading panel for simple direct grading.\n *\n * @module core_grades/grades/grader/gradingpanel/scale\n * @package core_grades\n * @copyright 2019 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {saveGrade, fetchGrade} from './repository';\nimport {compareData} from 'core_grades/grades/grader/gradingpanel/comparison';\n// Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send()\nimport jQuery from 'jquery';\nimport {invalidResult} from './normalise';\n\nexport const fetchCurrentGrade = (...args) => fetchGrade('scale')(...args);\n\nexport const storeCurrentGrade = (component, context, itemname, userId, rootNode) => {\n const form = rootNode.querySelector('form');\n const grade = form.querySelector('select[name=\"grade\"]');\n\n if (!grade.checkValidity() || !grade.value.trim()) {\n return invalidResult;\n }\n\n if (compareData(form) === true) {\n return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize());\n } else {\n return '';\n }\n};\n"],"file":"scale.min.js"} \ No newline at end of file diff --git a/grade/amd/src/grades/grader/gradingpanel/scale.js b/grade/amd/src/grades/grader/gradingpanel/scale.js index 3caca5ead0a..543eab1e94e 100644 --- a/grade/amd/src/grades/grader/gradingpanel/scale.js +++ b/grade/amd/src/grades/grader/gradingpanel/scale.js @@ -23,6 +23,7 @@ */ import {saveGrade, fetchGrade} from './repository'; +import {compareData} from 'core_grades/grades/grader/gradingpanel/comparison'; // Note: We use jQuery.serializer here until we can rewrite Ajax to use XHR.send() import jQuery from 'jquery'; import {invalidResult} from './normalise'; @@ -37,5 +38,9 @@ export const storeCurrentGrade = (component, context, itemname, userId, rootNode return invalidResult; } - return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize()); + if (compareData(form) === true) { + return saveGrade('scale')(component, context, itemname, userId, jQuery(form).serialize()); + } else { + return ''; + } };