Merge branch 'MDL-77168-master' of https://github.com/andrewnicols/moodle

This commit is contained in:
Ilya Tregubov
2023-05-31 10:22:02 +08:00
10 changed files with 46 additions and 310 deletions
+30 -19
View File
@@ -134,7 +134,36 @@ abstract class base_moodleform extends moodleform {
$buttonarray[] = $this->_form->createElement('submit', 'oneclickbackup', get_string('jumptofinalstep', 'backup'),
array('class' => 'oneclickbackup'));
}
$buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class' => 'confirmcancel'));
$cancelparams = [
'data-modal' => 'confirmation',
'data-modal-content-str' => json_encode([
'confirmcancelquestion',
'backup',
]),
'data-modal-yes-button-str' => json_encode([
'yes',
'moodle',
]),
];
if ($this->uistage->get_ui() instanceof import_ui) {
$cancelparams['data-modal-title-str'] = json_encode([
'confirmcancelimport',
'backup',
]);
} else if ($this->uistage->get_ui() instanceof restore_ui) {
$cancelparams['data-modal-title-str'] = json_encode([
'confirmcancelrestore',
'backup',
]);
} else {
$cancelparams['data-modal-title-str'] = json_encode([
'confirmcancel',
'backup',
]);
}
$buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), $cancelparams);
$buttonarray[] = $this->_form->createElement(
'submit',
'submitbutton',
@@ -383,24 +412,6 @@ abstract class base_moodleform extends moodleform {
$this->require_definition_after_data();
$config = new stdClass;
if ($this->uistage->get_ui() instanceof import_ui) {
$config->title = get_string('confirmcancelimport', 'backup');
} else if ($this->uistage->get_ui() instanceof restore_ui) {
$config->title = get_string('confirmcancelrestore', 'backup');
} else {
$config->title = get_string('confirmcancel', 'backup');
}
$config->question = get_string('confirmcancelquestion', 'backup');
$config->yesLabel = $config->title;
$config->noLabel = get_string('confirmcancelno', 'backup');
$config->closeButtonTitle = get_string('close', 'editor');
$PAGE->requires->yui_module(
'moodle-backup-confirmcancel',
'M.core_backup.confirmcancel.watch_cancel_buttons',
array($config)
);
// Get list of module types on course.
$modinfo = get_fast_modinfo($COURSE);
$modnames = array_map('strval', $modinfo->get_used_module_names(true));
@@ -1,91 +0,0 @@
YUI.add('moodle-backup-confirmcancel', function (Y, NAME) {
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @module moodle-backup-confirmcancel
*/
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @class M.core_backup.confirmcancel
*/
// Namespace for the backup.
M.core_backup = M.core_backup || {};
M.core_backup.confirmcancel = {
/**
* An array of EventHandlers which call the confirm_cancel dialogue.
*
* @property listeners
* @protected
* @type Array
*/
listeners: [],
/**
* The configuration supplied to this instance.
*
* @property config
* @protected
* @type Object
*/
config: {},
/**
* Initializer to watch all cancel buttons.
*
* @method watch_cancel_buttons
* @param {Object} config The configuration for the confirmation dialogue.
*/
watch_cancel_buttons: function(config) {
this.config = config;
this.listeners.push(
Y.one(Y.config.doc.body).delegate('click', this.confirm_cancel, '.confirmcancel', this)
);
},
/**
* Display the confirmation dialogue.
*
* @method confirm_cancel
* @protected
* @param {EventFacade} e
*/
confirm_cancel: function(e) {
// Prevent the default event (submit) from firing.
e.preventDefault();
// Create the confirmation dialogue.
var confirm = new M.core.confirm(this.config);
// If the user clicks yes.
confirm.on('complete-yes', function() {
// Detach the listeners for the confirm box so they don't fire again.
new Y.EventHandle(M.core_backup.confirmcancel.listeners).detach();
// The currentTarget is a div surrounding the form elements. Simulating a click on the div is
// not going to submit a form so we need to find the form element to click.
var element = e.currentTarget.one('input, select, button');
// Simulate the original cancel button click.
if (element) {
element.simulate('click');
} else {
// Backwards compatibility only.
e.currentTarget.simulate('click');
}
}, this);
// Show the confirm box.
confirm.show();
}
};
}, '@VERSION@', {"requires": ["node", "node-event-simulate", "moodle-core-notification-confirm"]});
@@ -1 +0,0 @@
YUI.add("moodle-backup-confirmcancel",function(n,c){M.core_backup=M.core_backup||{},M.core_backup.confirmcancel={listeners:[],config:{},watch_cancel_buttons:function(c){this.config=c,this.listeners.push(n.one(n.config.doc.body).delegate("click",this.confirm_cancel,".confirmcancel",this))},confirm_cancel:function(e){e.preventDefault();var c=new M.core.confirm(this.config);c.on("complete-yes",function(){new n.EventHandle(M.core_backup.confirmcancel.listeners).detach();var c=e.currentTarget.one("input, select, button");(c||e.currentTarget).simulate("click")},this),c.show()}}},"@VERSION@",{requires:["node","node-event-simulate","moodle-core-notification-confirm"]});
@@ -1,91 +0,0 @@
YUI.add('moodle-backup-confirmcancel', function (Y, NAME) {
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @module moodle-backup-confirmcancel
*/
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @class M.core_backup.confirmcancel
*/
// Namespace for the backup.
M.core_backup = M.core_backup || {};
M.core_backup.confirmcancel = {
/**
* An array of EventHandlers which call the confirm_cancel dialogue.
*
* @property listeners
* @protected
* @type Array
*/
listeners: [],
/**
* The configuration supplied to this instance.
*
* @property config
* @protected
* @type Object
*/
config: {},
/**
* Initializer to watch all cancel buttons.
*
* @method watch_cancel_buttons
* @param {Object} config The configuration for the confirmation dialogue.
*/
watch_cancel_buttons: function(config) {
this.config = config;
this.listeners.push(
Y.one(Y.config.doc.body).delegate('click', this.confirm_cancel, '.confirmcancel', this)
);
},
/**
* Display the confirmation dialogue.
*
* @method confirm_cancel
* @protected
* @param {EventFacade} e
*/
confirm_cancel: function(e) {
// Prevent the default event (submit) from firing.
e.preventDefault();
// Create the confirmation dialogue.
var confirm = new M.core.confirm(this.config);
// If the user clicks yes.
confirm.on('complete-yes', function() {
// Detach the listeners for the confirm box so they don't fire again.
new Y.EventHandle(M.core_backup.confirmcancel.listeners).detach();
// The currentTarget is a div surrounding the form elements. Simulating a click on the div is
// not going to submit a form so we need to find the form element to click.
var element = e.currentTarget.one('input, select, button');
// Simulate the original cancel button click.
if (element) {
element.simulate('click');
} else {
// Backwards compatibility only.
e.currentTarget.simulate('click');
}
}, this);
// Show the confirm box.
confirm.show();
}
};
}, '@VERSION@', {"requires": ["node", "node-event-simulate", "moodle-core-notification-confirm"]});
@@ -1,10 +0,0 @@
{
"name": "moodle-backup-confirmcancel",
"builds": {
"moodle-backup-confirmcancel": {
"jsfiles": [
"confirmcancel.js"
]
}
}
}
@@ -1,86 +0,0 @@
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @module moodle-backup-confirmcancel
*/
/**
* Add a confirmation dialogue when cancelling a backup.
*
* @class M.core_backup.confirmcancel
*/
// Namespace for the backup.
M.core_backup = M.core_backup || {};
M.core_backup.confirmcancel = {
/**
* An array of EventHandlers which call the confirm_cancel dialogue.
*
* @property listeners
* @protected
* @type Array
*/
listeners: [],
/**
* The configuration supplied to this instance.
*
* @property config
* @protected
* @type Object
*/
config: {},
/**
* Initializer to watch all cancel buttons.
*
* @method watch_cancel_buttons
* @param {Object} config The configuration for the confirmation dialogue.
*/
watch_cancel_buttons: function(config) {
this.config = config;
this.listeners.push(
Y.one(Y.config.doc.body).delegate('click', this.confirm_cancel, '.confirmcancel', this)
);
},
/**
* Display the confirmation dialogue.
*
* @method confirm_cancel
* @protected
* @param {EventFacade} e
*/
confirm_cancel: function(e) {
// Prevent the default event (submit) from firing.
e.preventDefault();
// Create the confirmation dialogue.
var confirm = new M.core.confirm(this.config);
// If the user clicks yes.
confirm.on('complete-yes', function() {
// Detach the listeners for the confirm box so they don't fire again.
new Y.EventHandle(M.core_backup.confirmcancel.listeners).detach();
// The currentTarget is a div surrounding the form elements. Simulating a click on the div is
// not going to submit a form so we need to find the form element to click.
var element = e.currentTarget.one('input, select, button');
// Simulate the original cancel button click.
if (element) {
element.simulate('click');
} else {
// Backwards compatibility only.
e.currentTarget.simulate('click');
}
}, this);
// Show the confirm box.
confirm.show();
}
};
@@ -1,9 +0,0 @@
{
"moodle-backup-confirmcancel": {
"requires": [
"node",
"node-event-simulate",
"moodle-core-notification-confirm"
]
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
define("core/utility",["core/str","core/pending","core/toast","core/notification"],(function(Str,_pending,_toast,_notification){var obj;Str=function(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]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};var _systemImportTransformerGlobalIdentifier="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};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)}let registered=!1;const getModalString=(dataset,type,field)=>dataset["".concat(type).concat(field,"Str")]?Str.get_string.apply(null,JSON.parse(dataset["".concat(type).concat(field,"Str")])):Promise.resolve(dataset["".concat(type).concat(field)]),displayConfirmation=(source,type)=>{let confirmationPromise=null;return confirmationPromise="".concat(type,"Type")in source.dataset&&"delete"===source.dataset["".concat(type,"Type")]?(0,_notification.deleteCancelPromise)(getModalString(source.dataset,type,"Title"),getModalString(source.dataset,type,"Content"),getModalString(source.dataset,type,"YesButton")):(0,_notification.saveCancelPromise)(getModalString(source.dataset,type,"Title"),getModalString(source.dataset,type,"Content"),getModalString(source.dataset,type,"YesButton")),confirmationPromise.then((()=>{if("true"===source.dataset["".concat(type,"Toast")]){const stringForToast=getModalString(source.dataset,type,"ToastConfirmation");"string"==typeof stringForToast?(0,_toast.add)(stringForToast):stringForToast.then((str=>(0,_toast.add)(str))).catch((e=>(0,_notification.exception)(e)))}window.location.href=source.dataset["".concat(type,"Destination")]})).catch((()=>{}))};registered||((()=>{document.addEventListener("click",(e=>{const confirmRequest=e.target.closest('[data-confirmation="modal"]');confirmRequest&&(e.preventDefault(),displayConfirmation(confirmRequest,"confirmation"));const modalConfirmation=e.target.closest('[data-modal="confirmation"]');modalConfirmation&&(e.preventDefault(),displayConfirmation(modalConfirmation,"modal"));const alertRequest=e.target.closest('[data-modal="alert"]');alertRequest&&(e.preventDefault(),(async(title,content)=>{const pendingPromise=new _pending.default("core/confirm:alert"),ModalFactory=await("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["core/modal_factory"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("core/modal_factory")):Promise.resolve(_systemImportTransformerGlobalIdentifier["core/modal_factory"]));ModalFactory.create({type:ModalFactory.types.ALERT,title:title,body:content,removeOnClose:!0}).then((function(modal){return modal.show(),pendingPromise.resolve(),modal}))})(getModalString(alertRequest.dataset,"modal","Title"),getModalString(alertRequest.dataset,"modal","Content")))}))})(),registered=!0)}));
define("core/utility",["core/str","core/pending","core/toast","core/notification"],(function(Str,_pending,_toast,_notification){var obj;Str=function(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]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};var _systemImportTransformerGlobalIdentifier="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};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)}let registered=!1;const getModalString=(dataset,type,field)=>dataset["".concat(type).concat(field,"Str")]?Str.get_string.apply(null,JSON.parse(dataset["".concat(type).concat(field,"Str")])):Promise.resolve(dataset["".concat(type).concat(field)]),displayConfirmation=(source,type)=>{let confirmationPromise=null;return confirmationPromise="".concat(type,"Type")in source.dataset&&"delete"===source.dataset["".concat(type,"Type")]?(0,_notification.deleteCancelPromise)(getModalString(source.dataset,type,"Title"),getModalString(source.dataset,type,"Content"),getModalString(source.dataset,type,"YesButton")):(0,_notification.saveCancelPromise)(getModalString(source.dataset,type,"Title"),getModalString(source.dataset,type,"Content"),getModalString(source.dataset,type,"YesButton")),confirmationPromise.then((()=>{if("true"===source.dataset["".concat(type,"Toast")]){const stringForToast=getModalString(source.dataset,type,"ToastConfirmation");"string"==typeof stringForToast?(0,_toast.add)(stringForToast):stringForToast.then((str=>(0,_toast.add)(str))).catch((e=>(0,_notification.exception)(e)))}if(source.dataset["".concat(type,"Destination")])window.location.href=source.dataset["".concat(type,"Destination")];else{if(!source.closest("form"))throw new Error("No destination found for confirmation action");source.dataset.confirmation="none",source.dataset.modal="none",source.click()}})).catch((()=>{}))};registered||((()=>{document.addEventListener("click",(e=>{const confirmRequest=e.target.closest('[data-confirmation="modal"]');confirmRequest&&(e.preventDefault(),displayConfirmation(confirmRequest,"confirmation"));const modalConfirmation=e.target.closest('[data-modal="confirmation"]');modalConfirmation&&(e.preventDefault(),displayConfirmation(modalConfirmation,"modal"));const alertRequest=e.target.closest('[data-modal="alert"]');alertRequest&&(e.preventDefault(),(async(title,content)=>{const pendingPromise=new _pending.default("core/confirm:alert"),ModalFactory=await("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require(["core/modal_factory"],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require("core/modal_factory")):Promise.resolve(_systemImportTransformerGlobalIdentifier["core/modal_factory"]));ModalFactory.create({type:ModalFactory.types.ALERT,title:title,body:content,removeOnClose:!0}).then((function(modal){return modal.show(),pendingPromise.resolve(),modal}))})(getModalString(alertRequest.dataset,"modal","Title"),getModalString(alertRequest.dataset,"modal","Content")))}))})(),registered=!0)}));
//# sourceMappingURL=utility.min.js.map
File diff suppressed because one or more lines are too long
+14 -1
View File
@@ -103,7 +103,20 @@ const displayConfirmation = (source, type) => {
stringForToast.then(str => addToast(str)).catch(e => exception(e));
}
}
window.location.href = source.dataset[`${type}Destination`];
if (source.dataset[`${type}Destination`]) {
window.location.href = source.dataset[`${type}Destination`];
} else if (source.closest('form')) {
// Update the modal and confirmation data fields so that we don't loop.
source.dataset.confirmation = 'none';
source.dataset.modal = 'none';
// Click on the button again.
// Note: Do not use the form.submit() because it will not work for cancel buttons.
source.click();
} else {
throw new Error("No destination found for confirmation action");
}
return;
}).catch(() => {
return;