Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-armstrong committed Mar 22, 2016
1 parent b7fbfd4 commit 08bcde2
Show file tree
Hide file tree
Showing 33 changed files with 580 additions and 495 deletions.
52 changes: 26 additions & 26 deletions common/static/common/js/components/views/feedback_notification.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
;(function(define) {
;(function (define) {
'use strict';
define(['jquery', 'underscore', 'underscore.string', 'common/js/components/views/feedback'],
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) {

var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: 'notification',
closeIcon: false
})
});
var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "notification",
closeIcon: false
})
});

// create Notification.Warning, Notification.Confirmation, etc
var capitalCamel, intents;
capitalCamel = _.compose(str.capitalize, str.camelize);
intents = ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini'];
_.each(intents, function(intent) {
var subclass;
subclass = Notification.extend({
options: $.extend({}, Notification.prototype.options, {
intent: intent
})
});
Notification[capitalCamel(intent)] = subclass;
// create Notification.Warning, Notification.Confirmation, etc
var capitalCamel, intents;
capitalCamel = _.compose(str.capitalize, str.camelize);
intents = ["warning", "error", "confirmation", "announcement", "step-required", "help", "mini"];
_.each(intents, function(intent) {
var subclass;
subclass = Notification.extend({
options: $.extend({}, Notification.prototype.options, {
intent: intent
})
});
Notification[capitalCamel(intent)] = subclass;
});

// set more sensible defaults for Notification.Mini views
var miniOptions = Notification.Mini.prototype.options;
miniOptions.minShown = 1250;
miniOptions.closeIcon = false;
// set more sensible defaults for Notification.Mini views
var miniOptions = Notification.Mini.prototype.options;
miniOptions.minShown = 1250;
miniOptions.closeIcon = false;

return Notification;
});
return Notification;
});
}).call(this, define || RequireJS.define);
48 changes: 26 additions & 22 deletions lms/djangoapps/teams/static/teams/js/views/edit_team.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
;(function (define) {
;(function(define) {
'use strict';

define(['backbone',
'underscore',
'gettext',
'edx-ui-toolkit/js/utils/html-utils',
'js/views/fields',
'teams/js/models/team',
'common/js/components/utils/view_utils',
'text!teams/templates/edit-team.underscore'],
function (Backbone, _, gettext, FieldViews, TeamModel, ViewUtils, editTeamTemplate) {
function(Backbone, _, gettext, HtmlUtils, FieldViews, TeamModel, ViewUtils, editTeamTemplate) {
return Backbone.View.extend({

maxTeamNameLength: 255,
Expand All @@ -30,12 +31,12 @@
if (this.action === 'create') {
this.teamModel = new TeamModel({});
this.teamModel.url = this.context.teamsUrl;
this.primaryButtonTitle = gettext("Create");
} else if(this.action === 'edit' ) {
this.primaryButtonTitle = gettext('Create');
} else if (this.action === 'edit') {
this.teamModel = options.model;
this.teamModel.url = this.context.teamsDetailUrl.replace('team_id', options.model.get('id')) +
'?expand=user';
this.primaryButtonTitle = gettext("Update");
this.primaryButtonTitle = gettext('Update');
}

this.teamNameField = new FieldViews.TextFieldView({
Expand All @@ -51,7 +52,7 @@
valueAttribute: 'description',
editable: 'always',
showMessages: false,
helpMessage: gettext('A short description of the team to help other learners understand the goals or direction of the team (maximum 300 characters).')
helpMessage: gettext('A short description of the team to help other learners understand the goals or direction of the team (maximum 300 characters).') // jshint ignore:line
});

this.teamLanguageField = new FieldViews.DropdownFieldView({
Expand All @@ -62,7 +63,7 @@
showMessages: false,
titleIconName: 'fa-comment-o',
options: this.context.languages,
helpMessage: gettext('The language that team members primarily use to communicate with each other.')
helpMessage: gettext('The language that team members primarily use to communicate with each other.') // jshint ignore:line
});

this.teamCountryField = new FieldViews.DropdownFieldView({
Expand All @@ -78,11 +79,14 @@
},

render: function() {
this.$el.html(_.template(editTeamTemplate) ({
primaryButtonTitle: this.primaryButtonTitle,
action: this.action,
totalMembers: _.isUndefined(this.teamModel) ? 0 : this.teamModel.get('membership').length
}));
HtmlUtils.setHtml(
this.$el,
HtmlUtils.template(editTeamTemplate)({
primaryButtonTitle: this.primaryButtonTitle,
action: this.action,
totalMembers: _.isUndefined(this.teamModel) ? 0 : this.teamModel.get('membership').length
})
);
this.set(this.teamNameField, '.team-required-fields');
this.set(this.teamDescriptionField, '.team-required-fields');
this.set(this.teamLanguageField, '.team-optional-fields');
Expand All @@ -99,7 +103,7 @@
}
},

createOrUpdateTeam: function (event) {
createOrUpdateTeam: function(event) {
event.preventDefault();
var view = this,
teamLanguage = this.teamLanguageField.fieldValue(),
Expand All @@ -117,7 +121,7 @@
if (this.action === 'create') {
data.course_id = this.context.courseID;
data.topic_id = this.topic.id;
} else if (this.action === 'edit' ) {
} else if (this.action === 'edit') {
saveOptions.patch = true;
saveOptions.contentType = 'application/merge-patch+json';
}
Expand All @@ -140,23 +144,23 @@
})
.fail(function(data) {
var response = JSON.parse(data.responseText);
var message = gettext("An error occurred. Please try again.");
if ('user_message' in response){
var message = gettext('An error occurred. Please try again.');
if ('user_message' in response) {
message = response.user_message;
}
view.showMessage(message, message);
});
},

validateTeamData: function (data) {
validateTeamData: function(data) {
var status = true,
message = gettext('Check the highlighted fields below and try again.');
var srMessages = [];

this.teamNameField.unhighlightField();
this.teamDescriptionField.unhighlightField();

if (_.isEmpty(data.name.trim()) ) {
if (_.isEmpty(data.name.trim())) {
status = false;
this.teamNameField.highlightFieldOnError();
srMessages.push(
Expand All @@ -170,7 +174,7 @@
);
}

if (_.isEmpty(data.description.trim()) ) {
if (_.isEmpty(data.description.trim())) {
status = false;
this.teamDescriptionField.highlightFieldOnError();
srMessages.push(
Expand All @@ -191,7 +195,7 @@
};
},

showMessage: function (message, screenReaderMessage) {
showMessage: function(message, screenReaderMessage) {
this.$('.wrapper-msg').removeClass('is-hidden');
this.$('.msg-content .copy p').text(message);
this.$('.wrapper-msg').focus();
Expand All @@ -201,12 +205,12 @@
}
},

cancelAndGoBack: function (event) {
cancelAndGoBack: function(event) {
event.preventDefault();
var url;
if (this.action === 'create') {
url = 'topics/' + this.topic.id;
} else if (this.action === 'edit' ) {
} else if (this.action === 'edit') {
url = 'teams/' + this.topic.id + '/' + this.teamModel.get('id');
}
Backbone.history.navigate(url, {trigger: true});
Expand Down
47 changes: 31 additions & 16 deletions lms/djangoapps/teams/static/teams/js/views/edit_team_members.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
'jquery',
'underscore',
'gettext',
'teams/js/models/team',
'teams/js/views/team_utils',
'common/js/components/utils/view_utils',
'edx-ui-toolkit/js/utils/html-utils',
'edx-ui-toolkit/js/utils/string-utils',
'common/js/components/utils/view_utils',
'teams/js/views/team_utils',
'teams/js/models/team',
'text!teams/templates/edit-team-member.underscore',
'text!teams/templates/date.underscore'
],
function(Backbone, $, _, gettext, TeamModel, TeamUtils, ViewUtils, StringUtils,
editTeamMemberTemplate, dateTemplate) {
function(Backbone, $, _, gettext, HtmlUtils, StringUtils, ViewUtils, TeamUtils, TeamModel,
editTeamMemberTemplate, dateTemplate) {
return Backbone.View.extend({
dateTemplate: _.template(dateTemplate),
teamMemberTemplate: _.template(editTeamMemberTemplate),
dateTemplate: HtmlUtils.template(dateTemplate),
teamMemberTemplate: HtmlUtils.template(editTeamMemberTemplate),
errorMessage: gettext('An error occurred while removing the member from the team. Try again.'),

events: {
Expand All @@ -36,10 +37,17 @@

render: function() {
if (this.model.get('membership').length === 0) {
this.$el.html('<p>' + gettext('This team does not have any members.') + '</p>');
HtmlUtils.setHtml(
this.$el.html,
HtmlUtils.joinHtml(
HtmlUtils.HTML('<p>'),
gettext('This team does not have any members.'),
HtmlUtils.HTML('</p>')
)
);
}
else {
this.$el.html('<ul class="edit-members"></ul>');
HtmlUtils.setHtml(this.$el, '<ul class="edit-members"></ul>');
this.renderTeamMembers();
}
return this;
Expand All @@ -64,13 +72,20 @@
);

// It is assumed that the team member array is automatically in the order of date joined.
self.$('.edit-members').append(self.teamMemberTemplate({
imageUrl: membership.user.profile_image.image_url_medium,
username: membership.user.username,
memberProfileUrl: '/u/' + membership.user.username,
dateJoined: dateJoined,
lastActive: lastActivity
}));
HtmlUtils.append(
self.$('.edit-members'),
self.teamMemberTemplate({
imageUrl: membership.user.profile_image.image_url_medium,
imageUrlAlt: StringUtils.interpolate(
"{username}'s profile page", // jshint ignore:line
{username: membership.user.username}
),
username: membership.user.username,
memberProfileUrl: '/u/' + membership.user.username,
dateJoined: dateJoined,
lastActive: lastActivity
})
);
});
this.$('abbr').timeago();
},
Expand Down
11 changes: 6 additions & 5 deletions lms/djangoapps/teams/static/teams/js/views/instructor_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
define(['backbone',
'underscore',
'gettext',
'edx-ui-toolkit/js/utils/html-utils',
'teams/js/views/team_utils',
'common/js/components/utils/view_utils',
'edx-ui-toolkit/js/utils/html-utils',
'edx-ui-toolkit/js/utils/string-utils',
'text!teams/templates/instructor-tools.underscore'
],
function(Backbone, _, gettext, TeamUtils, ViewUtils, HtmlUtils, instructorToolbarTemplate) {
function(Backbone, _, gettext, HtmlUtils, TeamUtils, ViewUtils, StringUtils, instructorToolbarTemplate) {
return Backbone.View.extend({

events: {
Expand All @@ -18,13 +19,13 @@
},

initialize: function(options) {
this.template = _.template(instructorToolbarTemplate);
this.template = HtmlUtils.template(instructorToolbarTemplate);
this.team = options.team;
this.teamEvents = options.teamEvents;
},

render: function() {
this.$el.html(this.template);
HtmlUtils.setHtml(this.$el, this.template());
return this;
},

Expand Down Expand Up @@ -55,7 +56,7 @@
});
Backbone.history.navigate('topics/' + self.team.get('topic_id'), {trigger: true});
TeamUtils.showMessage(
HtmlUtils.interpolateHtml(
StringUtils.interpolate(
gettext('Team "{team}" successfully deleted.'),
{team: self.team.get('name')}
),
Expand Down
19 changes: 14 additions & 5 deletions lms/djangoapps/teams/static/teams/js/views/my_teams.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
;(function (define) {
;(function(define) {
'use strict';

define(['backbone', 'gettext', 'teams/js/views/teams'],
function (Backbone, gettext, TeamsView) {
define(['backbone', 'gettext',
'edx-ui-toolkit/js/utils/html-utils',
'teams/js/views/teams'],
function(Backbone, gettext, HtmlUtils, TeamsView) {
var MyTeamsView = TeamsView.extend({
render: function() {
var view = this;
if (this.collection.isStale) {
this.$el.html('');
HtmlUtils.setHtml(this.$el, '');
}
this.collection.refresh()
.done(function() {
TeamsView.prototype.render.call(view);
if (view.collection.length === 0) {
view.$el.append('<p>' + gettext('You are not currently a member of any team.') + '</p>');
HtmlUtils.append(
view.$el,
HtmlUtils.joinHtml(
HtmlUtils.HTML('<p>'),
gettext('You are not currently a member of any team.'),
HtmlUtils.HTML('</p>')
)
);
}
});
return this;
Expand Down

0 comments on commit 08bcde2

Please sign in to comment.