Merge branch 'MDL-51292-master' of git://github.com/cameron1729/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 30 Sep 2015 15:32:57 +0000 (17:32 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 30 Sep 2015 15:32:57 +0000 (17:32 +0200)
lib/outputrenderers.php
lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js
lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js
lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js
lib/yui/src/formchangechecker/js/formchangechecker.js
message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js
message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js
message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js
message/yui/src/messenger/js/sendmessage.js

index 435dec2..97abc70 100644 (file)
@@ -3987,6 +3987,7 @@ EOD;
                         'page' => $this->page
                     )
                 );
+                $this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
             }
         }
 
index 868751f..6fbee86 100644 (file)
Binary files a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js and b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js differ
index 505dbe8..af2f3e2 100644 (file)
Binary files a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js and b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js differ
index 868751f..6fbee86 100644 (file)
Binary files a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js and b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js differ
index ae0d809..db1023f 100644 (file)
@@ -176,6 +176,14 @@ M.core_formchangechecker.get_form_dirty_state = function() {
     return 0;
 };
 
+/*
+ * Reset the form state
+ */
+M.core_formchangechecker.reset_form_dirty_state = function() {
+    M.core_formchangechecker.stateinformation.formsubmitted = false;
+    M.core_formchangechecker.stateinformation.formchanged = false;
+};
+
 /*
  * Return a suitable message if changes have been made to a form
  */
index 1c604a8..3d73d5d 100644 (file)
Binary files a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js and b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js differ
index 82fe415..8f60a30 100644 (file)
Binary files a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js and b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js differ
index 1c604a8..3d73d5d 100644 (file)
Binary files a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js and b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js differ
index 51d81eb..8998638 100644 (file)
@@ -60,7 +60,7 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M.
 
     _bb: null,
     _sendLock: false,
-
+    _hide: null,
     /**
      * Initializer.
      *
@@ -71,10 +71,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M.
             content;
 
         this._bb = this.get('boundingBox');
+        this._hide = this.hide;
 
         // Prepare the content area.
         tpl = Y.Handlebars.compile(
-            '<form action="#">' +
+            '<form action="#" id="messageform">' +
                 '<div class="{{CSSR.INPUTAREA}}">' +
                     '<label class="{{CSSR.ACCESSHIDE}}" for="{{id}}">{{labelStr}}</label>' +
                     '<textarea class="{{CSSR.INPUT}}" id="{{id}}"></textarea>' +
@@ -131,6 +132,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M.
 
         // Set the content as empty and lock send.
         this._bb.one(SELECTORS.SENDMSGDIALOG.INPUT).set('value', '');
+
+        // Register form with formchangechecker
+        Y.use('moodle-core-formchangechecker', function() {
+            M.core_formchangechecker.init({formid: "messageform"});
+        });
     },
 
     /**
@@ -204,6 +210,33 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M.
         });
     },
 
+    /**
+     * Override the default hide function.
+     * @method hide
+     */
+    hide: function() {
+        var self = this;
+
+        if (!M.core_formchangechecker.get_form_dirty_state()) {
+            return SENDMSGDIALOG.superclass.hide.call(this, arguments);
+        }
+
+        Y.use('moodle-core-notification-confirm', function() {
+            var confirm = new M.core.confirm({
+                title : M.util.get_string('confirm', 'moodle'),
+                question : M.util.get_string('changesmadereallygoaway', 'moodle'),
+                yesLabel : M.util.get_string('confirm', 'moodle'),
+                noLabel : M.util.get_string('cancel', 'moodle')
+            });
+            confirm.on('complete-yes', function() {
+                M.core_formchangechecker.reset_form_dirty_state();
+                confirm.hide();
+                confirm.destroy();
+                return SENDMSGDIALOG.superclass.hide.call(this, arguments);
+            }, self);
+        });
+    },
+
     /**
      * Show a notice.
      *