Commit b56dc2a1 authored by Abdullah Albanyan's avatar Abdullah Albanyan
Browse files

MDL-60002 js: Added a 'Save and show next' button to grading interface.

parent 23ab0d77
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -234,6 +234,7 @@ define(['jquery', 'mod_assign/grading_events'], function($, GradingEvents) {
$(document).on('user-changed', this._showActionsForm.bind(this));
this._region.find('[name="savechanges"]').on('click', this._trigger.bind(this, 'save-changes'));
this._region.find('[name="saveandshownext"]').on('click', this._trigger.bind(this, 'save-and-show-next'));
this._region.find('[name="resetbutton"]').on('click', this._trigger.bind(this, 'reset'));
this._region.find('form').on('submit', function(e) {
e.preventDefault();
......
......@@ -50,6 +50,7 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
this._region.find('[data-region="user-filters"]').on('click', this._toggleExpandFilters.bind(this));
$(document).on('user-changed', this._refreshSelector.bind(this));
$(document).on('done-saving-show-next', this._handleNextUser.bind(this));
// Position the configure filters panel under the link that expands it.
var toggleLink = this._region.find('[data-region="user-filters"]');
......@@ -361,8 +362,9 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
* Change to the next user in the grading list.
*
* @param {Event} e
* @param {Boolean} saved Has the form already been saved? Skips checking for changes if true.
*/
GradingNavigation.prototype._handleNextUser = function(e) {
GradingNavigation.prototype._handleNextUser = function(e, saved) {
e.preventDefault();
var select = this._region.find('[data-action=change-user]');
var currentUserId = select.attr('data-selected');
......@@ -379,7 +381,15 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
var count = this._filteredUsers.length;
var newIndex = (currentIndex + 1) % count;
if (count) {
if (saved && count) {
// If we've already saved the grade, skip checking if we've made any changes.
var userid = this._filteredUsers[newIndex].id;
var useridnumber = parseInt(userid, 10);
select.attr('data-selected', userid);
if (!isNaN(useridnumber) && useridnumber > 0) {
$(document).trigger('user-changed', userid);
}
} else if (count) {
this._selectUserById(this._filteredUsers[newIndex].id);
}
};
......
......@@ -99,9 +99,10 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
* @private
* @param {Object} event
* @param {Integer} nextUserId
* @param {Boolean} nextUser optional. Load next user in the grading list.
* @method _submitForm
*/
GradingPanel.prototype._submitForm = function(event, nextUserId) {
GradingPanel.prototype._submitForm = function(event, nextUserId, nextUser) {
// The form was submitted - send it via ajax instead.
var form = $(this._region.find('form.gradeform'));
......@@ -118,7 +119,7 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
ajax.call([{
methodname: 'mod_assign_submit_grading_form',
args: {assignmentid: assignmentid, userid: this._lastUserId, jsonformdata: JSON.stringify(data)},
done: this._handleFormSubmissionResponse.bind(this, data, nextUserId),
done: this._handleFormSubmissionResponse.bind(this, data, nextUserId, [], nextUser),
fail: notification.exception
}]);
};
......@@ -131,8 +132,9 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
* @param {Array} formdata - submitted values
* @param {Integer} nextUserId - optional. The id of the user to load after the form is saved.
* @param {Array} response List of errors.
* @param {Boolean} nextUser - optional. If true, switch to next user in the grading list.
*/
GradingPanel.prototype._handleFormSubmissionResponse = function(formdata, nextUserId, response) {
GradingPanel.prototype._handleFormSubmissionResponse = function(formdata, nextUserId, response, nextUser) {
if (typeof nextUserId === "undefined") {
nextUserId = this._lastUserId;
}
......@@ -152,6 +154,8 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
});
if (nextUserId == this._lastUserId) {
$(document).trigger('reset', nextUserId);
} else if (nextUser) {
$(document).trigger('done-saving-show-next', true);
} else {
$(document).trigger('user-changed', nextUserId);
}
......@@ -353,6 +357,7 @@ define(['jquery', 'core/yui', 'core/notification', 'core/templates', 'core/fragm
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('reset', this._resetForm.bind(this));
docElement.on('save-form-state', this._saveFormState.bind(this));
......
......@@ -36,6 +36,7 @@
{{#defaultsendnotifications}}checked="checked"{{/defaultsendnotifications}} />
</label>
<button type="submit" class="btn btn-primary" name="savechanges">{{#str}}savechanges{{/str}}</button>
<button type="submit" class="btn btn-primary" name="saveandshownext">{{#str}}saveandnext{{/str}}</button>
<button type="submit" class="btn" name="resetbutton">{{#str}}reset{{/str}}</button>
</form>
{{#showreview}}
......
......@@ -45,6 +45,7 @@
{{#defaultsendnotifications}}checked="checked"{{/defaultsendnotifications}} />
</label>
<button type="submit" class="btn btn-primary" name="savechanges">{{#str}}savechanges{{/str}}</button>
<button type="submit" class="btn btn-primary" name="saveandshownext">{{#str}}saveandnext{{/str}}</button>
<button type="submit" class="btn btn-secondary" name="resetbutton">{{#str}}reset{{/str}}</button>
</form>
{{#js}}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment