mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-77168 backup: Switch from YUI to confirmation modal
This commit is contained in:
parent
2078efeca9
commit
6a417a3632
7 changed files with 30 additions and 307 deletions
|
@ -134,7 +134,36 @@ abstract class base_moodleform extends moodleform {
|
||||||
$buttonarray[] = $this->_form->createElement('submit', 'oneclickbackup', get_string('jumptofinalstep', 'backup'),
|
$buttonarray[] = $this->_form->createElement('submit', 'oneclickbackup', get_string('jumptofinalstep', 'backup'),
|
||||||
array('class' => 'oneclickbackup'));
|
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(
|
$buttonarray[] = $this->_form->createElement(
|
||||||
'submit',
|
'submit',
|
||||||
'submitbutton',
|
'submitbutton',
|
||||||
|
@ -383,24 +412,6 @@ abstract class base_moodleform extends moodleform {
|
||||||
|
|
||||||
$this->require_definition_after_data();
|
$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.
|
// Get list of module types on course.
|
||||||
$modinfo = get_fast_modinfo($COURSE);
|
$modinfo = get_fast_modinfo($COURSE);
|
||||||
$modnames = array_map('strval', $modinfo->get_used_module_names(true));
|
$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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue