Support for joined date to profile.

LEARNER-1858
This commit is contained in:
Robert Raposa
2017-07-28 16:41:34 -04:00
committed by Diana Huang
parent 98ee25fbab
commit 7cc9400b91
9 changed files with 87 additions and 29 deletions

View File

@@ -74,7 +74,8 @@ define(['underscore'], function(_) {
year_of_birth: '3', // Note: test birth year range is a string from 0-3
requires_parental_consent: false,
country: '1',
language: null,
language: 'en-US',
date_joined: 'December 17, 1995 03:24:00',
bio: 'About the student',
language_proficiencies: [{code: '1'}],
profile_image: PROFILE_IMAGE,
@@ -82,7 +83,7 @@ define(['underscore'], function(_) {
};
var DEFAULT_USER_PREFERENCES_DATA = {
'pref-lang': '2',
'time_zone': null
time_zone: 'America/New_York'
};
var createAccountSettingsData = function(options) {

View File

@@ -326,19 +326,6 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper
expect(view.$('.u-field-value > a .u-field-link-title-' + view.options.valueAttribute).text().trim()).toBe(fieldData.linkTitle);
});
it('correctly renders LinkFieldView', function() {
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.LinkFieldView, {
title: 'Title',
linkTitle: 'Link title',
helpMessage: 'Click the link.',
valueAttribute: 'password-reset'
});
var view = new FieldViews.LinkFieldView(fieldData).render();
FieldViewsSpecHelpers.expectTitleAndMessageToContain(view, fieldData.title, fieldData.helpMessage);
expect(view.$('.u-field-value > a .u-field-link-title-' + view.options.valueAttribute).text().trim()).toBe(fieldData.linkTitle);
});
it("can't persist changes if persistChanges is off", function() {
requests = AjaxHelpers.requests(this);
var fieldClasses = [
@@ -350,5 +337,21 @@ define(['backbone', 'jquery', 'underscore', 'edx-ui-toolkit/js/utils/spec-helper
FieldViewsSpecHelpers.verifyPersistence(fieldClasses[i], requests);
}
});
it('correctly renders DateFieldView', function() {
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.DateFieldView, {
title: 'Title',
helpMessage: '',
dateFormat: 'MMM YYYY',
valueAttribute: 'date_joined',
userLanguage: 'en-US',
userTimezone: 'America/New_York'
}),
joinDate = new Date(1990, 0, 15),
view;
fieldData.model.set({date_joined: joinDate.toDateString()});
view = new FieldViews.DateFieldView(fieldData).render();
expect(view.$('.u-field-value').text().trim()).toBe('Jan 1990');
});
});
});

View File

@@ -3,13 +3,14 @@
define([
'gettext', 'jquery', 'underscore', 'backbone',
'edx-ui-toolkit/js/utils/html-utils',
'edx-ui-toolkit/js/utils/date-utils',
'text!templates/fields/field_readonly.underscore',
'text!templates/fields/field_dropdown.underscore',
'text!templates/fields/field_link.underscore',
'text!templates/fields/field_text.underscore',
'text!templates/fields/field_textarea.underscore',
'backbone-super'
], function(gettext, $, _, Backbone, HtmlUtils,
], function(gettext, $, _, Backbone, HtmlUtils, DateUtils,
field_readonly_template,
field_dropdown_template,
field_link_template,
@@ -313,6 +314,38 @@
}
});
FieldViews.DateFieldView = FieldViews.ReadonlyFieldView.extend({
fieldType: 'date',
timezoneFormattedDate: function() {
var context;
context = {
datetime: new Date(this.modelValue()),
language: this.options.userLanguage,
timezone: this.options.userTimezone,
format: this.options.dateFormat
};
return DateUtils.localize(context);
},
render: function() {
HtmlUtils.setHtml(this.$el, HtmlUtils.template(this.fieldTemplate)({
id: this.options.valueAttribute,
title: this.options.title,
screenReaderTitle: this.options.screenReaderTitle || this.options.title,
value: this.timezoneFormattedDate(),
message: this.helpMessage
}));
this.delegateEvents();
return this;
},
updateValueInField: function() {
this.$('.u-field-value ').text(this.timezoneFormattedDate());
}
});
FieldViews.TextFieldView = FieldViews.EditableFieldView.extend({
fieldType: 'text',

View File

@@ -235,7 +235,7 @@
}
.u-field-value-readonly {
@extend %t-weight3;
font-weight: 500;
font-family: $sans-serif;
color: $darkest-base-font-color;
}
@@ -245,6 +245,15 @@
display: block;
}
&:not(.u-field-readonly):not(:last-child) {
padding-bottom: $baseline/4;
border-bottom: 1px solid $gray-lighter;
&:hover.mode-placeholder {
padding-bottom: $baseline/5;
border-bottom: 2px dashed $link-color;
}
}
&.u-field-dropdown {
position: relative;
@@ -252,15 +261,6 @@
cursor: pointer;
}
&:not(:last-child) {
padding-bottom: $baseline/4;
border-bottom: 1px solid $gray-lighter;
&:hover.mode-placeholder {
padding-bottom: $baseline/5;
border-bottom: 2px dashed $link-color;
}
}
}
}