MDL-43232 JavaSript: Migrate moodle-backup-confirmcancel to use Shifter

This commit is contained in:
Andrew Nicols 2013-12-06 08:16:33 +08:00
parent 9b37cd72a2
commit 078d8c6e70
8 changed files with 262 additions and 31 deletions

View file

@ -340,7 +340,7 @@ abstract class base_moodleform extends moodleform {
$config->yesLabel = get_string('confirmcancelyes', 'backup'); $config->yesLabel = get_string('confirmcancelyes', 'backup');
$config->noLabel = get_string('confirmcancelno', 'backup'); $config->noLabel = get_string('confirmcancelno', 'backup');
$config->closeButtonTitle = get_string('close', 'editor'); $config->closeButtonTitle = get_string('close', 'editor');
$PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_cancel_buttons', array($config)); $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);

View file

@ -0,0 +1,82 @@
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();
// Simulate the original cancel button click.
c.currentTarget.simulate('click');
}, this);
// Show the confirm box.
confirm.show();
}
};
}, '@VERSION@', {"requires": ["node", "node-event-simulate", "moodle-core-notification-confirm"]});

View file

@ -0,0 +1 @@
YUI.add("moodle-backup-confirmcancel",function(e,t){M.core_backup=M.core_backup||{},M.core_backup.confirmcancel={listeners:[],config:{},watch_cancel_buttons:function(t){this.config=t,this.listeners.push(e.one(e.config.doc.body).delegate("click",this.confirm_cancel,".confirmcancel",this))},confirm_cancel:function(t){t.preventDefault();var n=new M.core.confirm(this.config);n.on("complete-yes",function(){(new e.EventHandle(M.core_backup.confirmcancel.listeners)).detach(),c.currentTarget.simulate("click")},this),n.show()}}},"@VERSION@",{requires:["node","node-event-simulate","moodle-core-notification-confirm"]});

View file

@ -0,0 +1,82 @@
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();
// Simulate the original cancel button click.
c.currentTarget.simulate('click');
}, this);
// Show the confirm box.
confirm.show();
}
};
}, '@VERSION@', {"requires": ["node", "node-event-simulate", "moodle-core-notification-confirm"]});

View file

@ -1,30 +0,0 @@
YUI.add('moodle-backup-confirmcancel', function(Y) {
// Namespace for the backup
M.core_backup = M.core_backup || {};
/**
* Adds confirmation dialogues to the cancel buttons on the page.
*
* @param {object} config
*/
M.core_backup.watch_cancel_buttons = function(config) {
Y.all('.confirmcancel').each(function(){
this._confirmationListener = this._confirmationListener || this.on('click', function(e){
// Prevent the default event (sumbit) from firing
e.preventDefault();
// Create the confirm box
var confirm = new M.core.confirm(config);
// If the user clicks yes
confirm.on('complete-yes', function(e){
// Detach the listener for the confirm box so it doesn't fire again.
this._confirmationListener.detach();
// Simulate the original cancel button click
this.simulate('click');
}, this);
// Show the confirm box
confirm.show();
}, this);
});
}
}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-core-notification']});

View file

@ -0,0 +1,10 @@
{
"name": "moodle-backup-confirmcancel",
"builds": {
"moodle-backup-confirmcancel": {
"jsfiles": [
"confirmcancel.js"
]
}
}
}

View file

@ -0,0 +1,77 @@
/**
* 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();
// Simulate the original cancel button click.
c.currentTarget.simulate('click');
}, this);
// Show the confirm box.
confirm.show();
}
};

View file

@ -0,0 +1,9 @@
{
"moodle-backup-confirmcancel": {
"requires": [
"node",
"node-event-simulate",
"moodle-core-notification-confirm"
]
}
}