Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"regrade_modal.min.js","sources":["../src/regrade_modal.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 * Regrade modal form is used to regrade or dryrun the attempts and questions.\n *\n * @module quiz_overview/regrade_modal\n * @copyright 2024 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Modal from 'core/modal';\nimport Templates from 'core/templates';\nimport {getString} from 'core/str';\nimport Notification from 'core/notification';\n\n/**\n * @type {Object} selectors used in this code.\n */\nconst SELECTORS = {\n    'allQuestionsButton': '#regradeallquestions',\n    'dryRunButton': '#dryrunbutton',\n    'mainTableForm': '#attemptsform',\n    'questionCheckbox': '[id^=\"regradeslot\"]',\n    'regradeAttemptsButtonId': 'regradeattempts',\n    'regradeButton': '#regradebutton',\n    'reportTableSelectedAttempts': '[id^=\"attemptid_\"]:checked',\n};\n\n/**\n * Show the regrade modal.\n *\n * @param {Event} e click event that opened the modal.\n * @returns {Promise<void>}\n */\nconst showModal = async(e) => {\n    e.preventDefault();\n    try {\n        let hiddenInputs = [];\n        document.querySelectorAll(SELECTORS.mainTableForm + ' input[type=hidden]').forEach((hiddenInput) => {\n            hiddenInputs.push({'name': hiddenInput.name, 'value': hiddenInput.value});\n        });\n        document.querySelectorAll(SELECTORS.reportTableSelectedAttempts).forEach((selectedAttempt) => {\n            hiddenInputs.push({'name': selectedAttempt.name, 'value': selectedAttempt.value});\n        });\n        const modal = await Modal.create({\n            title: getString('regrade', 'quiz_overview'),\n            body: Templates.render('quiz_overview/regrade_modal_body', {\n                'actionurl': document.querySelector(SELECTORS.mainTableForm).action,\n                'hasselectedattempts': document.querySelector(SELECTORS.reportTableSelectedAttempts) !== null,\n                'questions': JSON.parse(document.getElementById(SELECTORS.regradeAttemptsButtonId).dataset.slots),\n                'hiddeninputs': hiddenInputs,\n            }),\n            isVerticallyCentered: true,\n            removeOnClose: true,\n            show: true,\n        });\n        modal.getRoot()[0].addEventListener('change', updateButtonStates);\n        modal.getBodyPromise().then(updateButtonStates).catch(Notification.exception);\n\n        // TODO MDL-82204 - there is not currently a good way to add a help icon to a modal overall, so we do it this way.\n        modal.getTitlePromise().then((title) => {\n            title.append(' ' + document.getElementById(SELECTORS.regradeAttemptsButtonId).dataset.helpIcon);\n            // The next line is necessary to get a nice layout of the help icon.\n            title[0].querySelector('a').classList.add('align-baseline');\n            return title[0];\n        }).catch(Notification.exception);\n    } catch (ex) {\n        await Notification.exception(ex);\n    }\n};\n\n/**\n * Enables and disables controls when the selected options are changed.\n */\nconst updateButtonStates = () => {\n    const allQuestionsButton = document.querySelector(SELECTORS.allQuestionsButton);\n\n    // Question checkboxes enabled only if Selected questions is checked.\n    document.querySelectorAll(SELECTORS.questionCheckbox).forEach((questionCheckbox) => {\n        questionCheckbox.disabled = allQuestionsButton.checked;\n    });\n\n    // State of submit buttons.\n    const isAnyQuestionSelected = document.querySelector(SELECTORS.questionCheckbox + ':checked') !== null;\n    const canSubmit = allQuestionsButton.checked || isAnyQuestionSelected;\n    document.querySelector(SELECTORS.regradeButton).disabled = !canSubmit;\n    document.querySelector(SELECTORS.dryRunButton).disabled = !canSubmit;\n};\n\n/**\n * Initialize the regrade button to open the modal.\n */\nexport const init = () => {\n    const regradeButton = document.getElementById(SELECTORS.regradeAttemptsButtonId);\n    if (!regradeButton) {\n        return;\n    }\n\n    regradeButton.addEventListener('click', showModal);\n};\n"],"names":["SELECTORS","showModal","async","e","preventDefault","hiddenInputs","document","querySelectorAll","forEach","hiddenInput","push","name","value","selectedAttempt","modal","Modal","create","title","body","Templates","render","querySelector","action","JSON","parse","getElementById","dataset","slots","isVerticallyCentered","removeOnClose","show","getRoot","addEventListener","updateButtonStates","getBodyPromise","then","catch","Notification","exception","getTitlePromise","append","helpIcon","classList","add","ex","allQuestionsButton","questionCheckbox","disabled","checked","isAnyQuestionSelected","canSubmit","regradeButton"],"mappings":";;;;;;;gOA+BMA,6BACoB,uBADpBA,uBAEc,gBAFdA,wBAGe,gBAHfA,2BAIkB,sBAJlBA,kCAKyB,kBALzBA,wBAMe,iBANfA,sCAO6B,6BAS7BC,UAAYC,MAAAA,IACdC,EAAEC,yBAEMC,aAAe,GACnBC,SAASC,iBAAiBP,wBAA0B,uBAAuBQ,SAASC,cAChFJ,aAAaK,KAAK,MAASD,YAAYE,WAAeF,YAAYG,WAEtEN,SAASC,iBAAiBP,uCAAuCQ,SAASK,kBACtER,aAAaK,KAAK,MAASG,gBAAgBF,WAAeE,gBAAgBD,iBAExEE,YAAcC,eAAMC,OAAO,CAC7BC,OAAO,kBAAU,UAAW,iBAC5BC,KAAMC,mBAAUC,OAAO,mCAAoC,WAC1Cd,SAASe,cAAcrB,yBAAyBsB,2BAC4B,OAAlEhB,SAASe,cAAcrB,iDACjCuB,KAAKC,MAAMlB,SAASmB,eAAezB,mCAAmC0B,QAAQC,oBAC3EtB,eAEpBuB,sBAAsB,EACtBC,eAAe,EACfC,MAAM,IAEVhB,MAAMiB,UAAU,GAAGC,iBAAiB,SAAUC,oBAC9CnB,MAAMoB,iBAAiBC,KAAKF,oBAAoBG,MAAMC,sBAAaC,WAGnExB,MAAMyB,kBAAkBJ,MAAMlB,QAC1BA,MAAMuB,OAAO,IAAMlC,SAASmB,eAAezB,mCAAmC0B,QAAQe,UAEtFxB,MAAM,GAAGI,cAAc,KAAKqB,UAAUC,IAAI,kBACnC1B,MAAM,MACdmB,MAAMC,sBAAaC,WACxB,MAAOM,UACCP,sBAAaC,UAAUM,MAO/BX,mBAAqB,WACjBY,mBAAqBvC,SAASe,cAAcrB,8BAGlDM,SAASC,iBAAiBP,4BAA4BQ,SAASsC,mBAC3DA,iBAAiBC,SAAWF,mBAAmBG,iBAI7CC,sBAA4F,OAApE3C,SAASe,cAAcrB,2BAA6B,YAC5EkD,UAAYL,mBAAmBG,SAAWC,sBAChD3C,SAASe,cAAcrB,yBAAyB+C,UAAYG,UAC5D5C,SAASe,cAAcrB,wBAAwB+C,UAAYG,yBAM3C,WACVC,cAAgB7C,SAASmB,eAAezB,mCACzCmD,eAILA,cAAcnB,iBAAiB,QAAS/B"}