backup MDL-23727 The proceed button is now to the right of the screen and the cancel...
authorSam Hemelryk <sam@moodle.com>
Tue, 17 Aug 2010 05:21:57 +0000 (05:21 +0000)
committerSam Hemelryk <sam@moodle.com>
Tue, 17 Aug 2010 05:21:57 +0000 (05:21 +0000)
backup/util/ui/base_moodleform.class.php
backup/util/ui/renderer.php
backup/util/ui/yui/confirmcancel/confirmcancel.js [new file with mode: 0644]
lang/en/backup.php

index 3b88377..a101344 100644 (file)
@@ -93,16 +93,25 @@ abstract class base_moodleform extends moodleform {
     /**
      * Definition applied after the data is organised.. why's it here? because I want
      * to add elements on the fly.
+     * @global moodle_page $PAGE
      */
     function definition_after_data() {
+        global $PAGE;
         $buttonarray=array();
+        $buttonarray[] = $this->_form->createElement('submit', 'submitbutton', get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'), array('class'=>'proceedbutton'));
         if (!$this->uistage->is_first_stage()) {
             $buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage','backup'));
         }
-        $buttonarray[] = $this->_form->createElement('submit', 'submitbutton', get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'));
-        $buttonarray[] = $this->_form->createElement('cancel');
+        $buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class'=>'confirmcancel'));
         $this->_form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
         $this->_form->closeHeaderBefore('buttonar');
+
+        $config = new stdClass;
+        $config->title = get_string('confirmcancel', 'backup');
+        $config->question = get_string('confirmcancelquestion', 'backup');
+        $config->yesLabel = get_string('confirmcancelyes', 'backup');
+        $config->noLabel = get_string('confirmcancelno', 'backup');
+        $PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_cancel_buttons', array($config));
     }
     /**
      * Closes any open divs
index 47995eb..85d6cbd 100644 (file)
@@ -146,9 +146,9 @@ class core_backup_renderer extends plugin_renderer_base {
         }
         $html .= html_writer::end_tag('div');
         $html .= html_writer::end_tag('div');
-        $html .= html_writer::end_tag('div');
 
         $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
+        $html .= html_writer::end_tag('div');
 
         return $html;
     }
diff --git a/backup/util/ui/yui/confirmcancel/confirmcancel.js b/backup/util/ui/yui/confirmcancel/confirmcancel.js
new file mode 100644 (file)
index 0000000..84ed407
--- /dev/null
@@ -0,0 +1,30 @@
+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','moodle-enrol-notification']});
\ No newline at end of file
index 08f7f3f..b339721 100644 (file)
@@ -58,6 +58,11 @@ $string['configgeneralroleassignments'] = 'If enabled by default roles assignmen
 $string['configgeneraluserscompletion'] = 'If enabled user completion information will be included in backups by default.';
 $string['configgeneraluserfiles'] = 'Sets the default for whether user files will be included in backups.';
 $string['configgeneralusers'] = 'Sets the default for whether to include users in backups.';
+$string['confirmcancel'] = 'Cancel backup';
+$string['confirmcancelquestion'] = 'Are you sure you wish to cancel?
+Any information you have entered will be lost.';
+$string['confirmcancelyes'] = 'Cancel';
+$string['confirmcancelno'] = 'Stay';
 $string['coursecategory'] = 'Category the course will be restored into';
 $string['courseid'] = 'Original ID';
 $string['coursesettings'] = 'Course settings';