MDL-60430 assignment: Assignment save and show next for 1 user
authorMihail Geshoski <mihail@moodle.com>
Wed, 25 Oct 2017 06:18:16 +0000 (14:18 +0800)
committerMihail Geshoski <mihail@moodle.com>
Wed, 25 Oct 2017 06:18:16 +0000 (14:18 +0800)
mod/assign/amd/build/grading_navigation.min.js
mod/assign/amd/build/grading_panel.min.js
mod/assign/amd/src/grading_navigation.js
mod/assign/amd/src/grading_panel.js

index 159e855..bc111f0 100644 (file)
Binary files a/mod/assign/amd/build/grading_navigation.min.js and b/mod/assign/amd/build/grading_navigation.min.js differ
index cf2deb2..ed1ab5c 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 f5a373c..f8f1758 100644 (file)
@@ -130,6 +130,7 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
         } else {
             this._selectNoUser();
         }
+        this._triggerNextUserEvent();
     };
 
     /**
@@ -233,6 +234,7 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
         } else {
             this._selectNoUser();
         }
+        this._triggerNextUserEvent();
     };
 
     /**
@@ -447,6 +449,20 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
         this._refreshCount();
     };
 
+    /**
+     * Trigger the next user event depending on the number of filtered users
+     *
+     * @private
+     * @method _triggerNextUserEvent
+     */
+    GradingNavigation.prototype._triggerNextUserEvent = function() {
+        if (this._filteredUsers.length > 1) {
+            $(document).trigger('next-user', {nextUserId: null, nextUser: true});
+        } else {
+            $(document).trigger('next-user', {nextUser: false});
+        }
+    };
+
     /**
      * Change to a different user in the grading list.
      *
index ee0ab1c..a9abbac 100644 (file)
@@ -54,6 +54,12 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
     /** @type {JQuery} JQuery node for the page region containing the user navigation. */
     GradingPanel.prototype._region = null;
 
+     /** @type {Integer} The id of the next user in the grading list */
+    GradingPanel.prototype.nextUserId = null;
+
+     /** @type {Boolean} Next user exists in the grading list */
+    GradingPanel.prototype.nextUser = false;
+
     /**
      * Fade the dom node out, update it, and fade it back.
      *
@@ -314,6 +320,29 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
         }.bind(this)).fail(notification.exception);
     };
 
+    /**
+     * Get next user data and store it in global variables
+     *
+     * @private
+     * @method _getNextUser
+     * @param {Event} event
+     * @param {Object} data Next user's data
+     */
+    GradingPanel.prototype._getNextUser = function(event, data) {
+        this.nextUserId = data.nextUserId;
+        this.nextUser = data.nextUser;
+    };
+
+    /**
+     * Handle the save-and-show-next event
+     *
+     * @private
+     * @method _handleSaveAndShowNext
+     */
+    GradingPanel.prototype._handleSaveAndShowNext = function() {
+        this._submitForm(null, this.nextUserId, this.nextUser);
+    };
+
     /**
      * Get the grade panel element.
      *
@@ -355,9 +384,10 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
             e.preventDefault();
         });
 
+        docElement.on('next-user', this._getNextUser.bind(this));
         docElement.on('user-changed', this._refreshGradingPanel.bind(this));
         docElement.on('save-changes', this._submitForm.bind(this));
-        docElement.on('save-and-show-next', this._submitForm.bind(this, null, null, true));
+        docElement.on('save-and-show-next', this._handleSaveAndShowNext.bind(this));
         docElement.on('reset', this._resetForm.bind(this));
 
         docElement.on('save-form-state', this._saveFormState.bind(this));