mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-74996 Quiz: Convert submission confirmation to core/modal_factory
This commit is contained in:
parent
fee1b8ce5f
commit
783a5c8ce7
11
mod/quiz/amd/build/submission_confirmation.min.js
vendored
Normal file
11
mod/quiz/amd/build/submission_confirmation.min.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
define("mod_quiz/submission_confirmation",["exports","core/notification","core/prefetch","core/str","core/modal_factory","core/modal_events"],(function(_exports,_notification,_prefetch,_str,Modal,ModalEvents){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
/**
|
||||
* A javascript module to handle submission confirmation for quiz.
|
||||
*
|
||||
* @module mod_quiz/submission_confirmation
|
||||
* @copyright 2022 Huong Nguyen <huongnv13@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 4.1
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=_interopRequireDefault(_notification),_prefetch=_interopRequireDefault(_prefetch),Modal=_interopRequireWildcard(Modal),ModalEvents=_interopRequireWildcard(ModalEvents);const SELECTOR_attemptSubmitButton=".path-mod-quiz .btn-finishattempt button",SELECTOR_attemptSubmitForm="form#frm-finishattempt";_exports.init=()=>{_prefetch.default.prefetchStrings("core_admin",["confirmation"]),_prefetch.default.prefetchStrings("quiz",["confirmclose","submitallandfinish"]),(()=>{const submitAction=document.querySelector(SELECTOR_attemptSubmitButton);submitAction&&submitAction.addEventListener("click",(e=>{e.preventDefault(),Modal.create({type:Modal.types.SAVE_CANCEL,title:(0,_str.get_string)("confirmation","admin"),body:(0,_str.get_string)("confirmclose","quiz"),buttons:{save:(0,_str.get_string)("submitallandfinish","quiz")}}).then((modal=>(modal.show(),modal))).then((modal=>(modal.getRoot().on(ModalEvents.save,(()=>{submitAction.closest(SELECTOR_attemptSubmitForm).submit()})),modal))).catch(_notification.default.exception)}))})()}}));
|
||||
|
||||
//# sourceMappingURL=submission_confirmation.min.js.map
|
1
mod/quiz/amd/build/submission_confirmation.min.js.map
Normal file
1
mod/quiz/amd/build/submission_confirmation.min.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"submission_confirmation.min.js","sources":["../src/submission_confirmation.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 * A javascript module to handle submission confirmation for quiz.\n *\n * @module mod_quiz/submission_confirmation\n * @copyright 2022 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.1\n */\n\nimport Notification from 'core/notification';\nimport Prefetch from 'core/prefetch';\nimport {get_string as getString} from 'core/str';\nimport * as Modal from 'core/modal_factory';\nimport * as ModalEvents from 'core/modal_events';\n\nconst SELECTOR = {\n attemptSubmitButton: '.path-mod-quiz .btn-finishattempt button',\n attemptSubmitForm: 'form#frm-finishattempt',\n};\n\n/**\n * Register events for attempt submit button.\n */\nconst registerEventListeners = () => {\n const submitAction = document.querySelector(SELECTOR.attemptSubmitButton);\n if (submitAction) {\n submitAction.addEventListener('click', e => {\n e.preventDefault();\n Modal.create({\n type: Modal.types.SAVE_CANCEL,\n title: getString('confirmation', 'admin'),\n body: getString('confirmclose', 'quiz'),\n buttons: {\n save: getString('submitallandfinish', 'quiz')\n },\n }).then(modal => {\n modal.show();\n return modal;\n }).then(modal => {\n modal.getRoot().on(ModalEvents.save, () => {\n const attemptForm = submitAction.closest(SELECTOR.attemptSubmitForm);\n attemptForm.submit();\n });\n return modal;\n }).catch(Notification.exception);\n });\n }\n};\n\n/**\n * Initialises.\n */\nexport const init = () => {\n Prefetch.prefetchStrings('core_admin', ['confirmation']);\n Prefetch.prefetchStrings('quiz', ['confirmclose', 'submitallandfinish']);\n registerEventListeners();\n};\n"],"names":["SELECTOR","prefetchStrings","submitAction","document","querySelector","addEventListener","e","preventDefault","Modal","create","type","types","SAVE_CANCEL","title","body","buttons","save","then","modal","show","getRoot","on","ModalEvents","closest","submit","catch","Notification","exception","registerEventListeners"],"mappings":";;;;;;;;8QA8BMA,6BACmB,2CADnBA,2BAEiB,uCAmCH,uBACPC,gBAAgB,aAAc,CAAC,mCAC/BA,gBAAgB,OAAQ,CAAC,eAAgB,uBA/BvB,YACrBC,aAAeC,SAASC,cAAcJ,8BACxCE,cACAA,aAAaG,iBAAiB,SAASC,IACnCA,EAAEC,iBACFC,MAAMC,OAAO,CACTC,KAAMF,MAAMG,MAAMC,YAClBC,OAAO,mBAAU,eAAgB,SACjCC,MAAM,mBAAU,eAAgB,QAChCC,QAAS,CACLC,MAAM,mBAAU,qBAAsB,WAE3CC,MAAKC,QACJA,MAAMC,OACCD,SACRD,MAAKC,QACJA,MAAME,UAAUC,GAAGC,YAAYN,MAAM,KACbd,aAAaqB,QAAQvB,4BAC7BwB,YAETN,SACRO,MAAMC,sBAAaC,eAW9BC"}
|
72
mod/quiz/amd/src/submission_confirmation.js
Normal file
72
mod/quiz/amd/src/submission_confirmation.js
Normal file
@ -0,0 +1,72 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A javascript module to handle submission confirmation for quiz.
|
||||
*
|
||||
* @module mod_quiz/submission_confirmation
|
||||
* @copyright 2022 Huong Nguyen <huongnv13@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 4.1
|
||||
*/
|
||||
|
||||
import Notification from 'core/notification';
|
||||
import Prefetch from 'core/prefetch';
|
||||
import {get_string as getString} from 'core/str';
|
||||
import * as Modal from 'core/modal_factory';
|
||||
import * as ModalEvents from 'core/modal_events';
|
||||
|
||||
const SELECTOR = {
|
||||
attemptSubmitButton: '.path-mod-quiz .btn-finishattempt button',
|
||||
attemptSubmitForm: 'form#frm-finishattempt',
|
||||
};
|
||||
|
||||
/**
|
||||
* Register events for attempt submit button.
|
||||
*/
|
||||
const registerEventListeners = () => {
|
||||
const submitAction = document.querySelector(SELECTOR.attemptSubmitButton);
|
||||
if (submitAction) {
|
||||
submitAction.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
Modal.create({
|
||||
type: Modal.types.SAVE_CANCEL,
|
||||
title: getString('confirmation', 'admin'),
|
||||
body: getString('confirmclose', 'quiz'),
|
||||
buttons: {
|
||||
save: getString('submitallandfinish', 'quiz')
|
||||
},
|
||||
}).then(modal => {
|
||||
modal.show();
|
||||
return modal;
|
||||
}).then(modal => {
|
||||
modal.getRoot().on(ModalEvents.save, () => {
|
||||
const attemptForm = submitAction.closest(SELECTOR.attemptSubmitForm);
|
||||
attemptForm.submit();
|
||||
});
|
||||
return modal;
|
||||
}).catch(Notification.exception);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialises.
|
||||
*/
|
||||
export const init = () => {
|
||||
Prefetch.prefetchStrings('core_admin', ['confirmation']);
|
||||
Prefetch.prefetchStrings('quiz', ['confirmclose', 'submitallandfinish']);
|
||||
registerEventListeners();
|
||||
};
|
@ -786,9 +786,10 @@ class mod_quiz_renderer extends plugin_renderer_base {
|
||||
new moodle_url($attemptobj->processattempt_url(), $options),
|
||||
get_string('submitallandfinish', 'quiz'));
|
||||
$button->id = 'responseform';
|
||||
$button->class = 'btn-finishattempt';
|
||||
$button->formid = 'frm-finishattempt';
|
||||
if ($attemptobj->get_state() == quiz_attempt::IN_PROGRESS) {
|
||||
$button->add_action(new confirm_action(get_string('confirmclose', 'quiz'), null,
|
||||
get_string('submitallandfinish', 'quiz')));
|
||||
$this->page->requires->js_call_amd('mod_quiz/submission_confirmation', 'init');
|
||||
}
|
||||
$button->primary = true;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user