Commit fc5b94ee by Andy Armstrong

Address most of Christina's code review comments

parent 8e787b4f
...@@ -201,7 +201,7 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -201,7 +201,7 @@ class MembershipPageCohortManagementSection(PageObject):
select = self.q(css=self._bounded_selector(self.content_group_selector)) select = self.q(css=self._bounded_selector(self.content_group_selector))
groups = [] groups = []
for option in select: for option in select:
if option.text != "Choose a content group to associate": if option.text != "":
groups.append(option.text) groups.append(option.text)
return groups return groups
...@@ -213,7 +213,7 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -213,7 +213,7 @@ class MembershipPageCohortManagementSection(PageObject):
""" """
self.select_cohort_settings() self.select_cohort_settings()
radio_button = self.q(css=self._bounded_selector(self.no_content_group_button)).results[0] radio_button = self.q(css=self._bounded_selector(self.no_content_group_button)).results[0]
if radio_button.get_attribute("checked") == "true": if radio_button.is_selected():
return None return None
option_selector = self.q(css=self._bounded_selector(self.content_group_selector)) option_selector = self.q(css=self._bounded_selector(self.content_group_selector))
return option_selector.filter(lambda el: el.is_selected())[0].text return option_selector.filter(lambda el: el.is_selected())[0].text
......
...@@ -88,11 +88,12 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -88,11 +88,12 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
""" """
self.verify_cohort_description( self.verify_cohort_description(
self.manual_cohort_name, self.manual_cohort_name,
'Students are added to this group only when you provide their email addresses or usernames on this page', 'Students are added to this cohort group only when you provide '
'their email addresses or usernames on this page',
) )
self.verify_cohort_description( self.verify_cohort_description(
self.auto_cohort_name, self.auto_cohort_name,
'Students are added to this group automatically', 'Students are added to this cohort group automatically',
) )
def test_no_content_groups(self): def test_no_content_groups(self):
...@@ -110,7 +111,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -110,7 +111,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
self.cohort_management_page.select_cohort(self.manual_cohort_name) self.cohort_management_page.select_cohort(self.manual_cohort_name)
self.assertIsNone(self.cohort_management_page.get_cohort_associated_content_group()) self.assertIsNone(self.cohort_management_page.get_cohort_associated_content_group())
self.assertEqual( self.assertEqual(
"You haven't configured any content groups yet. You need to create a content group before you can create assignments. Create a content group", "No content groups exist. Create a content group to associate with cohort groups. Create a content group",
self.cohort_management_page.get_cohort_related_content_group_message() self.cohort_management_page.get_cohort_related_content_group_message()
) )
# TODO: test can't select radio button # TODO: test can't select radio button
...@@ -346,7 +347,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -346,7 +347,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
start_time = datetime.now(UTC) start_time = datetime.now(UTC)
self.cohort_management_page.upload_cohort_file(filename) self.cohort_management_page.upload_cohort_file(filename)
self._verify_cohort_by_csv_notification( self._verify_cohort_by_csv_notification(
"Your file '{}' has been uploaded. Please allow a few minutes for processing.".format(filename) "Your file '{}' has been uploaded. Allow a few minutes for processing.".format(filename)
) )
# student_user is moved from manual cohort group to auto cohort group # student_user is moved from manual cohort group to auto cohort group
...@@ -601,7 +602,7 @@ class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin): ...@@ -601,7 +602,7 @@ class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin):
self.browser.refresh() self.browser.refresh()
self.cohort_management_page.wait_for_page() self.cohort_management_page.wait_for_page()
self.cohort_management_page.select_cohort(new_cohort) self.cohort_management_page.select_cohort(new_cohort)
self.assertEqual("Some content group that's been deleted", self.cohort_management_page.get_cohort_associated_content_group()) self.assertEqual("Deleted Content Group", self.cohort_management_page.get_cohort_associated_content_group())
self.assertEquals(["Bananas", "Pears", "Some content group that's been deleted"], self.cohort_management_page.get_all_content_groups()) self.assertEquals(["Bananas", "Pears", "Some content group that's been deleted"], self.cohort_management_page.get_all_content_groups())
self.assertEqual( self.assertEqual(
"The selected content group has been deleted, you may wish to reassign this cohort group.", "The selected content group has been deleted, you may wish to reassign this cohort group.",
...@@ -610,9 +611,8 @@ class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin): ...@@ -610,9 +611,8 @@ class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin):
self.cohort_management_page.set_cohort_associated_content_group("Pears") self.cohort_management_page.set_cohort_associated_content_group("Pears")
confirmation_messages = self.cohort_management_page.get_cohort_settings_messages() confirmation_messages = self.cohort_management_page.get_cohort_settings_messages()
self.assertEqual(["Saved cohort group."], confirmation_messages) self.assertEqual(["Saved cohort group."], confirmation_messages)
# TODO: uncomment self.assertIsNone(self.cohort_management_page.get_cohort_related_content_group_message())
# self.assertIsNone(self.cohort_management_page.get_cohort_related_content_group_message()) self.assertEquals(["Bananas", "Pears"], self.cohort_management_page.get_all_content_groups())
# self.assertEquals(["Bananas", "Pears"], self.cohort_management_page.get_all_content_groups())
def _create_new_cohort_linked_to_content_group(self, new_cohort, cohort_group): def _create_new_cohort_linked_to_content_group(self, new_cohort, cohort_group):
""" """
......
...@@ -8,7 +8,8 @@ var edx = edx || {}; ...@@ -8,7 +8,8 @@ var edx = edx || {};
edx.groups.ContentGroupModel = Backbone.Model.extend({ edx.groups.ContentGroupModel = Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
defaults: { defaults: {
name: '' name: '',
user_partition_id: null
} }
}); });
}).call(this, Backbone); }).call(this, Backbone);
...@@ -15,9 +15,8 @@ var edx = edx || {}; ...@@ -15,9 +15,8 @@ var edx = edx || {};
initialize: function(options) { initialize: function(options) {
this.template = _.template($('#cohort-editor-tpl').text()); this.template = _.template($('#cohort-editor-tpl').text());
this.cohorts = options.cohorts; this.cohorts = options.cohorts;
this.cohortUserPartitionId = options.cohortUserPartitionId;
this.contentGroups = options.contentGroups; this.contentGroups = options.contentGroups;
this.advanced_settings_url = options.advanced_settings_url; this.context = options.context;
}, },
// Any errors that are currently being displayed to the instructor (for example, unknown email addresses). // Any errors that are currently being displayed to the instructor (for example, unknown email addresses).
...@@ -28,14 +27,12 @@ var edx = edx || {}; ...@@ -28,14 +27,12 @@ var edx = edx || {};
render: function() { render: function() {
this.$el.html(this.template({ this.$el.html(this.template({
cohort: this.model, cohort: this.model,
cohortUserPartitionId: this.cohortUserPartitionId, studioAdvancedSettingsUrl: this.context.studioAdvancedSettingsUrl
contentGroups: this.contentGroups,
advanced_settings_url: this.advanced_settings_url
})); }));
this.cohortFormView = new CohortFormView({ this.cohortFormView = new CohortFormView({
model: this.model, model: this.model,
cohortUserPartitionId: this.cohortUserPartitionId, contentGroups: this.contentGroups,
contentGroups: this.contentGroups context: this.context
}); });
this.cohortFormView.render(); this.cohortFormView.render();
this.$('.tab-content-settings').append(this.cohortFormView.$el); this.$('.tab-content-settings').append(this.cohortFormView.$el);
...@@ -53,8 +50,12 @@ var edx = edx || {}; ...@@ -53,8 +50,12 @@ var edx = edx || {};
}, },
saveSettings: function(event) { saveSettings: function(event) {
var cohortFormView = this.cohortFormView;
event.preventDefault(); event.preventDefault();
this.cohortFormView.saveForm(); cohortFormView.saveForm()
.done(function() {
cohortFormView.showMessage(gettext('Saved cohort group.'));
});
}, },
setCohort: function(cohort) { setCohort: function(cohort) {
...@@ -94,7 +95,7 @@ var edx = edx || {}; ...@@ -94,7 +95,7 @@ var edx = edx || {};
self.showErrorMessage(gettext('Error adding students.'), true); self.showErrorMessage(gettext('Error adding students.'), true);
}); });
} else { } else {
self.showErrorMessage(gettext('Please enter a username or email.'), true); self.showErrorMessage(gettext('Enter a username or email.'), true);
input.val(''); input.val('');
} }
}, },
......
...@@ -8,15 +8,14 @@ var edx = edx || {}; ...@@ -8,15 +8,14 @@ var edx = edx || {};
edx.groups.CohortFormView = Backbone.View.extend({ edx.groups.CohortFormView = Backbone.View.extend({
events : { events : {
'change .cohort-management-details-association-course input': 'onRadioButtonChange', 'change .cohort-management-details-association-course input': 'onRadioButtonChange',
'change .input-cohort-group-association': 'onGroupAssociationChange',
'click .tab-content-settings .action-save': 'saveSettings', 'click .tab-content-settings .action-save': 'saveSettings',
'submit .cohort-management-group-add-form': 'addStudents' 'submit .cohort-management-group-add-form': 'addStudents'
}, },
initialize: function(options) { initialize: function(options) {
this.template = _.template($('#cohort-form-tpl').text()); this.template = _.template($('#cohort-form-tpl').text());
this.cohortUserPartitionId = options.cohortUserPartitionId;
this.contentGroups = options.contentGroups; this.contentGroups = options.contentGroups;
this.context = options.context;
}, },
showNotification: function(options, beforeElement) { showNotification: function(options, beforeElement) {
...@@ -26,9 +25,6 @@ var edx = edx || {}; ...@@ -26,9 +25,6 @@ var edx = edx || {};
model: model model: model
}); });
this.notification.render(); this.notification.render();
if (!beforeElement) {
beforeElement = this.$('.cohort-management-group');
}
beforeElement.before(this.notification.$el); beforeElement.before(this.notification.$el);
}, },
...@@ -41,7 +37,8 @@ var edx = edx || {}; ...@@ -41,7 +37,8 @@ var edx = edx || {};
render: function() { render: function() {
this.$el.html(this.template({ this.$el.html(this.template({
cohort: this.model, cohort: this.model,
contentGroups: this.contentGroups contentGroups: this.contentGroups,
studioGroupConfigurationsUrl: this.context.studioGroupConfigurationsUrl
})); }));
return this; return this;
}, },
...@@ -51,22 +48,29 @@ var edx = edx || {}; ...@@ -51,22 +48,29 @@ var edx = edx || {};
groupsEnabled = target.val() === 'yes'; groupsEnabled = target.val() === 'yes';
if (!groupsEnabled) { if (!groupsEnabled) {
// If the user has chosen 'no', then clear the selection by setting // If the user has chosen 'no', then clear the selection by setting
// it to the first option ('Choose a content group to associate'). // it to the first option which represents no selection.
this.$('.input-cohort-group-association').val('None'); this.$('.input-cohort-group-association').val('None');
} }
// Enable the select if the user has chosen groups, else disable it
this.$('.input-cohort-group-association').prop('disabled', !groupsEnabled);
}, },
onGroupAssociationChange: function(event) { getSelectedContentGroup: function() {
// Since the user has chosen a content group, click the 'Yes' button too var selectValue = this.$('.input-cohort-group-association').val(),
this.$('.cohort-management-details-association-course .radio-yes').click(); ids, groupId, userPartitionId, i, contentGroup;
},
getSelectedGroupId: function() {
var selectValue = this.$('.input-cohort-group-association').val();
if (!this.$('.radio-yes').prop('checked') || selectValue === 'None') { if (!this.$('.radio-yes').prop('checked') || selectValue === 'None') {
return null; return null;
} }
return parseInt(selectValue); ids = selectValue.split(':');
groupId = parseInt(ids[0]);
userPartitionId = parseInt(ids[1]);
for (i=0; i < this.contentGroups.length; i++) {
contentGroup = this.contentGroups[i];
if (contentGroup.get('id') === groupId && contentGroup.get('user_partition_id') === userPartitionId) {
return contentGroup;
}
}
return null;
}, },
getUpdatedCohortName: function() { getUpdatedCohortName: function() {
...@@ -74,37 +78,43 @@ var edx = edx || {}; ...@@ -74,37 +78,43 @@ var edx = edx || {};
return cohortName ? cohortName.trim() : this.model.get('name'); return cohortName ? cohortName.trim() : this.model.get('name');
}, },
showMessage: function(message, type) {
this.showNotification(
{type: type || 'confirmation', title: message},
this.$('.form-fields')
);
},
saveForm: function() { saveForm: function() {
var self = this, var self = this,
cohort = this.model, cohort = this.model,
saveOperation = $.Deferred(), saveOperation = $.Deferred(),
cohortName, groupId, showMessage, showAddError; isUpdate = this.model.id !== null,
cohortName, selectedContentGroup, showErrorMessage;
this.removeNotification(); this.removeNotification();
showMessage = function(message, type) { showErrorMessage = function(message) {
self.showNotification( self.showMessage(message, 'error');
{type: type || 'confirmation', title: message},
self.$('.form-fields')
);
};
showAddError = function(message, type) {
showMessage(message, 'error');
}; };
cohortName = this.getUpdatedCohortName(); cohortName = this.getUpdatedCohortName();
if (cohortName.length === 0) { if (cohortName.length === 0) {
showAddError(gettext('Please enter a name for your new cohort group.')); showErrorMessage(gettext('Enter a name for your cohort group.'));
saveOperation.reject(); saveOperation.reject();
} else { } else {
groupId = this.getSelectedGroupId(); selectedContentGroup = this.getSelectedContentGroup();
cohort.save( cohort.save(
{name: cohortName, user_partition_id: this.cohortUserPartitionId, group_id: groupId}, {
{patch: true} name: cohortName,
group_id: selectedContentGroup ? selectedContentGroup.id : null,
user_partition_id: selectedContentGroup ? selectedContentGroup.get('user_partition_id') : null
},
{patch: isUpdate}
).done(function(result) { ).done(function(result) {
if (!result.error) { if (!result.error) {
cohort.id = result.id; cohort.id = result.id;
showMessage(gettext('Saved cohort group.')); self.render(); // re-render to remove any now invalid error messages
saveOperation.resolve(); saveOperation.resolve();
} else { } else {
showAddError(result.error); showErrorMessage(result.error);
saveOperation.reject(); saveOperation.reject();
} }
}).fail(function(result) { }).fail(function(result) {
...@@ -116,9 +126,9 @@ var edx = edx || {}; ...@@ -116,9 +126,9 @@ var edx = edx || {};
// Ignore the exception and show the default error message instead. // Ignore the exception and show the default error message instead.
} }
if (!errorMessage) { if (!errorMessage) {
errorMessage = gettext("We've encountered an error. Please refresh your browser and then try again."); errorMessage = gettext("We've encountered an error. Refresh your browser and then try again.");
} }
showAddError(errorMessage); showErrorMessage(errorMessage);
saveOperation.reject(); saveOperation.reject();
}); });
} }
......
...@@ -24,9 +24,7 @@ var edx = edx || {}; ...@@ -24,9 +24,7 @@ var edx = edx || {};
this.template = _.template($('#cohorts-tpl').text()); this.template = _.template($('#cohorts-tpl').text());
this.selectorTemplate = _.template($('#cohort-selector-tpl').text()); this.selectorTemplate = _.template($('#cohort-selector-tpl').text());
this.advanced_settings_url = options.advanced_settings_url; this.context = options.context;
this.upload_cohorts_csv_url = options.upload_cohorts_csv_url;
this.cohortUserPartitionId = options.cohortUserPartitionId;
this.contentGroups = options.contentGroups; this.contentGroups = options.contentGroups;
model.on('sync', this.onSync, this); model.on('sync', this.onSync, this);
...@@ -58,9 +56,14 @@ var edx = edx || {}; ...@@ -58,9 +56,14 @@ var edx = edx || {};
hasCohorts = this.model.length > 0, hasCohorts = this.model.length > 0,
cohortNavElement = this.$('.cohort-management-nav'), cohortNavElement = this.$('.cohort-management-nav'),
additionalCohortControlElement = this.$('.wrapper-cohort-supplemental'), additionalCohortControlElement = this.$('.wrapper-cohort-supplemental'),
isModelUpdate = options && options.patch && response.hasOwnProperty('user_partition_id'); isModelUpdate;
isModelUpdate = function() {
// Distinguish whether this is a sync event for just one model, or if it is for
// an entire collection.
return options && options.patch && response.hasOwnProperty('user_partition_id');
};
this.hideAddCohortForm(); this.hideAddCohortForm();
if (isModelUpdate) { if (isModelUpdate()) {
// Refresh the selector in case the model's name changed // Refresh the selector in case the model's name changed
this.renderSelector(selectedCohort); this.renderSelector(selectedCohort);
} else if (hasCohorts) { } else if (hasCohorts) {
...@@ -104,9 +107,8 @@ var edx = edx || {}; ...@@ -104,9 +107,8 @@ var edx = edx || {};
el: this.$('.cohort-management-group'), el: this.$('.cohort-management-group'),
model: cohort, model: cohort,
cohorts: this.model, cohorts: this.model,
cohortUserPartitionId: this.cohortUserPartitionId,
contentGroups: this.contentGroups, contentGroups: this.contentGroups,
advanced_settings_url: this.advanced_settings_url context: this.context
}); });
this.editor.render(); this.editor.render();
} }
...@@ -142,8 +144,8 @@ var edx = edx || {}; ...@@ -142,8 +144,8 @@ var edx = edx || {};
newCohort.url = this.model.url; newCohort.url = this.model.url;
this.cohortFormView = new CohortFormView({ this.cohortFormView = new CohortFormView({
model: newCohort, model: newCohort,
cohortUserPartitionId: this.cohortUserPartitionId, contentGroups: this.contentGroups,
contentGroups: this.contentGroups context: this.context
}); });
this.cohortFormView.render(); this.cohortFormView.render();
this.$('.cohort-management-add-modal').append(this.cohortFormView.$el); this.$('.cohort-management-add-modal').append(this.cohortFormView.$el);
...@@ -215,10 +217,10 @@ var edx = edx || {}; ...@@ -215,10 +217,10 @@ var edx = edx || {};
inputTip: gettext("Only properly formatted .csv files will be accepted."), inputTip: gettext("Only properly formatted .csv files will be accepted."),
submitButtonText: gettext("Upload File and Assign Students"), submitButtonText: gettext("Upload File and Assign Students"),
extensions: ".csv", extensions: ".csv",
url: this.upload_cohorts_csv_url, url: this.context.uploadCohortsCsvUrl,
successNotification: function (file, event, data) { successNotification: function (file, event, data) {
var message = interpolate_text(gettext( var message = interpolate_text(gettext(
"Your file '{file}' has been uploaded. Please allow a few minutes for processing." "Your file '{file}' has been uploaded. Allow a few minutes for processing."
), {file: file}); ), {file: file});
return new NotificationModel({ return new NotificationModel({
type: "confirmation", type: "confirmation",
......
...@@ -7,13 +7,20 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -7,13 +7,20 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
var catLoversInitialCount = 123, dogLoversInitialCount = 456, unknownUserMessage, var catLoversInitialCount = 123, dogLoversInitialCount = 456, unknownUserMessage,
createMockCohort, createMockCohorts, createMockContentGroups, createCohortsView, cohortsView, createMockCohort, createMockCohorts, createMockContentGroups, createCohortsView, cohortsView,
requests, respondToRefresh, verifyMessage, verifyNoMessage, verifyDetailedMessage, verifyHeader, requests, respondToRefresh, verifyMessage, verifyNoMessage, verifyDetailedMessage, verifyHeader,
expectCohortAddRequest, getAddModal, selectContentGroup, clearContentGroup; expectCohortAddRequest, getAddModal, selectContentGroup, clearContentGroup,
MOCK_COHORTED_USER_PARTITION_ID, MOCK_UPLOAD_COHORTS_CSV_URL, MOCK_STUDIO_ADVANCED_SETTINGS_URL,
MOCK_STUDIO_GROUP_CONFIGURATIONS_URL;
MOCK_COHORTED_USER_PARTITION_ID = 0;
MOCK_UPLOAD_COHORTS_CSV_URL = 'http://upload-csv-file-url/';
MOCK_STUDIO_ADVANCED_SETTINGS_URL = 'http://studio/settings/advanced';
MOCK_STUDIO_GROUP_CONFIGURATIONS_URL = 'http://studio/group_configurations';
createMockCohort = function (name, id, userCount, groupId, userPartitionId) { createMockCohort = function (name, id, userCount, groupId, userPartitionId) {
return { return {
id: id || 1, id: id !== undefined ? id : 1,
name: name, name: name,
user_count: userCount || 0, user_count: userCount !== undefined ? userCount : 0,
group_id: groupId, group_id: groupId,
user_partition_id: userPartitionId user_partition_id: userPartitionId
}; };
...@@ -30,8 +37,12 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -30,8 +37,12 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
createMockContentGroups = function () { createMockContentGroups = function () {
return [ return [
new ContentGroupModel({id: 0, name: 'Dog Content'}), new ContentGroupModel({
new ContentGroupModel({id: 1, name: 'Cat Content'}) id: 0, name: 'Dog Content', user_partition_id: MOCK_COHORTED_USER_PARTITION_ID
}),
new ContentGroupModel({
id: 1, name: 'Cat Content', user_partition_id: MOCK_COHORTED_USER_PARTITION_ID
})
]; ];
}; };
...@@ -46,7 +57,11 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -46,7 +57,11 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView = new CohortsView({ cohortsView = new CohortsView({
model: cohorts, model: cohorts,
contentGroups: contentGroups, contentGroups: contentGroups,
upload_cohorts_csv_url: "http://upload-csv-file-url/" context: {
uploadCohortsCsvUrl: MOCK_UPLOAD_COHORTS_CSV_URL,
studioAdvancedSettingsUrl: MOCK_STUDIO_ADVANCED_SETTINGS_URL,
studioGroupConfigurationsUrl: MOCK_STUDIO_GROUP_CONFIGURATIONS_URL
}
}); });
cohortsView.render(); cohortsView.render();
if (options && options.selectCohort) { if (options && options.selectCohort) {
...@@ -58,14 +73,15 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -58,14 +73,15 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
AjaxHelpers.respondWithJson(requests, createMockCohorts(catCount, dogCount)); AjaxHelpers.respondWithJson(requests, createMockCohorts(catCount, dogCount));
}; };
expectCohortAddRequest = function(name, group_id) { expectCohortAddRequest = function(name, groupId, userPartitionId) {
AjaxHelpers.expectJsonRequest( AjaxHelpers.expectJsonRequest(
requests, 'POST', '/mock_service/cohorts', requests, 'POST', '/mock_service/cohorts',
{ {
name: name, name: name,
user_count: 0, user_count: 0,
assignment_type: '', assignment_type: '',
group_id: group_id group_id: groupId,
user_partition_id: userPartitionId
} }
); );
}; };
...@@ -74,14 +90,16 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -74,14 +90,16 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
return cohortsView.$('.cohort-management-add-modal'); return cohortsView.$('.cohort-management-add-modal');
}; };
selectContentGroup = function(values) { selectContentGroup = function(groupId, userPartitionId) {
var ids = groupId + ':' + userPartitionId;
cohortsView.$('.radio-yes').prop('checked', true).change(); cohortsView.$('.radio-yes').prop('checked', true).change();
cohortsView.$('.input-cohort-group-association').val(values).change(); cohortsView.$('.input-cohort-group-association').val(ids).change();
expect(cohortsView.$('.input-cohort-group-association').prop('disabled')).toBeFalsy();
}; };
clearContentGroup = function() { clearContentGroup = function() {
cohortsView.$('.radio-no').prop('checked', true).change(); cohortsView.$('.radio-no').prop('checked', true).change();
expect(cohortsView.$('.radio-yes').prop('checked')).toBeFalsy(); expect(cohortsView.$('.input-cohort-group-association').prop('disabled')).toBeTruthy();
expect(cohortsView.$('.input-cohort-group-association').val()).toBe('None'); expect(cohortsView.$('.input-cohort-group-association').val()).toBe('None');
}; };
...@@ -145,7 +163,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -145,7 +163,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
TemplateHelpers.installTemplate('templates/file-upload'); TemplateHelpers.installTemplate('templates/file-upload');
}); });
it("Show an error if no cohorts are defined", function() { it("shows an error if no cohorts are defined", function() {
createCohortsView(this, {cohorts: []}); createCohortsView(this, {cohorts: []});
verifyMessage( verifyMessage(
'You currently have no cohort groups configured', 'You currently have no cohort groups configured',
...@@ -157,7 +175,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -157,7 +175,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
expect(cohortsView.$('.wrapper-cohort-supplemental')).toHaveClass('is-hidden'); expect(cohortsView.$('.wrapper-cohort-supplemental')).toHaveClass('is-hidden');
}); });
it("Syncs data when membership tab is clicked", function() { it("syncs data when membership tab is clicked", function() {
createCohortsView(this, {selectCohort: 1}); createCohortsView(this, {selectCohort: 1});
verifyHeader(1, 'Cat Lovers', catLoversInitialCount); verifyHeader(1, 'Cat Lovers', catLoversInitialCount);
$(cohortsView.getSectionCss("membership")).click(); $(cohortsView.getSectionCss("membership")).click();
...@@ -188,10 +206,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -188,10 +206,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.submit-file-button').click(); cohortsView.$('.submit-file-button').click();
// No file will actually be uploaded because "uploaded_file.txt" doesn't actually exist. // No file will actually be uploaded because "uploaded_file.txt" doesn't actually exist.
AjaxHelpers.expectRequest(requests, 'POST', "http://upload-csv-file-url/", new FormData()); AjaxHelpers.expectRequest(requests, 'POST', MOCK_UPLOAD_COHORTS_CSV_URL, new FormData());
AjaxHelpers.respondWithJson(requests, {}); AjaxHelpers.respondWithJson(requests, {});
expect(cohortsView.$('.file-upload-form-result .message-confirmation .message-title').text().trim()) expect(cohortsView.$('.file-upload-form-result .message-confirmation .message-title').text().trim())
.toBe("Your file 'upload_file.txt' has been uploaded. Please allow a few minutes for processing."); .toBe("Your file 'upload_file.txt' has been uploaded. Allow a few minutes for processing.");
}); });
describe("Cohort Selector", function () { describe("Cohort Selector", function () {
...@@ -208,7 +226,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -208,7 +226,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
it('can switch cohort', function () { it('can switch cohort', function () {
createCohortsView(this, {selectCohort: 1}); createCohortsView(this, {selectCohort: 1});
cohortsView.$('.cohort-select').val("2").change(); cohortsView.$('.cohort-select').val('2').change();
verifyHeader(2, 'Dog Lovers', dogLoversInitialCount); verifyHeader(2, 'Dog Lovers', dogLoversInitialCount);
}); });
}); });
...@@ -236,22 +254,24 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -236,22 +254,24 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
var defaultCohortName = 'New Cohort'; var defaultCohortName = 'New Cohort';
it("can add a cohort", function() { it("can add a cohort", function() {
var contentGroupId = 0; var contentGroupId = 0,
contentGroupUserPartitionId = 0;
createCohortsView(this, {cohorts: []}); createCohortsView(this, {cohorts: []});
cohortsView.$('.action-create').click(); cohortsView.$('.action-create').click();
expect(cohortsView.$('.cohort-management-settings-form').length).toBe(1); expect(cohortsView.$('.cohort-management-settings-form').length).toBe(1);
expect(cohortsView.$('.cohort-management-nav')).toHaveClass('is-disabled'); expect(cohortsView.$('.cohort-management-nav')).toHaveClass('is-disabled');
expect(cohortsView.$('.cohort-management-group')).toHaveClass('is-hidden'); expect(cohortsView.$('.cohort-management-group')).toHaveClass('is-hidden');
cohortsView.$('.cohort-name').val(defaultCohortName); cohortsView.$('.cohort-name').val(defaultCohortName);
selectContentGroup(contentGroupId); selectContentGroup(contentGroupId, MOCK_COHORTED_USER_PARTITION_ID);
cohortsView.$('.action-save').click(); cohortsView.$('.action-save').click();
expectCohortAddRequest(defaultCohortName, contentGroupId); expectCohortAddRequest(defaultCohortName, contentGroupId, MOCK_COHORTED_USER_PARTITION_ID);
AjaxHelpers.respondWithJson( AjaxHelpers.respondWithJson(
requests, requests,
{ {
id: 1, id: 1,
name: defaultCohortName, name: defaultCohortName,
group_id: contentGroupId group_id: contentGroupId,
user_partition_id: MOCK_COHORTED_USER_PARTITION_ID
} }
); );
AjaxHelpers.respondWithJson( AjaxHelpers.respondWithJson(
...@@ -274,7 +294,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -274,7 +294,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.action-create').click(); cohortsView.$('.action-create').click();
cohortsView.$('.cohort-name').val(' New Cohort '); cohortsView.$('.cohort-name').val(' New Cohort ');
cohortsView.$('.action-save').click(); cohortsView.$('.action-save').click();
expectCohortAddRequest('New Cohort', null); expectCohortAddRequest('New Cohort', null, null);
}); });
it("does not allow a blank cohort name to be submitted", function() { it("does not allow a blank cohort name to be submitted", function() {
...@@ -285,7 +305,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -285,7 +305,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
expect(cohortsView.$('.cohort-management-nav')).toHaveClass('is-disabled'); expect(cohortsView.$('.cohort-management-nav')).toHaveClass('is-disabled');
getAddModal().find('.action-save').click(); getAddModal().find('.action-save').click();
expect(requests.length).toBe(0); expect(requests.length).toBe(0);
verifyMessage('Please enter a name for your new cohort group.', 'error'); verifyMessage('Enter a name for your cohort group.', 'error');
}); });
it("shows a message when adding a cohort returns a server error", function() { it("shows a message when adding a cohort returns a server error", function() {
...@@ -336,10 +356,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -336,10 +356,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.action-create').click(); cohortsView.$('.action-create').click();
cohortsView.$('.cohort-name').val(''); cohortsView.$('.cohort-name').val('');
cohortsView.$('.action-save').click(); cohortsView.$('.action-save').click();
verifyMessage('Please enter a name for your new cohort group.', 'error'); verifyMessage('Enter a name for your cohort group.', 'error');
// Now switch to a different cohort // Now switch to a different cohort
cohortsView.$('.cohort-select').val("2").change(); cohortsView.$('.cohort-select').val('2').change();
verifyHeader(2, 'Dog Lovers', dogLoversInitialCount); verifyHeader(2, 'Dog Lovers', dogLoversInitialCount);
verifyNoMessage(); verifyNoMessage();
}); });
...@@ -351,7 +371,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -351,7 +371,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.action-create').click(); cohortsView.$('.action-create').click();
cohortsView.$('.cohort-name').val(''); cohortsView.$('.cohort-name').val('');
cohortsView.$('.action-save').click(); cohortsView.$('.action-save').click();
verifyMessage('Please enter a name for your new cohort group.', 'error'); verifyMessage('Enter a name for your cohort group.', 'error');
// Now cancel the form // Now cancel the form
cohortsView.$('.action-cancel').click(); cohortsView.$('.action-cancel').click();
...@@ -382,7 +402,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -382,7 +402,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
createCohortsView(this, {selectCohort: 1}); createCohortsView(this, {selectCohort: 1});
addStudents(' '); addStudents(' ');
expect(requests.length).toBe(0); expect(requests.length).toBe(0);
verifyMessage('Please enter a username or email.', 'error'); verifyMessage('Enter a username or email.', 'error');
expect(getStudentInput().val()).toBe(''); expect(getStudentInput().val()).toBe('');
}); });
...@@ -508,9 +528,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -508,9 +528,10 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
var options; var options;
createCohortsView(this, {selectCohort: 1}); createCohortsView(this, {selectCohort: 1});
cohortsView.$('.tab-settings a').click(); cohortsView.$('.tab-settings a').click();
expect(cohortsView.$('.input-cohort-group-association').prop('disabled')).toBeTruthy();
options = cohortsView.$('.input-cohort-group-association option'); options = cohortsView.$('.input-cohort-group-association option');
expect(options.length).toBe(3); expect(options.length).toBe(3);
expect($(options[0]).text().trim()).toBe('Choose a content group to associate'); expect($(options[0]).text().trim()).toBe('');
expect($(options[1]).text().trim()).toBe('Cat Content'); expect($(options[1]).text().trim()).toBe('Cat Content');
expect($(options[2]).text().trim()).toBe('Dog Content'); expect($(options[2]).text().trim()).toBe('Dog Content');
}); });
...@@ -520,7 +541,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -520,7 +541,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.tab-settings a').click(); cohortsView.$('.tab-settings a').click();
// Select the content group with id 1 and verify the radio button was switched to 'Yes' // Select the content group with id 1 and verify the radio button was switched to 'Yes'
selectContentGroup(0); selectContentGroup(0, MOCK_COHORTED_USER_PARTITION_ID);
expect(cohortsView.$('.radio-yes').prop('checked')).toBeTruthy(); expect(cohortsView.$('.radio-yes').prop('checked')).toBeTruthy();
// Click the save button and verify that the correct request is sent // Click the save button and verify that the correct request is sent
...@@ -529,7 +550,8 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -529,7 +550,8 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
requests, 'PATCH', '/mock_service/cohorts/1', requests, 'PATCH', '/mock_service/cohorts/1',
{ {
name: 'Cat Lovers', name: 'Cat Lovers',
group_id: 0 group_id: 0,
user_partition_id: MOCK_COHORTED_USER_PARTITION_ID
} }
); );
AjaxHelpers.respondWithJson( AjaxHelpers.respondWithJson(
...@@ -556,7 +578,8 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -556,7 +578,8 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
requests, 'PATCH', '/mock_service/cohorts/1', requests, 'PATCH', '/mock_service/cohorts/1',
{ {
name: 'Cat Lovers', name: 'Cat Lovers',
group_id: null group_id: null,
user_partition_id: null
} }
); );
AjaxHelpers.respondWithJson( AjaxHelpers.respondWithJson(
...@@ -566,6 +589,30 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -566,6 +589,30 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
verifyMessage('Saved cohort group.', 'confirmation'); verifyMessage('Saved cohort group.', 'confirmation');
}); });
it("can clear a selected content group which had been deleted", function () {
createCohortsView(this, {
cohorts: [
{id: 1, name: 'Cat Lovers', group_id: 999}
],
selectCohort: 1
});
cohortsView.$('.tab-settings a').click();
expect(cohortsView.$('.radio-yes').prop('checked')).toBeTruthy();
clearContentGroup();
// Click the save button and verify that the correct request is sent
cohortsView.$('.action-save').click();
AjaxHelpers.respondWithJson(
requests,
createMockCohort('Cat Lovers', 1, catLoversInitialCount, 0, 0)
);
verifyMessage('Saved cohort group.', 'confirmation');
// Verify that the deleted content group and associated message have been removed
expect(cohortsView.$('option.option-unavailable').text().trim()).toBe('');
expect(cohortsView.$('.copy-error').text().trim()).toBe('');
});
it("shows a message when the selected content group does not exist", function () { it("shows a message when the selected content group does not exist", function () {
createCohortsView(this, { createCohortsView(this, {
cohorts: [ cohorts: [
...@@ -574,8 +621,9 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -574,8 +621,9 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
selectCohort: 1 selectCohort: 1
}); });
cohortsView.$('.tab-settings a').click(); cohortsView.$('.tab-settings a').click();
expect(cohortsView.$('option.option-unavailable').text().trim()).toBe('Deleted Content Group');
expect(cohortsView.$('.copy-error').text().trim()).toBe( expect(cohortsView.$('.copy-error').text().trim()).toBe(
'The selected content group has been deleted, you may wish to reassign this cohort group.' 'The previously selected content group was deleted. Select another content group.'
); );
}); });
...@@ -585,7 +633,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -585,7 +633,7 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
cohortsView.$('.action-save').click(); cohortsView.$('.action-save').click();
AjaxHelpers.respondWithError(requests); AjaxHelpers.respondWithError(requests);
verifyMessage( verifyMessage(
'We\'ve encountered an error. Please refresh your browser and then try again.', 'We\'ve encountered an error. Refresh your browser and then try again.',
'error' 'error'
); );
}); });
...@@ -593,10 +641,14 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe ...@@ -593,10 +641,14 @@ define(['backbone', 'jquery', 'js/common_helpers/ajax_helpers', 'js/common_helpe
it("shows an error message when no content groups are specified", function () { it("shows an error message when no content groups are specified", function () {
createCohortsView(this, {selectCohort: 1, contentGroups: []}); createCohortsView(this, {selectCohort: 1, contentGroups: []});
cohortsView.$('.tab-settings a').click(); cohortsView.$('.tab-settings a').click();
expect(cohortsView.$('.radio-yes').prop('disabled')).toBeTruthy();
expect(cohortsView.$('.msg-inline').text().trim()).toBe(
'No content groups exist. Create a content group to associate with cohort groups. ' +
'Create a content group'
);
expect( expect(
cohortsView.$('.msg-inline').text().trim(), cohortsView.$('.msg-inline a').attr('href'),
'You haven\'t configured any content groups yet. You need to create a content group ' + MOCK_STUDIO_GROUP_CONFIGURATIONS_URL
'before you can create assignments.'
); );
}); });
}); });
......
...@@ -57,10 +57,15 @@ ...@@ -57,10 +57,15 @@
// TYPE: inline // TYPE: inline
.msg-inline { .msg-inline {
@extend %t-copy-sub2; // @extend %t-copy-sub1;
display: inline-block; display: inline-block;
margin: 0 0 0 $baseline; margin: 0 0 0 $baseline;
padding: 0; padding: 0;
.icon,
.fa {
margin-right: ($baseline/2);
}
} }
// TYPE: warning // TYPE: warning
...@@ -1085,7 +1090,7 @@ ...@@ -1085,7 +1090,7 @@
a { a {
display: inline-block; display: inline-block;
padding: $baseline; padding: ($baseline - 5);
-webkit-transition: none; -webkit-transition: none;
-moz-transition: none; -moz-transition: none;
-ms-transition: none; -ms-transition: none;
...@@ -1096,7 +1101,7 @@ ...@@ -1096,7 +1101,7 @@
&.is-selected { // Active or selected tabs (<li>) get this class. Also useful for aria stuff if ever implemented in the future. &.is-selected { // Active or selected tabs (<li>) get this class. Also useful for aria stuff if ever implemented in the future.
a { a {
padding-bottom: ($baseline+($baseline/5)); padding-bottom: ($baseline - 5);
border-style: solid; border-style: solid;
border-width: ($baseline/5) ($baseline/5) 0 ($baseline/5); border-width: ($baseline/5) ($baseline/5) 0 ($baseline/5);
border-color: $gray-l4; border-color: $gray-l4;
......
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
<div class="cohort-management-group-setup"> <div class="cohort-management-group-setup">
<div class="setup-value"> <div class="setup-value">
<% if (cohort.get('assignment_type') == "none") { %> <% if (cohort.get('assignment_type') == "none") { %>
<%- gettext("Students are added to this group only when you provide their email addresses or usernames on this page.") %> <%- gettext("Students are added to this cohort group only when you provide their email addresses or usernames on this page.") %>
<a href="http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/cohorts/cohort_config.html#assign-students-to-cohort-groups-manually" class="incontext-help action-secondary action-help"><%= gettext("What does this mean?") %></a> <a href="http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/cohorts/cohort_config.html#assign-students-to-cohort-groups-manually" class="incontext-help action-secondary action-help"><%= gettext("What does this mean?") %></a>
<% } else { %> <% } else { %>
<%- gettext("Students are added to this group automatically.") %> <%- gettext("Students are added to this cohort group automatically.") %>
<a href="http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/cohorts/cohorts_overview.html#all-automated-assignment" class="incontext-help action-secondary action-help"><%- gettext("What does this mean?") %></a> <a href="http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/cohorts/cohorts_overview.html#all-automated-assignment" class="incontext-help action-secondary action-help"><%- gettext("What does this mean?") %></a>
<% } %> <% } %>
</div> </div>
<div class="setup-actions"> <div class="setup-actions">
<% if (advanced_settings_url != "None") { %> <% if (studioAdvancedSettingsUrl !== "None") { %>
<a href="<%= advanced_settings_url %>" class="action-secondary action-edit"><%- gettext("Edit settings in Studio") %></a> <a href="<%= studioAdvancedSettingsUrl %>" class="action-secondary action-edit"><%- gettext("Edit settings in Studio") %></a>
<% } %> <% } %>
</div> </div>
</div> </div>
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<h4 class="form-title"><%- gettext('Add students to this cohort group') %></h4> <h4 class="form-title"><%- gettext('Add students to this cohort group') %></h4>
<div class="form-introduction"> <div class="form-introduction">
<p><%- gettext('Note: Students can only be in one cohort group. Adding students to this group overrides any previous group assignment.') %></p> <p><%- gettext('Note: Students can be in only one cohort group. Adding students to this group overrides any previous group assignment.') %></p>
</div> </div>
<div class="cohort-confirmations"></div> <div class="cohort-confirmations"></div>
...@@ -48,14 +48,14 @@ ...@@ -48,14 +48,14 @@
<div class="form-fields"> <div class="form-fields">
<div class="field field-textarea is-required"> <div class="field field-textarea is-required">
<label for="cohort-management-group-add-students" class="label"> <label for="cohort-management-group-add-students" class="label">
<%- gettext('Enter email addresses and/or usernames separated by new lines or commas for students to add. *') %> <%- gettext('Enter email addresses and/or usernames, separated by new lines or commas, for the students you want to add. *') %>
<span class="sr"><%- gettext('(Required Field)') %></span> <span class="sr"><%- gettext('(Required Field)') %></span>
</label> </label>
<textarea name="cohort-management-group-add-students" id="cohort-management-group-add-students" <textarea name="cohort-management-group-add-students" id="cohort-management-group-add-students"
class="input cohort-management-group-add-students" class="input cohort-management-group-add-students"
placeholder="<%- gettext('e.g. johndoe@example.com, JaneDoe, joeydoe@example.com') %>"></textarea> placeholder="<%- gettext('e.g. johndoe@example.com, JaneDoe, joeydoe@example.com') %>"></textarea>
<span class="tip"><%- gettext('You will not get notification for emails that bounce, so please double-check spelling.') %></span> <span class="tip"><%- gettext('You will not receive notification for emails that bounce, so double-check your spelling.') %></span>
</div> </div>
</div> </div>
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
<div class="form-field"> <div class="form-field">
<div class="cohort-management-settings-form-name field field-text"> <div class="cohort-management-settings-form-name field field-text">
<label for="cohort-name" class="label"> <label for="cohort-name" class="label">
<%- gettext('Cohort Name') %> * <%- gettext('Cohort Group Name') %> *
<span class="sr"><%- gettext('(Required Field)')%></span> <span class="sr"><%- gettext('(Required Field)')%></span>
</label> </label>
<input type="text" name="cohort-name" value="<%- cohort ? cohort.get('name') : '' %>" class="input cohort-name" <input type="text" name="cohort-name" value="<%- cohort ? cohort.get('name') : '' %>" class="input cohort-name"
id="cohort-name" id="cohort-name"
placeholder="<%- gettext("Enter Your Cohort Group's Name") %>" required="required" /> placeholder="<%- gettext("Enter the name of the cohort group") %>" required="required" />
</div> </div>
</div> </div>
<% } %> <% } %>
...@@ -28,20 +28,21 @@ ...@@ -28,20 +28,21 @@
var foundSelected = false; var foundSelected = false;
var selectedContentGroupId = cohort.get('group_id'); var selectedContentGroupId = cohort.get('group_id');
var hasSelectedContentGroup = selectedContentGroupId != null; var hasSelectedContentGroup = selectedContentGroupId != null;
var hasContentGroups = contentGroups.length > 0;
%> %>
<div class="form-field"> <div class="form-field">
<div class="cohort-management-details-association-course field field-radio"> <div class="cohort-management-details-association-course field field-radio">
<label class="label"> <label class="label">
<%- gettext('Is this cohort group associated with course-based content groups?') %> <%- gettext('Associate this cohort group with a content group') %>
</label> </label>
<label><input type="radio" class="radio-no" name="cohort-association-course" value="no" <%- !hasSelectedContentGroup ? 'checked="checked"' : '' %>/> <%- gettext("No") %></label> <label><input type="radio" class="radio-no" name="cohort-association-course" value="no" <%- !hasSelectedContentGroup ? 'checked="checked"' : '' %>/> <%- gettext("No Content Group") %></label>
<div class="input-group has-other-input-text"> <div class="input-group has-other-input-text">
<label><input type="radio" class="radio-yes" name="cohort-association-course" value="yes" <%- hasSelectedContentGroup ? 'checked="checked"' : '' %> /> <%- gettext("Yes") %></label> <label><input type="radio" class="radio-yes" name="cohort-association-course" value="yes" <%- !hasContentGroups ? 'disabled="disabled"' : '' %> <%- hasSelectedContentGroup ? 'checked="checked"' : '' %> /> <%- gettext("Select a Content Group") %></label>
<% if (contentGroups.length > 0) { %> <% if (hasContentGroups) { %>
<div class="input-group-other"> <div class="input-group-other">
<label class="sr" for="cohort-group-association"><%- gettext("Choose a content group to associate") %></label> <label class="sr" for="cohort-group-association"><%- gettext("Choose a content group to associate") %></label>
<select name="cohort-group-association" class="input input-lg has-option-unavailable input-cohort-group-association"> <select name="cohort-group-association" class="input input-lg has-option-unavailable input-cohort-group-association" <%- !hasSelectedContentGroup ? 'disabled="disabled"' : '' %>>
<option value="None"><%- gettext("Choose a content group to associate") %></option> <option value="None"></option>
<% <%
var orderedContentGroups = _.sortBy( var orderedContentGroups = _.sortBy(
...@@ -49,33 +50,34 @@ ...@@ -49,33 +50,34 @@
function(group) { return group.get('name'); } function(group) { return group.get('name'); }
); );
for (var i=0; i < orderedContentGroups.length; i++) { for (var i=0; i < orderedContentGroups.length; i++) {
var contentGroup = orderedContentGroups[i]; var contentGroup = orderedContentGroups[i],
var contentGroupId = contentGroup.get('id'); contentGroupUserPartitionId = contentGroup.get('user_partition_id'),
var isSelected = contentGroupId == selectedContentGroupId; contentGroupId = contentGroup.get('id'),
isSelected = contentGroupId == selectedContentGroupId;
if (isSelected) { if (isSelected) {
foundSelected = true; foundSelected = true;
} }
%> %>
<option value="<%- contentGroupId %>" <%- isSelected ? 'selected="selected"' : '' %>><%- contentGroup.get('name') %></option> <option value="<%- contentGroupId %>:<%- contentGroupUserPartitionId %>" <%- isSelected ? 'selected="selected"' : '' %>><%- contentGroup.get('name') %></option>
<% <%
} }
%> %>
<% if (hasSelectedContentGroup && !foundSelected) { %> <% if (hasSelectedContentGroup && !foundSelected) { %>
<option value="<%- contentGroupId %>" class="option-unavailable" selected="selected"><%- gettext("Some content group that's been deleted") %></option> <option value="<%- contentGroupId %>:<%- contentGroupUserPartitionId %>" class="option-unavailable" selected="selected"><%- gettext("Deleted Content Group") %></option>
<% } %> <% } %>
</select> </select>
<% if (hasSelectedContentGroup && !foundSelected) { %> <% if (hasSelectedContentGroup && !foundSelected) { %>
<div class="msg-inline"> <div class="msg-inline">
<p class="copy-error"><i class="icon icon-warning-sign"></i><%- gettext("The selected content group has been deleted, you may wish to reassign this cohort group.") %></p> <p class="copy-error"><i class="icon icon-warning-sign"></i><%- gettext("The previously selected content group was deleted. Select another content group.") %></p>
</div> </div>
<% } %> <% } %>
</div> </div>
<% } else { // no content groups available %> <% } else { // no content groups available %>
<div class="input-group-other is-visible"> <div class="input-group-other">
<div class="msg-inline"> <div class="msg-inline">
<p class="copy-error"><i class="icon icon-warning-sign"></i> You haven't configured any content groups yet. You need to create a content group before you can create assignments. <a href="#">Create a content group</a></p> <p class="copy-error"><i class="icon icon-warning-sign"></i><%- gettext("No content groups exist. Create a content group to associate with cohort groups.") %> <a href="<%- studioGroupConfigurationsUrl %>"><%- gettext("Create a content group") %></a></p>
</div> </div>
</div> </div>
<% } %> <% } %>
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
<%page args="section_data"/> <%page args="section_data"/>
<%! from courseware.courses import get_studio_url %>
<%! from microsite_configuration import microsite %> <%! from microsite_configuration import microsite %>
<%! from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition %> <%! from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition %>
...@@ -264,11 +265,13 @@ ...@@ -264,11 +265,13 @@
var cohortManagementElement = $('.cohort-management'); var cohortManagementElement = $('.cohort-management');
if (cohortManagementElement.length > 0) { if (cohortManagementElement.length > 0) {
var cohorts = new edx.groups.CohortCollection(), var cohorts = new edx.groups.CohortCollection(),
cohortUserPartitionId = ${cohorted_user_partition.id if cohorted_user_partition else 'null'},
contentGroups = [ contentGroups = [
% for content_group in content_groups: % for content_group in content_groups:
new edx.groups.ContentGroupModel({ new edx.groups.ContentGroupModel({
id: ${content_group.id}, id: ${content_group.id},
name: "${content_group.name | h}" name: "${content_group.name | h}",
user_partition_id: cohortUserPartitionId
}), }),
% endfor % endfor
]; ];
...@@ -276,10 +279,12 @@ ...@@ -276,10 +279,12 @@
var cohortsView = new edx.groups.CohortsView({ var cohortsView = new edx.groups.CohortsView({
el: cohortManagementElement, el: cohortManagementElement,
model: cohorts, model: cohorts,
cohortUserPartitionId: ${cohorted_user_partition.id if cohorted_user_partition else 'null'},
contentGroups: contentGroups, contentGroups: contentGroups,
advanced_settings_url: cohortManagementElement.data('advanced-settings-url'), context: {
upload_cohorts_csv_url: cohortManagementElement.data('upload_cohorts_csv_url') uploadCohortsCsvUrl: cohortManagementElement.data('upload_cohorts_csv_url'),
studioAdvancedSettingsUrl: cohortManagementElement.data('advanced-settings-url'),
studioGroupConfigurationsUrl: '${get_studio_url(course, 'group_configurations') | h}'
}
}); });
cohorts.fetch().done(function() { cohorts.fetch().done(function() {
cohortsView.render(); cohortsView.render();
......
copy
\ No newline at end of file
Markdown is supported
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