Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Underscore.string #11963

Merged
merged 4 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,4 @@ Sanford Student <sstudent@edx.org>
Florian Haas <florian@hastexo.com>
Leonardo Qui帽onez <leonardo.quinonez@edunext.co>
Dmitry Viskov <dmitry.viskov@webenterprise.ru>
Brian Jacobel <bjacobel@edx.org>
2 changes: 1 addition & 1 deletion cms/static/cms/js/require-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"moment-with-locales": "js/vendor/moment-with-locales.min",
"text": 'js/vendor/requirejs/text',
"underscore": "common/js/vendor/underscore",
"underscore.string": "js/vendor/underscore.string.min",
"underscore.string": "common/js/vendor/underscore.string",
"backbone": "js/vendor/backbone-min",
"backbone-relational" : "js/vendor/backbone-relational.min",
"backbone.associations": "js/vendor/backbone-associations-min",
Expand Down
2 changes: 1 addition & 1 deletion cms/static/coffee/spec/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ requirejs.config({
"moment-with-locales": "xmodule_js/common_static/js/vendor/moment-with-locales.min",
"text": "xmodule_js/common_static/js/vendor/requirejs/text",
"underscore": "xmodule_js/common_static/common/js/vendor/underscore",
"underscore.string": "xmodule_js/common_static/js/vendor/underscore.string.min",
"underscore.string": "xmodule_js/common_static/common/js/vendor/underscore.string",
"backbone": "xmodule_js/common_static/js/vendor/backbone-min",
"backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min",
"backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min",
Expand Down
2 changes: 1 addition & 1 deletion cms/static/coffee/spec/main_squire.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ requirejs.config({
"date": "xmodule_js/common_static/js/vendor/date",
"text": "xmodule_js/common_static/js/vendor/requirejs/text",
"underscore": "xmodule_js/common_static/common/js/vendor/underscore",
"underscore.string": "xmodule_js/common_static/js/vendor/underscore.string.min",
"underscore.string": "xmodule_js/common_static/common/js/vendor/underscore.string",
"backbone": "xmodule_js/common_static/js/vendor/backbone-min",
"backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min",
"backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min",
Expand Down
5 changes: 0 additions & 5 deletions cms/static/coffee/spec/views/textbook_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js
describe "EditTextbook", ->
describe "Basic", ->
tpl = readFixtures('edit-textbook.underscore')
chapterTpl = readFixtures('edit-chapter.underscore')

beforeEach ->
setFixtures($("<script>", {id: "edit-textbook-tpl", type: "text/template"}).text(tpl))
appendSetFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(chapterTpl))
appendSetFixtures(sandbox({id: "page-notification"}))
appendSetFixtures(sandbox({id: "page-prompt"}))
@model = new Textbook({name: "Life Sciences", editing: true})
Expand Down Expand Up @@ -298,11 +296,8 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js


describe "EditChapter", ->
tpl = readFixtures("edit-chapter.underscore")

beforeEach ->
modal_helpers.installModalTemplates()
appendSetFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(tpl))
@model = new Chapter
name: "Chapter 1"
asset_path: "/ch1.pdf"
Expand Down
172 changes: 85 additions & 87 deletions cms/static/js/certificates/models/certificate.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,98 @@
// Backbone.js Application Model: Certificate

define([ // jshint ignore:line
'underscore',
'underscore.string',
'backbone',
'backbone-relational',
'backbone.associations',
'gettext',
'coffee/src/main',
'js/certificates/models/signatory',
'js/certificates/collections/signatories'
],
function (_, str, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeSrcMain,
SignatoryModel, SignatoryCollection) {
'use strict';
_.str = str;
var Certificate = Backbone.RelationalModel.extend({
idAttribute: "id",
defaults: {
// Metadata fields currently displayed in web forms
course_title: '',
define([
'underscore',
'backbone',
'backbone-relational',
'backbone.associations',
'gettext',
'coffee/src/main',
'js/certificates/models/signatory',
'js/certificates/collections/signatories'
],
function(_, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeSrcMain,
SignatoryModel, SignatoryCollection) {
'use strict';
var Certificate = Backbone.RelationalModel.extend({
idAttribute: 'id',
defaults: {
// Metadata fields currently displayed in web forms
course_title: '',

// Metadata fields not currently displayed in web forms
name: 'Name of the certificate',
description: 'Description of the certificate',
// Metadata fields not currently displayed in web forms
name: 'Name of the certificate',
description: 'Description of the certificate',

// Internal-use only, not displayed in web forms
version: 1,
is_active: false
},
// Internal-use only, not displayed in web forms
version: 1,
is_active: false
},

// Certificate child collection/model mappings (backbone-relational)
relations: [{
type: Backbone.HasMany,
key: 'signatories',
relatedModel: SignatoryModel,
collectionType: SignatoryCollection,
reverseRelation: {
key: 'certificate',
includeInJSON: "id"
}
}],
// Certificate child collection/model mappings (backbone-relational)
relations: [{
type: Backbone.HasMany,
key: 'signatories',
relatedModel: SignatoryModel,
collectionType: SignatoryCollection,
reverseRelation: {
key: 'certificate',
includeInJSON: 'id'
}
}],

initialize: function(attributes, options) {
// Set up the initial state of the attributes set for this model instance
this.canBeEmpty = options && options.canBeEmpty;
if(options.add) {
// Ensure at least one child Signatory model is defined for any new Certificate model
attributes.signatories = new SignatoryModel({certificate: this});
}
this.setOriginalAttributes();
return this;
},
initialize: function(attributes, options) {
// Set up the initial state of the attributes set for this model instance
this.canBeEmpty = options && options.canBeEmpty;
if (options.add) {
// Ensure at least one child Signatory model is defined for any new Certificate model
attributes.signatories = new SignatoryModel({certificate: this});
}
this.setOriginalAttributes();
return this;
},

parse: function (response) {
// Parse must be defined for the model, but does not need to do anything special right now
return response;
},
parse: function(response) {
// Parse must be defined for the model, but does not need to do anything special right now
return response;
},

setOriginalAttributes: function() {
// Remember the current state of this model (enables edit->cancel use cases)
this._originalAttributes = this.parse(this.toJSON());
setOriginalAttributes: function() {
// Remember the current state of this model (enables edit->cancel use cases)
this._originalAttributes = this.parse(this.toJSON());

this.get("signatories").each(function (modelSignatory) {
modelSignatory.setOriginalAttributes();
});
this.get('signatories').each(function(modelSignatory) {
modelSignatory.setOriginalAttributes();
});

// If no url is defined for the signatories child collection we'll need to create that here as well
if(!this.isNew() && !this.get('signatories').url) {
this.get('signatories').url = this.collection.url + '/' + this.get('id') + '/signatories';
}
},
// If no url is defined for the signatories child collection we'll need to create that here as well
if (!this.isNew() && !this.get('signatories').url) {
this.get('signatories').url = this.collection.url + '/' + this.get('id') + '/signatories';
}
},

validate: function(attrs) {
// Ensure the provided attributes set meets our expectations for format, type, etc.
if (!_.str.trim(attrs.name)) {
return {
message: gettext('Certificate name is required.'),
attributes: {name: true}
};
}
var all_signatories_valid = _.every(attrs.signatories.models, function(signatory){
return signatory.isValid();
});
if (!all_signatories_valid) {
return {
message: gettext('Signatory field(s) has invalid data.'),
attributes: {signatories: attrs.signatories.models}
};
}
},
validate: function(attrs) {
// Ensure the provided attributes set meets our expectations for format, type, etc.
if (!attrs.name.trim()) {
return {
message: gettext('Certificate name is required.'),
attributes: {name: true}
};
}
var allSignatoriesValid = _.every(attrs.signatories.models, function(signatory){
return signatory.isValid();
});
if (!allSignatoriesValid) {
return {
message: gettext('Signatory field(s) has invalid data.'),
attributes: {signatories: attrs.signatories.models}
};
}
},

reset: function() {
// Revert the attributes of this model instance back to initial state
this.set(this._originalAttributes, { parse: true, validate: true });
}
reset: function() {
// Revert the attributes of this model instance back to initial state
this.set(this._originalAttributes, {parse: true, validate: true});
}
});
return Certificate;
});
return Certificate;
});
13 changes: 5 additions & 8 deletions cms/static/js/certificates/models/signatory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

define([ // jshint ignore:line
'underscore',
'underscore.string',
'backbone',
'backbone-relational',
'gettext'
'backbone-relational'
],
function(_, str, Backbone, BackboneRelational, gettext) {
function(_, Backbone) {
'use strict';
_.str = str;

var Signatory = Backbone.RelationalModel.extend({
idAttribute: "id",
idAttribute: 'id',
defaults: {
name: '',
title: '',
Expand All @@ -26,7 +23,7 @@ function(_, str, Backbone, BackboneRelational, gettext) {
return this;
},

parse: function (response) {
parse: function(response) {
// Parse must be defined for the model, but does not need to do anything special right now
return response;
},
Expand All @@ -38,7 +35,7 @@ function(_, str, Backbone, BackboneRelational, gettext) {

reset: function() {
// Revert the attributes of this model instance back to initial state
this.set(this._originalAttributes, { parse: true, validate: true });
this.set(this._originalAttributes, {parse: true, validate: true});
}
});
return Signatory;
Expand Down
19 changes: 9 additions & 10 deletions cms/static/js/models/group_configuration.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
define([
'backbone', 'underscore', 'underscore.string', 'gettext', 'js/models/group',
'js/collections/group', 'backbone.associations', 'coffee/src/main'
'backbone', 'underscore', 'gettext', 'js/models/group', 'js/collections/group',
'backbone.associations', 'coffee/src/main'
],
function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
function(Backbone, _, gettext, GroupModel, GroupCollection) {
'use strict';
_.str = str;
var GroupConfiguration = Backbone.AssociatedModel.extend({
defaults: function() {
return {
Expand Down Expand Up @@ -49,7 +48,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
},

reset: function() {
this.set(this._originalAttributes, { parse: true, validate: true });
this.set(this._originalAttributes, {parse: true, validate: true});
},

isDirty: function() {
Expand Down Expand Up @@ -84,7 +83,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
},

validate: function(attrs) {
if (!_.str.trim(attrs.name)) {
if (!attrs.name.trim()) {
return {
message: gettext('Group Configuration name is required.'),
attributes: {name: true}
Expand All @@ -94,7 +93,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
if (!this.canBeEmpty && attrs.groups.length < 1) {
return {
message: gettext('There must be at least one group.'),
attributes: { groups: true }
attributes: {groups: true}
};
} else {
// validate all groups
Expand All @@ -111,21 +110,21 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
if (!invalidGroups.isEmpty()) {
return {
message: gettext('All groups must have a name.'),
attributes: { groups: invalidGroups.toJSON() }
attributes: {groups: invalidGroups.toJSON()}
};
}

var groupNames = validGroups.map(function(group) { return group.get('name'); });
if (groupNames.length !== _.uniq(groupNames).length) {
return {
message: gettext('All groups must have a unique name.'),
attributes: { groups: validGroups.toJSON() }
attributes: {groups: validGroups.toJSON()}
};
}
}
},

groupRemoved: function () {
groupRemoved: function() {
this.setOriginalAttributes();
}
});
Expand Down