MDL-54796 forms: Editor restore event created.
authorAdrian Greeve <adrian@moodle.com>
Tue, 19 Jul 2016 03:54:50 +0000 (11:54 +0800)
committerAdrian Greeve <adrian@moodle.com>
Mon, 25 Jul 2016 02:42:58 +0000 (10:42 +0800)
The editor restore event is currently being subscribed
to by the change checkers to refresh their savedstate.

17 files changed:
lib/amd/build/event.min.js
lib/amd/src/event.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js
lib/editor/atto/yui/src/editor/js/autosave.js
lib/yui/build/moodle-core-event/moodle-core-event-debug.js
lib/yui/build/moodle-core-event/moodle-core-event-min.js
lib/yui/build/moodle-core-event/moodle-core-event.js
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/event/js/event.js
lib/yui/src/formchangechecker/js/formchangechecker.js
lib/yui/src/formchangechecker/meta/formchangechecker.json
mod/assign/amd/build/grading_panel.min.js
mod/assign/amd/src/grading_panel.js

index 86a6407..39b9bb5 100644 (file)
Binary files a/lib/amd/build/event.min.js and b/lib/amd/build/event.min.js differ
index b43c704..0923668 100644 (file)
@@ -38,7 +38,7 @@ define(['jquery', 'core/yui'],
             nodes = $(nodes);
             Y.use('event', 'moodle-core-event', function(Y) {
                 // Trigger it the JQuery way.
-                $('document').trigger(M.core.event.FILTER_CONTENT_UPDATED, nodes);
+                $(document).trigger(M.core.event.FILTER_CONTENT_UPDATED, nodes);
 
                 // Create a YUI NodeList from our JQuery Object.
                 var yuiNodes = new Y.NodeList(nodes.get());
@@ -47,6 +47,20 @@ define(['jquery', 'core/yui'],
                 Y.fire(M.core.event.FILTER_CONTENT_UPDATED, {nodes: yuiNodes});
             });
         },
+        /**
+         * Trigger an event using both JQuery and YUI
+         * This event alerts the world that the editor has restored some content.
+         *
+         * @method notifyEditorContentRestored
+         */
+        notifyEditorContentRestored: function() {
+            Y.use('event', 'moodle-core-event', function(Y) {
+                // Trigger it the JQuery way.
+                $(document).trigger(M.core.event.EDITOR_CONTENT_RESTORED);
 
+                // And again for YUI.
+                Y.fire(M.core.event.EDITOR_CONTENT_RESTORED);
+            });
+        },
     };
 });
index 3320709..542e509 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js differ
index 4a4d051..dd58489 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js differ
index 4680aef..8384b85 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js differ
index 7df539e..9430557 100644 (file)
@@ -206,6 +206,11 @@ EditorAutosave.prototype = {
         this.showMessage(M.util.get_string('textrecovered', 'editor_atto'),
                 NOTIFY_INFO, RECOVER_MESSAGE_TIMEOUT);
 
+        // Fire an event that the editor content has changed.
+        require(['core/event'], function(event) {
+            event.notifyEditorContentRestored();
+        });
+
         return this;
     },
 
index 75d33c1..1dd7edc 100644 (file)
Binary files a/lib/yui/build/moodle-core-event/moodle-core-event-debug.js and b/lib/yui/build/moodle-core-event/moodle-core-event-debug.js differ
index 7a13d0d..ae188f2 100644 (file)
Binary files a/lib/yui/build/moodle-core-event/moodle-core-event-min.js and b/lib/yui/build/moodle-core-event/moodle-core-event-min.js differ
index a54d395..847ca8f 100644 (file)
Binary files a/lib/yui/build/moodle-core-event/moodle-core-event.js and b/lib/yui/build/moodle-core-event/moodle-core-event.js differ
index 6fbee86..4b4f09a 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 af2f3e2..6e2c93e 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 6fbee86..4b4f09a 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 f30f900..8ceff44 100644 (file)
@@ -39,7 +39,15 @@ M.core.event = M.core.event || {
      * @event "filter-content-updated"
      * @param nodes {Y.NodeList} List of nodes added to the DOM.
      */
-    FILTER_CONTENT_UPDATED: "filter-content-updated"
+    FILTER_CONTENT_UPDATED: "filter-content-updated",
+    /**
+     * This event is triggered when an editor has recovered some draft text.
+     * It can be used to determine let other sections know that they should reset their
+     * form comparison for changes.
+     *
+     * @event "editor-content-restored"
+     */
+    EDITOR_CONTENT_RESTORED: "editor-content-restored"
 };
 
 M.core.globalEvents = M.core.globalEvents || {
index db1023f..998bcd5 100644 (file)
@@ -36,6 +36,9 @@ Y.extend(FORMCHANGECHECKER, Y.Base, {
                 return;
             }
 
+            // Add a listener here for an editor restore event.
+            Y.on(M.core.event.EDITOR_CONTENT_RESTORED, M.core_formchangechecker.reset_form_dirty_state, this);
+
             // Add change events to the form elements
             currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'input', this);
             currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'textarea', this);
index ca81382..8490d8b 100644 (file)
@@ -2,7 +2,8 @@
   "moodle-core-formchangechecker": {
     "requires": [
       "base",
-      "event-focus"
+      "event-focus",
+      "moodle-core-event"
     ]
   }
 }
index 8f5faad..012556a 100644 (file)
Binary files a/mod/assign/amd/build/grading_panel.min.js and b/mod/assign/amd/build/grading_panel.min.js differ
index 4809c75..7cb42fb 100644 (file)
@@ -282,6 +282,11 @@ define(['jquery', 'core/notification', 'core/templates', 'core/fragment',
                         this._niceReplaceNodeContents(this._region, html, js)
                         .done(function() {
                             checker.saveFormState('[data-region="grade-panel"] .gradeform');
+                            $(document).on('editor-content-restored', function() {
+                                // If the editor has some content that has been restored
+                                // then save the form state again for comparison.
+                                checker.saveFormState('[data-region="grade-panel"] .gradeform');
+                            });
                             $('[data-region="attempt-chooser"]').on('click', this._chooseAttempt.bind(this));
                             this._addPopoutButtons('[data-region="grade-panel"] .gradeform');
                             $(document).trigger('finish-loading-user');