Skip to content

Commit

Permalink
MDL-57604 mod_assign: fix incorrect user being selector from chooser
Browse files Browse the repository at this point in the history
Previously there was a logic bug where by if some students were filtered
from the list, the label for another student could be attached to the
'filered' student.

This fix reworks the promises a bit so we render the student summary and
then build an row with the explict user id, rather than itterating through
the array later.

I also remove the storing of the initial promise in a varible because
this is an easy way to introduce a bug (not waiting for the .then()
chained promise)
  • Loading branch information
danpoltawski committed Jan 9, 2017
1 parent a09a987 commit fb5655b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mod/assign/amd/build/participant_selector.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions mod/assign/amd/src/participant_selector.js
Expand Up @@ -62,12 +62,10 @@ define(['core/ajax', 'jquery', 'core/templates'], function(ajax, $, templates) {
filterstrings[$(element).attr('name')] = $(element).prop('checked');
});

var promise = ajax.call([{
ajax.call([{
methodname: 'mod_assign_list_participants',
args: {assignid: assignmentid, groupid: groupid, filter: query, limit: 30, includeenrolments: false}
}]);

promise[0].then(function(results) {
}])[0].then(function(results) {
var promises = [];
var identityfields = $('[data-showuseridentity]').data('showuseridentity').split(',');

Expand All @@ -94,23 +92,18 @@ define(['core/ajax', 'jquery', 'core/templates'], function(ajax, $, templates) {
}
});
ctx.identity = identity.join(', ');
promises.push(templates.render('mod_assign/list_participant_user_summary', ctx));
promises.push(templates.render('mod_assign/list_participant_user_summary', ctx).then(function(html) {
return {id: user.id, label: html};
}));
}
});

// When all the templates have been rendered, call the success handler.
$.when.apply($.when, promises).then(function() {
var args = arguments,
i = 0;

$.each(results, function(index, user) {
user.label = args[i];
i++;
});

success(results);
});
}, failure);
// Do the dance for $.when()
return $.when.apply($, promises);
}).then(function() {
// Undo the $.when() dance from arguments object into an array..
var users = Array.prototype.slice.call(arguments);
success(users);
}).catch(failure);
}
};
});

0 comments on commit fb5655b

Please sign in to comment.