Commit bc05cd0c by Usman Khalid Committed by Andy Armstrong

Resolving JS lint errors for account settings & learner profile page.

TNL-1855
parent f03841a6
...@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'js/student_account/views/account_settings_view' 'js/student_account/views/account_settings_view'
], ],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViewsSpecHelpers, Helpers, function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViewsSpecHelpers, Helpers,
AccountSettingsFieldViewSpecHelpers, AccountSettingsPage, AccountSettingsView) { AccountSettingsFieldViewSpecHelpers, AccountSettingsPage) {
'use strict'; 'use strict';
describe("edx.user.AccountSettingsFactory", function () { describe("edx.user.AccountSettingsFactory", function () {
...@@ -44,7 +44,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -44,7 +44,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'disconnect_url': 'yetanother2.com/auth/disconnect' 'disconnect_url': 'yetanother2.com/auth/disconnect'
} }
] ]
} };
var requests; var requests;
...@@ -103,7 +103,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -103,7 +103,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false); Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
Helpers.expectSettingsSectionsButNotFieldsToBeRendered(accountSettingsView); Helpers.expectSettingsSectionsButNotFieldsToBeRendered(accountSettingsView);
var request = requests[1]; request = requests[1];
expect(request.method).toBe('GET'); expect(request.method).toBe('GET');
expect(request.url).toBe(Helpers.USER_PREFERENCES_API_URL); expect(request.url).toBe(Helpers.USER_PREFERENCES_API_URL);
...@@ -131,7 +131,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -131,7 +131,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false); Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false);
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false); Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView) Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView);
}); });
it("expects all fields to behave correctly", function () { it("expects all fields to behave correctly", function () {
......
...@@ -22,7 +22,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -22,7 +22,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
view.$(selector).click(); view.$(selector).click();
FieldViewsSpecHelpers.expectMessageContains(view, 'Linking'); FieldViewsSpecHelpers.expectMessageContains(view, 'Linking');
expect(view.redirect_to).toHaveBeenCalledWith(data.connectUrl); expect(view.redirect_to).toHaveBeenCalledWith(data.connectUrl);
} };
return { return {
verifyAuthField: verifyAuthField verifyAuthField: verifyAuthField
......
...@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'js/student_account/models/user_account_model', 'js/student_account/models/user_account_model',
'string_utils'], 'string_utils'],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViews, FieldViewsSpecHelpers, function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViews, FieldViewsSpecHelpers,
AccountSettingsFieldViewSpecHelpers, AccountSettingsFieldViews, UserAccountModel) { AccountSettingsFieldViewSpecHelpers, AccountSettingsFieldViews) {
'use strict'; 'use strict';
describe("edx.AccountSettingsFieldViews", function () { describe("edx.AccountSettingsFieldViews", function () {
...@@ -14,10 +14,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -14,10 +14,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var requests, var requests,
timerCallback; timerCallback;
var USERNAME = 'Legolas',
FULLNAME = 'Legolas Thranduil',
EMAIL = 'legolas@woodland.middlearth';
beforeEach(function () { beforeEach(function () {
TemplateHelpers.installTemplate('templates/fields/field_readonly'); TemplateHelpers.installTemplate('templates/fields/field_readonly');
TemplateHelpers.installTemplate('templates/fields/field_dropdown'); TemplateHelpers.installTemplate('templates/fields/field_dropdown');
...@@ -39,9 +35,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -39,9 +35,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var view = new AccountSettingsFieldViews.PasswordFieldView(fieldData).render(); var view = new AccountSettingsFieldViews.PasswordFieldView(fieldData).render();
view.$('.u-field-value > a').click(); view.$('.u-field-value > a').click();
AjaxHelpers.expectRequest(requests, 'POST', '/password_reset', "email=legolas%40woodland.middlearth"); AjaxHelpers.expectRequest(requests, 'POST', '/password_reset', "email=legolas%40woodland.middlearth");
AjaxHelpers.respondWithJson(requests, {"success": "true"}) AjaxHelpers.respondWithJson(requests, {"success": "true"});
FieldViewsSpecHelpers.expectMessageContains(view, FieldViewsSpecHelpers.expectMessageContains(
"We've sent a message to legolas@woodland.middlearth. Click the link in the message to reset your password." view,
"We've sent a message to legolas@woodland.middlearth. " +
"Click the link in the message to reset your password."
); );
}); });
...@@ -61,18 +59,31 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -61,18 +59,31 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data); FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data);
AjaxHelpers.respondWithNoContent(requests); AjaxHelpers.respondWithNoContent(requests);
AjaxHelpers.expectRequest(requests, 'POST', '/i18n/setlang/', 'language=' + data[fieldData.valueAttribute]); AjaxHelpers.expectRequest(
requests,
'POST',
'/i18n/setlang/',
'language=' + data[fieldData.valueAttribute]
);
AjaxHelpers.respondWithNoContent(requests); AjaxHelpers.respondWithNoContent(requests);
FieldViewsSpecHelpers.expectMessageContains(view, "Your changes have been saved."); FieldViewsSpecHelpers.expectMessageContains(view, "Your changes have been saved.");
var data = {'language': FieldViewsSpecHelpers.SELECT_OPTIONS[1][0]}; data = {'language': FieldViewsSpecHelpers.SELECT_OPTIONS[1][0]};
view.$(selector).val(data[fieldData.valueAttribute]).change(); view.$(selector).val(data[fieldData.valueAttribute]).change();
FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data); FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data);
AjaxHelpers.respondWithNoContent(requests); AjaxHelpers.respondWithNoContent(requests);
AjaxHelpers.expectRequest(requests, 'POST', '/i18n/setlang/', 'language=' + data[fieldData.valueAttribute]); AjaxHelpers.expectRequest(
requests,
'POST',
'/i18n/setlang/',
'language=' + data[fieldData.valueAttribute]
);
AjaxHelpers.respondWithError(requests, 500); AjaxHelpers.respondWithError(requests, 500);
FieldViewsSpecHelpers.expectMessageContains(view, "You must sign out of edX and sign back in before your language changes take effect."); FieldViewsSpecHelpers.expectMessageContains(
view,
"You must sign out of edX and sign back in before your language changes take effect."
);
}); });
it("reads and saves the value correctly for LanguageProficienciesFieldView", function() { it("reads and saves the value correctly for LanguageProficienciesFieldView", function() {
......
...@@ -4,7 +4,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -4,7 +4,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'js/student_account/models/user_account_model', 'js/student_account/models/user_account_model',
'js/student_account/views/account_settings_view' 'js/student_account/views/account_settings_view'
], ],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, FieldViews, UserAccountModel, AccountSettingsView) { function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, FieldViews, UserAccountModel,
AccountSettingsView) {
'use strict'; 'use strict';
describe("edx.user.AccountSettingsView", function () { describe("edx.user.AccountSettingsView", function () {
...@@ -47,7 +48,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -47,7 +48,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
} }
] ]
} }
] ];
var accountSettingsView = new AccountSettingsView({ var accountSettingsView = new AccountSettingsView({
el: $('.wrapper-account-settings'), el: $('.wrapper-account-settings'),
...@@ -94,7 +95,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -94,7 +95,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
accountSettingsView.renderFields(); accountSettingsView.renderFields();
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false); Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false);
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false); Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView) Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView);
}); });
}); });
......
...@@ -46,7 +46,10 @@ define(['underscore'], function(_) { ...@@ -46,7 +46,10 @@ define(['underscore'], function(_) {
expect(sectionOneFieldElements.length).toBe(learnerProfileView.options.sectionOneFieldViews.length); expect(sectionOneFieldElements.length).toBe(learnerProfileView.options.sectionOneFieldViews.length);
_.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) { _.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) {
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionOneFieldViews[fieldIndex]); expectProfileElementContainsField(
sectionFieldElement,
learnerProfileView.options.sectionOneFieldViews[fieldIndex]
);
}); });
}; };
...@@ -58,7 +61,10 @@ define(['underscore'], function(_) { ...@@ -58,7 +61,10 @@ define(['underscore'], function(_) {
expect(sectionTwoFieldElements.length).toBe(learnerProfileView.options.sectionTwoFieldViews.length); expect(sectionTwoFieldElements.length).toBe(learnerProfileView.options.sectionTwoFieldViews.length);
_.each(sectionTwoFieldElements, function (sectionFieldElement, fieldIndex) { _.each(sectionTwoFieldElements, function (sectionFieldElement, fieldIndex) {
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionTwoFieldViews[fieldIndex]); expectProfileElementContainsField(
sectionFieldElement,
learnerProfileView.options.sectionTwoFieldViews[fieldIndex]
);
}); });
}; };
...@@ -75,13 +81,17 @@ define(['underscore'], function(_) { ...@@ -75,13 +81,17 @@ define(['underscore'], function(_) {
expect(sectionOneFieldElements.length).toBe(1); expect(sectionOneFieldElements.length).toBe(1);
_.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) { _.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) {
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionOneFieldViews[fieldIndex]); expectProfileElementContainsField(
sectionFieldElement,
learnerProfileView.options.sectionOneFieldViews[fieldIndex]
);
}); });
if (othersProfile) { if (othersProfile) {
expect($('.profile-private--message').text()).toBe('This edX learner is currently sharing a limited profile.') expect($('.profile-private--message').text())
.toBe('This edX learner is currently sharing a limited profile.');
} else { } else {
expect($('.profile-private--message').text()).toBe('You are currently sharing a limited profile.') expect($('.profile-private--message').text()).toBe('You are currently sharing a limited profile.');
} }
}; };
......
...@@ -8,8 +8,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -8,8 +8,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'js/student_profile/views/learner_profile_fields', 'js/student_profile/views/learner_profile_fields',
'js/student_profile/views/learner_profile_factory' 'js/student_profile/views/learner_profile_factory'
], ],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews, UserAccountModel, UserPreferencesModel, function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews,
LearnerProfileView, LearnerProfileFields, LearnerProfilePage) { UserAccountModel, UserPreferencesModel, LearnerProfileView, LearnerProfileFields, LearnerProfilePage) {
'use strict'; 'use strict';
describe("edx.user.LearnerProfileFactory", function () { describe("edx.user.LearnerProfileFactory", function () {
...@@ -33,7 +33,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -33,7 +33,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'country_options': Helpers.FIELD_OPTIONS, 'country_options': Helpers.FIELD_OPTIONS,
'language_options': Helpers.FIELD_OPTIONS, 'language_options': Helpers.FIELD_OPTIONS,
'has_preferences_access': true 'has_preferences_access': true
}) });
}; };
it("show loading error when UserAccountModel fails to load", function() { it("show loading error when UserAccountModel fails to load", function() {
...@@ -91,7 +91,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -91,7 +91,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false); Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView) LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
}); });
it("renders the full profile after models are successfully fetched", function() { it("renders the full profile after models are successfully fetched", function() {
...@@ -102,15 +102,15 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -102,15 +102,15 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
learnerProfileView = context.learnerProfileView; learnerProfileView = context.learnerProfileView;
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA; var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData['year_of_birth'] = 1989; accountSettingsData.year_of_birth = 1989;
accountSettingsData['requires_parental_consent'] = false; accountSettingsData.requires_parental_consent = false;
AjaxHelpers.respondWithJson(requests, accountSettingsData); AjaxHelpers.respondWithJson(requests, accountSettingsData);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
// sets the profile for full view. // sets the profile for full view.
context.accountPreferencesModel.set({account_privacy: 'all_users'}); context.accountPreferencesModel.set({account_privacy: 'all_users'});
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false) LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false);
}); });
it("renders the limited profile for undefined 'year_of_birth'", function() { it("renders the limited profile for undefined 'year_of_birth'", function() {
...@@ -123,7 +123,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -123,7 +123,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView) LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
}); });
it("renders the limited profile for under 13 users", function() { it("renders the limited profile for under 13 users", function() {
...@@ -134,12 +134,12 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -134,12 +134,12 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
learnerProfileView = context.learnerProfileView; learnerProfileView = context.learnerProfileView;
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA; var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData['requires_parental_consent'] = true; accountSettingsData.requires_parental_consent = true;
AjaxHelpers.respondWithJson(requests, accountSettingsData); AjaxHelpers.respondWithJson(requests, accountSettingsData);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView) LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
}); });
}); });
}); });
...@@ -8,8 +8,9 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -8,8 +8,9 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'js/student_profile/views/learner_profile_view', 'js/student_profile/views/learner_profile_view',
'js/student_account/views/account_settings_fields' 'js/student_account/views/account_settings_fields'
], ],
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews, UserAccountModel, function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews,
AccountPreferencesModel, LearnerProfileFields, LearnerProfileView, AccountSettingsFieldViews) { UserAccountModel, AccountPreferencesModel, LearnerProfileFields, LearnerProfileView,
AccountSettingsFieldViews) {
'use strict'; 'use strict';
describe("edx.user.LearnerProfileView", function () { describe("edx.user.LearnerProfileView", function () {
...@@ -18,8 +19,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -18,8 +19,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var accountSettingsModel = new UserAccountModel(); var accountSettingsModel = new UserAccountModel();
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA; var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData['year_of_birth'] = 1989; accountSettingsData.year_of_birth = 1989;
accountSettingsData['requires_parental_consent'] = false; accountSettingsData.requires_parental_consent = false;
accountSettingsModel.set(accountSettingsData); accountSettingsModel.set(accountSettingsData);
accountSettingsModel.set({'profile_is_public': profileIsPublic}); accountSettingsModel.set({'profile_is_public': profileIsPublic});
...@@ -84,7 +85,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -84,7 +85,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
editable: editable, editable: editable,
showMessages: false, showMessages: false,
title: 'About me', title: 'About me',
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you're taking courses on edX, or what you hope to learn.", placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
"what your interests are, why you're taking courses on edX, or what you hope to learn.",
valueAttribute: "bio", valueAttribute: "bio",
helpMessage: '' helpMessage: ''
}) })
...@@ -102,7 +104,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -102,7 +104,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
sectionOneFieldViews: sectionOneFieldViews, sectionOneFieldViews: sectionOneFieldViews,
sectionTwoFieldViews: sectionTwoFieldViews sectionTwoFieldViews: sectionTwoFieldViews
}); });
}; };
beforeEach(function () { beforeEach(function () {
...@@ -162,7 +163,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -162,7 +163,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
learnerProfileView.render(); learnerProfileView.render();
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false); Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, true) LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, true);
}); });
it("renders the fields as expected for others with limited access", function() { it("renders the fields as expected for others with limited access", function() {
......
...@@ -50,13 +50,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -50,13 +50,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
}; };
var createErrorMessage = function(attribute, user_message) { var createErrorMessage = function(attribute, user_message) {
var field_errors = {} var field_errors = {};
field_errors[attribute] = { field_errors[attribute] = {
"user_message": user_message "user_message": user_message
} };
return { return {
"field_errors": field_errors "field_errors": field_errors
} };
}; };
var expectTitleToBe = function(view, expectedTitle) { var expectTitleToBe = function(view, expectedTitle) {
...@@ -80,7 +80,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -80,7 +80,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var verifyMessageUpdates = function (view, data, timerCallback) { var verifyMessageUpdates = function (view, data, timerCallback) {
var message = 'Here to help!' var message = 'Here to help!';
view.message(message); view.message(message);
expectMessageContains(view, message); expectMessageContains(view, message);
...@@ -89,11 +89,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -89,11 +89,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
expectMessageContains(view, view.helpMessage); expectMessageContains(view, view.helpMessage);
view.showInProgressMessage(); view.showInProgressMessage();
expectMessageContains(view, view.indicators['inProgress']); expectMessageContains(view, view.indicators.inProgress);
expectMessageContains(view, view.messages['inProgress']); expectMessageContains(view, view.messages.inProgress);
view.showSuccessMessage(); view.showSuccessMessage();
expectMessageContains(view, view.indicators['success']); expectMessageContains(view, view.indicators.success);
expectMessageContains(view, view.getMessage('success')); expectMessageContains(view, view.getMessage('success'));
expect(timerCallback).not.toHaveBeenCalled(); expect(timerCallback).not.toHaveBeenCalled();
...@@ -102,24 +102,24 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -102,24 +102,24 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
responseText: JSON.stringify(createErrorMessage(data.valueAttribute, 'Ops, try again!.')), responseText: JSON.stringify(createErrorMessage(data.valueAttribute, 'Ops, try again!.')),
status: 400 status: 400
}); });
expectMessageContains(view, view.indicators['validationError']); expectMessageContains(view, view.indicators.validationError);
view.showErrorMessage({status: 500}); view.showErrorMessage({status: 500});
expectMessageContains(view, view.indicators['error']); expectMessageContains(view, view.indicators.error);
expectMessageContains(view, view.indicators['error']); expectMessageContains(view, view.indicators.error);
}; };
var verifySuccessMessageReset = function (view, data, timerCallback) { var verifySuccessMessageReset = function (view) {
view.showHelpMessage(); view.showHelpMessage();
expectMessageContains(view, view.helpMessage); expectMessageContains(view, view.helpMessage);
view.showSuccessMessage(); view.showSuccessMessage();
expectMessageContains(view, view.indicators['success']); expectMessageContains(view, view.indicators.success);
jasmine.Clock.tick(5000); jasmine.Clock.tick(5000);
// Message gets reset // Message gets reset
expectMessageContains(view, view.helpMessage); expectMessageContains(view, view.helpMessage);
view.showSuccessMessage(); view.showSuccessMessage();
expectMessageContains(view, view.indicators['success']); expectMessageContains(view, view.indicators.success);
// But if we change the message, it should not get reset. // But if we change the message, it should not get reset.
view.message("Do not reset this!"); view.message("Do not reset this!");
jasmine.Clock.tick(5000); jasmine.Clock.tick(5000);
...@@ -133,7 +133,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -133,7 +133,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
if (data.editable === 'toggle') { if (data.editable === 'toggle') {
expect(view.el).toHaveClass('mode-placeholder'); expect(view.el).toHaveClass('mode-placeholder');
expectTitleToBe(view, data.title); expectTitleToBe(view, data.title);
expectMessageContains(view, view.indicators['canEdit']); expectMessageContains(view, view.indicators.canEdit);
view.$el.click(); view.$el.click();
} else { } else {
expectTitleAndMessageToBe(view, data.title, data.helpMessage); expectTitleAndMessageToBe(view, data.title, data.helpMessage);
...@@ -145,8 +145,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -145,8 +145,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
view.$(data.valueInputSelector).val(data.validValue).change(); view.$(data.valueInputSelector).val(data.validValue).change();
// When the value in the field is changed // When the value in the field is changed
expect(view.fieldValue()).toBe(data.validValue); expect(view.fieldValue()).toBe(data.validValue);
expectMessageContains(view, view.indicators['inProgress']); expectMessageContains(view, view.indicators.inProgress);
expectMessageContains(view, view.messages['inProgress']); expectMessageContains(view, view.messages.inProgress);
request_data[data.valueAttribute] = data.validValue; request_data[data.valueAttribute] = data.validValue;
AjaxHelpers.expectJsonRequest( AjaxHelpers.expectJsonRequest(
requests, 'PATCH', url, request_data requests, 'PATCH', url, request_data
...@@ -158,7 +158,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -158,7 +158,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
expect(view.el).toHaveClass('mode-display'); expect(view.el).toHaveClass('mode-display');
view.$el.click(); view.$el.click();
} else { } else {
expectMessageContains(view, view.indicators['success']); expectMessageContains(view, view.indicators.success);
} }
view.$(data.valueInputSelector).val(data.invalidValue1).change(); view.$(data.valueInputSelector).val(data.invalidValue1).change();
...@@ -168,8 +168,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -168,8 +168,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
); );
AjaxHelpers.respondWithError(requests, 500); AjaxHelpers.respondWithError(requests, 500);
// When server returns a 500 error // When server returns a 500 error
expectMessageContains(view, view.indicators['error']); expectMessageContains(view, view.indicators.error);
expectMessageContains(view, view.messages['error']); expectMessageContains(view, view.messages.error);
expect(view.el).toHaveClass('mode-edit'); expect(view.el).toHaveClass('mode-edit');
view.$(data.valueInputSelector).val(data.invalidValue2).change(); view.$(data.valueInputSelector).val(data.invalidValue2).change();
...@@ -179,7 +179,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -179,7 +179,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
); );
AjaxHelpers.respondWithError(requests, 400, createErrorMessage(data.valueAttribute, data.validationError)); AjaxHelpers.respondWithError(requests, 400, createErrorMessage(data.valueAttribute, data.validationError));
// When server returns a validation error // When server returns a validation error
expectMessageContains(view, view.indicators['validationError']); expectMessageContains(view, view.indicators.validationError);
expectMessageContains(view, data.validationError); expectMessageContains(view, data.validationError);
expect(view.el).toHaveClass('mode-edit'); expect(view.el).toHaveClass('mode-edit');
...@@ -200,22 +200,20 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -200,22 +200,20 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
}; };
var verifyTextField = function (view, data, requests) { var verifyTextField = function (view, data, requests) {
var selector = '.u-field-value > input';
verifyEditableField(view, _.extend({ verifyEditableField(view, _.extend({
valueSelector: '.u-field-value', valueSelector: '.u-field-value',
valueInputSelector: '.u-field-value > input' valueInputSelector: '.u-field-value > input'
}, data }, data
), requests); ), requests);
} };
var verifyDropDownField = function (view, data, requests) { var verifyDropDownField = function (view, data, requests) {
var selector = '.u-field-value > select';
verifyEditableField(view, _.extend({ verifyEditableField(view, _.extend({
valueSelector: '.u-field-value', valueSelector: '.u-field-value',
valueInputSelector: '.u-field-value > select' valueInputSelector: '.u-field-value > select'
}, data }, data
), requests); ), requests);
} };
return { return {
SELECT_OPTIONS: SELECT_OPTIONS, SELECT_OPTIONS: SELECT_OPTIONS,
......
...@@ -6,8 +6,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -6,8 +6,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'use strict'; 'use strict';
var USERNAME = 'Legolas', var USERNAME = 'Legolas',
FULLNAME = 'Legolas Thranduil',
EMAIL = 'legolas@woodland.middlearth',
BIO = "My Name is Theon Greyjoy. I'm member of House Greyjoy"; BIO = "My Name is Theon Greyjoy. I'm member of House Greyjoy";
describe("edx.FieldViews", function () { describe("edx.FieldViews", function () {
...@@ -75,7 +73,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -75,7 +73,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
title: 'Preferred Language', title: 'Preferred Language',
valueAttribute: 'language', valueAttribute: 'language',
helpMessage: 'Your preferred language.' helpMessage: 'Your preferred language.'
}) });
var view = new fieldViewClass(fieldData); var view = new fieldViewClass(fieldData);
view.saveAttributes( view.saveAttributes(
...@@ -86,7 +84,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -86,7 +84,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var request = requests[0]; var request = requests[0];
expect(request.method).toBe('PATCH'); expect(request.method).toBe('PATCH');
expect(request.requestHeaders['Content-Type']).toBe('application/merge-patch+json;charset=utf-8'); expect(request.requestHeaders['Content-Type']).toBe('application/merge-patch+json;charset=utf-8');
expect(request.requestHeaders['Priority']).toBe('Urgent'); expect(request.requestHeaders.Priority).toBe('Urgent');
expect(request.requestBody).toBe('{"language":"ur"}'); expect(request.requestBody).toBe('{"language":"ur"}');
}); });
...@@ -199,7 +197,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -199,7 +197,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
title: 'About me', title: 'About me',
valueAttribute: 'bio', valueAttribute: 'bio',
helpMessage: 'Wicked is good', helpMessage: 'Wicked is good',
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you’re taking courses on edX, or what you hope to learn.", placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
"what your interests are, why you’re taking courses on edX, or what you hope to learn.",
editable: 'never' editable: 'never'
}); });
...@@ -210,7 +209,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -210,7 +209,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
expect(view.el).toHaveClass('mode-hidden'); expect(view.el).toHaveClass('mode-hidden');
expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue); expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue);
var bio = 'Too much to tell!' var bio = 'Too much to tell!';
view.model.set({'bio': bio}); view.model.set({'bio': bio});
expect(view.el).toHaveClass('mode-display'); expect(view.el).toHaveClass('mode-display');
expect(view.$('.u-field-value').text()).toBe(bio); expect(view.$('.u-field-value').text()).toBe(bio);
...@@ -222,12 +221,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -222,12 +221,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
requests = AjaxHelpers.requests(this); requests = AjaxHelpers.requests(this);
var valueInputSelector = '.u-field-value > textarea' var valueInputSelector = '.u-field-value > textarea';
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.TextareaFieldView, { var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.TextareaFieldView, {
title: 'About me', title: 'About me',
valueAttribute: 'bio', valueAttribute: 'bio',
helpMessage: 'Wicked is good', helpMessage: 'Wicked is good',
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you’re taking courses on edX, or what you hope to learn.", placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
"what your interests are, why you’re taking courses on edX, or what you hope to learn.",
editable: 'toggle' editable: 'toggle'
}); });
...@@ -236,7 +236,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -236,7 +236,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var view = new FieldViews.TextareaFieldView(fieldData).render(); var view = new FieldViews.TextareaFieldView(fieldData).render();
FieldViewsSpecHelpers.expectTitleToBe(view, fieldData.title); FieldViewsSpecHelpers.expectTitleToBe(view, fieldData.title);
FieldViewsSpecHelpers.expectMessageContains(view, view.indicators['canEdit']); FieldViewsSpecHelpers.expectMessageContains(view, view.indicators.canEdit);
expect(view.el).toHaveClass('mode-placeholder'); expect(view.el).toHaveClass('mode-placeholder');
expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue); expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue);
......
...@@ -45,5 +45,5 @@ ...@@ -45,5 +45,5 @@
} }
}); });
return UserAccountModel; return UserAccountModel;
}) });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
}); });
return UserPreferencesModel; return UserPreferencesModel;
}) });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -37,7 +37,10 @@ ...@@ -37,7 +37,10 @@
model: userAccountModel, model: userAccountModel,
title: gettext('Full Name'), title: gettext('Full Name'),
valueAttribute: 'name', valueAttribute: 'name',
helpMessage: gettext('The name that appears on your edX certificates. Other learners never see your full name.') helpMessage: gettext(
'The name that appears on your edX certificates. Other learners never see ' +
'your full name.'
)
}) })
}, },
{ {
...@@ -45,7 +48,10 @@ ...@@ -45,7 +48,10 @@
model: userAccountModel, model: userAccountModel,
title: gettext('Email Address'), title: gettext('Email Address'),
valueAttribute: 'email', valueAttribute: 'email',
helpMessage: gettext('The email address you use to sign in to edX. Communications from edX and your courses are sent to this address.') helpMessage: gettext(
'The email address you use to sign in to edX. Communications ' +
'from edX and your courses are sent to this address.'
)
}) })
}, },
{ {
...@@ -56,7 +62,10 @@ ...@@ -56,7 +62,10 @@
emailAttribute: 'email', emailAttribute: 'email',
linkTitle: gettext('Reset Password'), linkTitle: gettext('Reset Password'),
linkHref: fieldsData.password.url, linkHref: fieldsData.password.url,
helpMessage: gettext('When you click "Reset Password", a message will be sent to your email address. Click the link in the message to reset your password.') helpMessage: gettext(
'When you click "Reset Password", a message will be sent to your email address. ' +
'Click the link in the message to reset your password.'
)
}) })
}, },
{ {
...@@ -66,7 +75,10 @@ ...@@ -66,7 +75,10 @@
valueAttribute: 'pref-lang', valueAttribute: 'pref-lang',
required: true, required: true,
refreshPageOnSave: true, refreshPageOnSave: true,
helpMessage: gettext('The language used for the edX site. The site is currently available in a limited number of languages.'), helpMessage: gettext(
'The language used for the edX site. The site is currently available in a ' +
'limited number of languages.'
),
options: fieldsData.language.options options: fieldsData.language.options
}) })
} }
......
...@@ -9,8 +9,11 @@ ...@@ -9,8 +9,11 @@
AccountSettingsFieldViews.EmailFieldView = FieldViews.TextFieldView.extend({ AccountSettingsFieldViews.EmailFieldView = FieldViews.TextFieldView.extend({
successMessage: function() { successMessage: function() {
return this.indicators['success'] + interpolate_text( return this.indicators.success + interpolate_text(
gettext('We\'ve sent a confirmation message to {new_email_address}. Click the link in the message to update your email address.'), gettext(
'We\'ve sent a confirmation message to {new_email_address}. ' +
'Click the link in the message to update your email address.'
),
{'new_email_address': this.fieldValue()} {'new_email_address': this.fieldValue()}
); );
} }
...@@ -32,9 +35,13 @@ ...@@ -32,9 +35,13 @@
success: function () { success: function () {
view.showSuccessMessage(); view.showSuccessMessage();
}, },
error: function (xhr, status, error) { error: function () {
view.message( view.message(
view.indicators['error'] + gettext('You must sign out of edX and sign back in before your language changes take effect.') view.indicators.error +
gettext(
'You must sign out of edX and sign back in before your language ' +
'changes take effect.'
)
); );
} }
}); });
...@@ -51,10 +58,10 @@ ...@@ -51,10 +58,10 @@
linkClicked: function (event) { linkClicked: function (event) {
event.preventDefault(); event.preventDefault();
this.resetPassword(event) this.resetPassword(event);
}, },
resetPassword: function (event) { resetPassword: function () {
var data = {}; var data = {};
data[this.options.emailAttribute] = this.model.get(this.options.emailAttribute); data[this.options.emailAttribute] = this.model.get(this.options.emailAttribute);
...@@ -64,17 +71,20 @@ ...@@ -64,17 +71,20 @@
url: view.options.linkHref, url: view.options.linkHref,
data: data, data: data,
success: function () { success: function () {
view.showSuccessMessage() view.showSuccessMessage();
}, },
error: function (xhr, status, error) { error: function (xhr) {
view.showErrorMessage(xhr); view.showErrorMessage(xhr);
} }
}); });
}, },
successMessage: function () { successMessage: function () {
return this.indicators['success'] + interpolate_text( return this.indicators.success + interpolate_text(
gettext('We\'ve sent a message to {email_address}. Click the link in the message to reset your password.'), gettext(
'We\'ve sent a message to {email_address}. ' +
'Click the link in the message to reset your password.'
),
{'email_address': this.model.get(this.options.emailAttribute)} {'email_address': this.model.get(this.options.emailAttribute)}
); );
} }
...@@ -85,15 +95,15 @@ ...@@ -85,15 +95,15 @@
modelValue: function () { modelValue: function () {
var modelValue = this.model.get(this.options.valueAttribute); var modelValue = this.model.get(this.options.valueAttribute);
if (_.isArray(modelValue) && modelValue.length > 0) { if (_.isArray(modelValue) && modelValue.length > 0) {
return modelValue[0].code return modelValue[0].code;
} else { } else {
return ''; return '';
} }
}, },
saveValue: function () { saveValue: function () {
var attributes = {}; var attributes = {},
var value = this.fieldValue() ? [{'code': this.fieldValue()}] : []; value = this.fieldValue() ? [{'code': this.fieldValue()}] : [];
attributes[this.options.valueAttribute] = value; attributes[this.options.valueAttribute] = value;
this.saveAttributes(attributes); this.saveAttributes(attributes);
} }
...@@ -152,21 +162,21 @@ ...@@ -152,21 +162,21 @@
view.render(); view.render();
view.showSuccessMessage(); view.showSuccessMessage();
}, },
error: function (xhr, status, error) { error: function (xhr) {
view.showErrorMessage(xhr); view.showErrorMessage(xhr);
} }
}); });
}, },
inProgressMessage: function() { inProgressMessage: function() {
return this.indicators['inProgress'] + (this.options.connected ? gettext('Unlinking') : gettext('Linking')); return this.indicators.inProgress + (this.options.connected ? gettext('Unlinking') : gettext('Linking'));
}, },
successMessage: function() { successMessage: function() {
return this.indicators['success'] + gettext('Successfully unlinked.'); return this.indicators.success + gettext('Successfully unlinked.');
} }
}); });
return AccountSettingsFieldViews; return AccountSettingsFieldViews;
}) });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
var AccountSettingsView = Backbone.View.extend({ var AccountSettingsView = Backbone.View.extend({
initialize: function (options) { initialize: function () {
this.template = _.template($('#account_settings-tpl').text()); this.template = _.template($('#account_settings-tpl').text());
_.bindAll(this, 'render', 'renderFields', 'showLoadingError'); _.bindAll(this, 'render', 'renderFields', 'showLoadingError');
}, },
......
...@@ -78,7 +78,10 @@ ...@@ -78,7 +78,10 @@
editable: editable, editable: editable,
showMessages: false, showMessages: false,
title: gettext('About me'), title: gettext('About me'),
placeholderValue: gettext("Tell other edX learners a little about yourself: where you live, what your interests are, why you're taking courses on edX, or what you hope to learn."), placeholderValue: gettext(
"Tell other edX learners a little about yourself: where you live, what your interests are, " +
"why you're taking courses on edX, or what you hope to learn."
),
valueAttribute: "bio", valueAttribute: "bio",
helpMessage: '' helpMessage: ''
}) })
......
...@@ -16,15 +16,22 @@ ...@@ -16,15 +16,22 @@
}, },
message: function () { message: function () {
var accountSettingsLink = '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>';
if (this.profileIsPrivate) { if (this.profileIsPrivate) {
this._super(interpolate_text( this._super(interpolate_text(
gettext("You must specify your birth year before you can share your full profile. To specify your birth year, go to the {account_settings_page_link}"), gettext(
{'account_settings_page_link': '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>'} "You must specify your birth year before you can share your full profile. To specify " +
"your birth year, go to the {account_settings_page_link}"
),
{'account_settings_page_link': accountSettingsLink}
)); ));
} else if (this.requiresParentalConsent) { } else if (this.requiresParentalConsent) {
this._super(interpolate_text( this._super(interpolate_text(
gettext('You must be over 13 to share a full profile. If you are over 13, make sure that you have specified a birth year on the {account_settings_page_link}'), gettext(
{'account_settings_page_link': '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>'} 'You must be over 13 to share a full profile. If you are over 13, make sure that you ' +
'have specified a birth year on the {account_settings_page_link}'
),
{'account_settings_page_link': accountSettingsLink}
)); ));
} }
else { else {
...@@ -42,5 +49,5 @@ ...@@ -42,5 +49,5 @@
}); });
return LearnerProfileFieldViews; return LearnerProfileFieldViews;
}) });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
var LearnerProfileView = Backbone.View.extend({ var LearnerProfileView = Backbone.View.extend({
initialize: function (options) { initialize: function () {
this.template = _.template($('#learner_profile-tpl').text()); this.template = _.template($('#learner_profile-tpl').text());
_.bindAll(this, 'showFullProfile', 'render', 'renderFields', 'showLoadingError'); _.bindAll(this, 'showFullProfile', 'render', 'renderFields', 'showLoadingError');
this.listenTo(this.options.preferencesModel, "change:" + 'account_privacy', this.render); this.listenTo(this.options.preferencesModel, "change:" + 'account_privacy', this.render);
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
}, },
modelValueIsSet: function() { modelValueIsSet: function() {
return (this.modelValue() == true); return (this.modelValue() === true);
}, },
message: function (message) { message: function (message) {
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
this.lastSuccessMessageContext = context; this.lastSuccessMessageContext = context;
setTimeout(function () { setTimeout(function () {
if ((context === view.lastSuccessMessageContext) && (view.message().html() == successMessage)) { if ((context === view.lastSuccessMessageContext) && (view.message().html() === successMessage)) {
view.showHelpMessage(); view.showHelpMessage();
} }
}, messageRevertDelay); }, messageRevertDelay);
...@@ -111,9 +111,11 @@ ...@@ -111,9 +111,11 @@
showErrorMessage: function (xhr) { showErrorMessage: function (xhr) {
if (xhr.status === 400) { if (xhr.status === 400) {
try { try {
var errors = JSON.parse(xhr.responseText); var errors = JSON.parse(xhr.responseText),
var validationErrorMessage = Mustache.escapeHtml(errors['field_errors'][this.options.valueAttribute]['user_message']); validationErrorMessage = Mustache.escapeHtml(
var message = this.indicators['validationError'] + validationErrorMessage; errors.field_errors[this.options.valueAttribute].user_message
),
message = this.indicators.validationError + validationErrorMessage;
this.message(message); this.message(message);
} catch (error) { } catch (error) {
this.message(this.getMessage('error')); this.message(this.getMessage('error'));
...@@ -127,7 +129,9 @@ ...@@ -127,7 +129,9 @@
FieldViews.EditableFieldView = FieldViews.FieldView.extend({ FieldViews.EditableFieldView = FieldViews.FieldView.extend({
initialize: function (options) { initialize: function (options) {
_.bindAll(this, 'saveAttributes', 'saveSucceeded', 'showDisplayMode', 'showEditMode', 'startEditing', 'finishEditing'); _.bindAll(this, 'saveAttributes', 'saveSucceeded', 'showDisplayMode', 'showEditMode',
'startEditing', 'finishEditing'
);
this._super(options); this._super(options);
this.editable = _.isUndefined(this.options.editable) ? 'always': this.options.editable; this.editable = _.isUndefined(this.options.editable) ? 'always': this.options.editable;
...@@ -183,13 +187,13 @@ ...@@ -183,13 +187,13 @@
this.$el.addClass('mode-edit'); this.$el.addClass('mode-edit');
}, },
startEditing: function (event) { startEditing: function () {
if (this.editable === 'toggle' && this.mode !== 'edit') { if (this.editable === 'toggle' && this.mode !== 'edit') {
this.showEditMode(true); this.showEditMode(true);
} }
}, },
finishEditing: function(event) { finishEditing: function() {
if (this.fieldValue() !== this.modelValue()) { if (this.fieldValue() !== this.modelValue()) {
this.saveValue(); this.saveValue();
} else { } else {
...@@ -268,7 +272,7 @@ ...@@ -268,7 +272,7 @@
this.$('.u-field-value input').val(Mustache.escapeHtml(value)); this.$('.u-field-value input').val(Mustache.escapeHtml(value));
}, },
saveValue: function (event) { saveValue: function () {
var attributes = {}; var attributes = {};
attributes[this.options.valueAttribute] = this.fieldValue(); attributes[this.options.valueAttribute] = this.fieldValue();
this.saveAttributes(attributes); this.saveAttributes(attributes);
...@@ -315,15 +319,15 @@ ...@@ -315,15 +319,15 @@
modelValueIsSet: function() { modelValueIsSet: function() {
var value = this.modelValue(); var value = this.modelValue();
if (_.isUndefined(value) || _.isNull(value) || value == '') { if (_.isUndefined(value) || _.isNull(value) || value === '') {
return false; return false;
} else { } else {
return !(_.isUndefined(this.optionForValue(value))) return !(_.isUndefined(this.optionForValue(value)));
} }
}, },
optionForValue: function(value) { optionForValue: function(value) {
return _.find(this.options.options, function(option) { return option[0] == value; }) return _.find(this.options.options, function(option) { return option[0] === value; });
}, },
fieldValue: function () { fieldValue: function () {
...@@ -420,7 +424,7 @@ ...@@ -420,7 +424,7 @@
return this; return this;
}, },
adjustTextareaHeight: function(event) { adjustTextareaHeight: function() {
var textarea = this.$('textarea'); var textarea = this.$('textarea');
textarea.css('height', 'auto').css('height', textarea.prop('scrollHeight') + 10); textarea.css('height', 'auto').css('height', textarea.prop('scrollHeight') + 10);
}, },
...@@ -490,11 +494,11 @@ ...@@ -490,11 +494,11 @@
return this; return this;
}, },
linkClicked: function () { linkClicked: function (event) {
event.preventDefault(); event.preventDefault();
} }
}); });
return FieldViews; return FieldViews;
}) });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
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