$config->yesLabel = get_string('confirmcancelyes', 'backup');
$config->noLabel = get_string('confirmcancelno', 'backup');
$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.
$modinfo = get_fast_modinfo($COURSE);
+++ /dev/null
-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']});
--- /dev/null
+{
+ "name": "moodle-backup-confirmcancel",
+ "builds": {
+ "moodle-backup-confirmcancel": {
+ "jsfiles": [
+ "confirmcancel.js"
+ ]
+ }
+ }
+}
--- /dev/null
+/**
+ * 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();
+ }
+};
--- /dev/null
+{
+ "moodle-backup-confirmcancel": {
+ "requires": [
+ "node",
+ "node-event-simulate",
+ "moodle-core-notification-confirm"
+ ]
+ }
+}