ED-549 Assign learner to a cohort before registration.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
/* globals _, NotificationModel, NotificationView, interpolate_text */
|
||||
(function(define) {
|
||||
'use strict';
|
||||
define(['backbone', 'underscore', 'jquery', 'gettext', 'js/groups/views/cohort_form', 'string_utils',
|
||||
'js/models/notification', 'js/views/notification'],
|
||||
'js/models/notification', 'js/views/notification'],
|
||||
function(Backbone, _, $, gettext, CohortFormView) {
|
||||
var CohortEditorView = Backbone.View.extend({
|
||||
|
||||
@@ -24,6 +25,8 @@
|
||||
errorNotifications: null,
|
||||
// Any confirmation messages that are currently being displayed (for example, number of students added).
|
||||
confirmationNotifications: null,
|
||||
// Any messages about preassigned email addresses currently being displayed to the instructor.
|
||||
preassignedNotifications: null,
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template({
|
||||
@@ -47,13 +50,18 @@
|
||||
},
|
||||
|
||||
selectTab: function(event) {
|
||||
var tabElement = $(event.currentTarget),
|
||||
tabName = tabElement.data('tab');
|
||||
var $tabElement = $(event.currentTarget),
|
||||
tabName = $tabElement.data('tab');
|
||||
event.preventDefault();
|
||||
this.$('.wrapper-tabs .tab').removeClass('is-selected');
|
||||
this.$('.wrapper-tabs .tab').find('span.sr').remove();
|
||||
tabElement.addClass('is-selected');
|
||||
tabElement.find('a').prepend('<span class="sr">' + gettext('Selected tab') + ' </span>');
|
||||
$tabElement.addClass('is-selected');
|
||||
edx.HtmlUtils.prepend(
|
||||
$($tabElement.find('a')),
|
||||
edx.HtmlUtils.interpolateHtml('<span class="sr"> {selectedTab} </span>',
|
||||
{selectedTab: gettext('Selected tab')}
|
||||
)
|
||||
);
|
||||
this.$('.tab-content').addClass('is-hidden');
|
||||
this.$('.tab-content-' + tabName).removeClass('is-hidden').focus();
|
||||
},
|
||||
@@ -108,7 +116,7 @@
|
||||
}
|
||||
});
|
||||
}).fail(function() {
|
||||
self.showErrorMessage(gettext('Error adding students.'), true);
|
||||
self.showErrorMessage(gettext('Error adding learners.'), true);
|
||||
});
|
||||
} else {
|
||||
self.showErrorMessage(gettext('Enter a username or email.'), true);
|
||||
@@ -151,18 +159,20 @@
|
||||
},
|
||||
|
||||
addNotifications: function(modifiedUsers) {
|
||||
var oldCohort, title, details, numPresent, numUsersAdded, numErrors,
|
||||
createErrorDetails, errorActionCallback, errorModel,
|
||||
var oldCohort, title, details, numPresent, numUsersAdded, numPreassigned,
|
||||
numErrors, createErrorDetails, errorActionCallback, errorModel, i,
|
||||
errorLimit = 5;
|
||||
|
||||
// Show confirmation messages.
|
||||
this.undelegateViewEvents(this.confirmationNotifications);
|
||||
numUsersAdded = modifiedUsers.added.length + modifiedUsers.changed.length;
|
||||
numPresent = modifiedUsers.present.length;
|
||||
numPreassigned = modifiedUsers.preassigned.length;
|
||||
title = '';
|
||||
if (numUsersAdded > 0 || numPresent > 0) {
|
||||
title = interpolate_text(
|
||||
ngettext('{numUsersAdded} student has been added to this cohort',
|
||||
'{numUsersAdded} students have been added to this cohort', numUsersAdded),
|
||||
title += interpolate_text(
|
||||
ngettext('{numUsersAdded} learner has been added to this cohort. ',
|
||||
'{numUsersAdded} learners have been added to this cohort. ', numUsersAdded),
|
||||
{numUsersAdded: numUsersAdded}
|
||||
);
|
||||
|
||||
@@ -171,27 +181,28 @@
|
||||
oldCohort = changedInfo.previous_cohort;
|
||||
if (oldCohort in movedByCohort) {
|
||||
movedByCohort[oldCohort] = movedByCohort[oldCohort] + 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
movedByCohort[oldCohort] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
details = [];
|
||||
for (oldCohort in movedByCohort) {
|
||||
|
||||
_.each(movedByCohort, function(numMoved, prevCohort) {
|
||||
details.push(
|
||||
interpolate_text(
|
||||
ngettext('{numMoved} student was removed from {oldCohort}',
|
||||
'{numMoved} students were removed from {oldCohort}', movedByCohort[oldCohort]),
|
||||
{numMoved: movedByCohort[oldCohort], oldCohort: oldCohort}
|
||||
ngettext('{numMoved} learner was moved from {prevCohort}',
|
||||
'{numMoved} learners were moved from {prevCohort}', numMoved),
|
||||
{numMoved: numMoved, prevCohort: prevCohort}
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (numPresent > 0) {
|
||||
details.push(
|
||||
interpolate_text(
|
||||
ngettext('{numPresent} student was already in the cohort',
|
||||
'{numPresent} students were already in the cohort', numPresent),
|
||||
ngettext('{numPresent} learner was already in the cohort',
|
||||
'{numPresent} learners were already in the cohort', numPresent),
|
||||
{numPresent: numPresent}
|
||||
)
|
||||
);
|
||||
@@ -206,35 +217,81 @@
|
||||
})
|
||||
});
|
||||
this.confirmationNotifications.render();
|
||||
}
|
||||
else if (this.confirmationNotifications) {
|
||||
} else if (this.confirmationNotifications) {
|
||||
this.confirmationNotifications.$el.html('');
|
||||
this.confirmationNotifications = null;
|
||||
}
|
||||
|
||||
// Show preassigned email addresses.
|
||||
this.undelegateViewEvents(this.preassignedNotifications);
|
||||
if (numPreassigned > 0) {
|
||||
details = [];
|
||||
for (i = 0; i < modifiedUsers.preassigned.length; i++) {
|
||||
details.push(interpolate_text(gettext('{email}'),
|
||||
{email: modifiedUsers.preassigned[i]}));
|
||||
}
|
||||
|
||||
title = (
|
||||
interpolate_text(
|
||||
ngettext('{numPreassigned} learner was pre-assigned for this cohort. ' +
|
||||
'This learner will automatically be added to the cohort when ' +
|
||||
'they enroll in the course.',
|
||||
'{numPreassigned} learners were pre-assigned for this cohort. ' +
|
||||
'These learners will automatically be added to the cohort when ' +
|
||||
'they enroll in the course.',
|
||||
numPreassigned),
|
||||
{numPreassigned: numPreassigned}
|
||||
)
|
||||
);
|
||||
|
||||
this.preassignedNotifications = new NotificationView({
|
||||
el: this.$('.cohort-preassigned'),
|
||||
model: new NotificationModel({
|
||||
type: 'warning',
|
||||
title: title,
|
||||
details: details
|
||||
})
|
||||
});
|
||||
this.preassignedNotifications.render();
|
||||
} else if (this.preassignedNotifications) {
|
||||
this.preassignedNotifications.$el.html('');
|
||||
this.preassignedNotifications = null;
|
||||
}
|
||||
|
||||
// Show error messages.
|
||||
this.undelegateViewEvents(this.errorNotifications);
|
||||
numErrors = modifiedUsers.unknown.length;
|
||||
numErrors = modifiedUsers.unknown.length + modifiedUsers.invalid.length;
|
||||
if (numErrors > 0) {
|
||||
createErrorDetails = function(unknownUsers, showAllErrors) {
|
||||
var numErrors = unknownUsers.length, details = [];
|
||||
createErrorDetails = function(unknownUsers, invalidEmails, showAllErrors) {
|
||||
var unknownErrorsShown = showAllErrors ? unknownUsers.length :
|
||||
Math.min(errorLimit, unknownUsers.length);
|
||||
var invalidErrorsShown = showAllErrors ? invalidEmails.length :
|
||||
Math.min(errorLimit - unknownUsers.length, invalidEmails.length);
|
||||
details = [];
|
||||
|
||||
for (var i = 0; i < (showAllErrors ? numErrors : Math.min(errorLimit, numErrors)); i++) {
|
||||
details.push(interpolate_text(gettext('Unknown user: {user}'), {user: unknownUsers[i]}));
|
||||
|
||||
for (i = 0; i < unknownErrorsShown; i++) {
|
||||
details.push(interpolate_text(gettext('Unknown username: {user}'),
|
||||
{user: unknownUsers[i]}));
|
||||
}
|
||||
for (i = 0; i < invalidErrorsShown; i++) {
|
||||
details.push(interpolate_text(gettext('Invalid email address: {email}'),
|
||||
{email: invalidEmails[i]}));
|
||||
}
|
||||
return details;
|
||||
};
|
||||
|
||||
title = interpolate_text(
|
||||
ngettext('There was an error when trying to add students:',
|
||||
'There were {numErrors} errors when trying to add students:', numErrors),
|
||||
ngettext('There was an error when trying to add learners:',
|
||||
'{numErrors} learners could not be added to this cohort:', numErrors),
|
||||
{numErrors: numErrors}
|
||||
);
|
||||
details = createErrorDetails(modifiedUsers.unknown, false);
|
||||
details = createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, false);
|
||||
|
||||
errorActionCallback = function(view) {
|
||||
view.model.set('actionText', null);
|
||||
view.model.set('details', createErrorDetails(modifiedUsers.unknown, true));
|
||||
view.model.set('details',
|
||||
createErrorDetails(modifiedUsers.unknown, modifiedUsers.invalid, true));
|
||||
view.render();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user