Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"comparison.min.js","sources":["../../../../src/grades/grader/gradingpanel/comparison.js"],"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Compare a given form's values and its previously set data attributes.\n *\n * @module     core_grades/grades/grader/gradingpanel/comparison\n * @copyright  2019 Mathew May <mathew.solutions>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const fillInitialValues = (form) => {\n    Array.prototype.forEach.call(form.elements, (input) => {\n        if (input.type === 'submit' || input.type === 'button') {\n            return;\n        } else if (input.type === 'radio' || input.type === 'checkbox') {\n            input.dataset.initialValue = JSON.stringify(input.checked);\n        } else if (typeof input.value !== 'undefined') {\n            input.dataset.initialValue = JSON.stringify(input.value);\n        } else if (input.type === 'select-one') {\n            Array.prototype.forEach.call(input.options, (option) => {\n                option.dataset.initialValue = JSON.stringify(option.selected);\n            });\n        }\n   });\n};\n\n\n/**\n * Compare the form data with the initial form data from when the form was set up.\n *\n * If values have changed, return a truthy value.\n *\n * @param {HTMLElement} form\n * @return {Boolean}\n */\nexport const compareData = (form) => {\n    const result = Array.prototype.some.call(form.elements, (input) => {\n        if (input.type === 'submit' || input.type === 'button') {\n            return false;\n        } else if (input.type === 'radio' || input.type === 'checkbox') {\n            if (typeof input.dataset.initialValue !== 'undefined') {\n                return input.dataset.initialValue !== JSON.stringify(input.checked);\n            }\n        } else if (typeof input.value !== 'undefined') {\n            if (typeof input.dataset.initialValue !== 'undefined') {\n                return input.dataset.initialValue !== JSON.stringify(input.value);\n            }\n        } else if (input.type === 'select-one') {\n            return Array.prototype.some.call(input.options, (option) => {\n                if (typeof option.dataset.initialValue !== 'undefined') {\n                    return option.dataset.initialValue !== JSON.stringify(option.selected);\n                }\n\n                return false;\n            });\n        }\n\n        // No value found to check. Assume that there were changes.\n        return true;\n    });\n\n    // Fill the initial values again as the form may not be reloaded.\n    fillInitialValues(form);\n\n    return result;\n};\n"],"names":["fillInitialValues","form","Array","prototype","forEach","call","elements","input","type","dataset","initialValue","JSON","stringify","checked","value","options","option","selected","result","some"],"mappings":";;;;;;;;MAuBaA,kBAAqBC,OAC9BC,MAAMC,UAAUC,QAAQC,KAAKJ,KAAKK,UAAWC,QACtB,WAAfA,MAAMC,MAAoC,WAAfD,MAAMC,OAEX,UAAfD,MAAMC,MAAmC,aAAfD,MAAMC,KACvCD,MAAME,QAAQC,aAAeC,KAAKC,UAAUL,MAAMM,cACpB,IAAhBN,MAAMO,MACpBP,MAAME,QAAQC,aAAeC,KAAKC,UAAUL,MAAMO,OAC5B,eAAfP,MAAMC,MACbN,MAAMC,UAAUC,QAAQC,KAAKE,MAAMQ,SAAUC,SACzCA,OAAOP,QAAQC,aAAeC,KAAKC,UAAUI,OAAOC,oFAexChB,aAClBiB,OAAShB,MAAMC,UAAUgB,KAAKd,KAAKJ,KAAKK,UAAWC,WAClC,WAAfA,MAAMC,MAAoC,WAAfD,MAAMC,YAC1B,EACJ,GAAmB,UAAfD,MAAMC,MAAmC,aAAfD,MAAMC,cACG,IAA/BD,MAAME,QAAQC,oBACdH,MAAME,QAAQC,eAAiBC,KAAKC,UAAUL,MAAMM,cAE5D,QAA2B,IAAhBN,MAAMO,eACsB,IAA/BP,MAAME,QAAQC,oBACdH,MAAME,QAAQC,eAAiBC,KAAKC,UAAUL,MAAMO,YAE5D,GAAmB,eAAfP,MAAMC,YACNN,MAAMC,UAAUgB,KAAKd,KAAKE,MAAMQ,SAAUC,aACF,IAAhCA,OAAOP,QAAQC,cACfM,OAAOP,QAAQC,eAAiBC,KAAKC,UAAUI,OAAOC,mBAQlE,YAIXjB,kBAAkBC,MAEXiB"}