Perform esacaping in the templates.
Use new best practices.
This commit is contained in:
@@ -857,7 +857,7 @@ define([
|
||||
|
||||
beforeEach(function() {
|
||||
TemplateHelpers.installTemplate('content-group-details', true);
|
||||
this.model = new GroupModel({name: 'Content Group', id: 0});
|
||||
this.model = new GroupModel({name: 'Content Group', id: 0, courseOutlineUrl: "CourseOutlineUrl"});
|
||||
|
||||
var saveableModel = new GroupConfigurationModel({
|
||||
name: 'Content Group Configuration',
|
||||
@@ -888,7 +888,7 @@ define([
|
||||
|
||||
it('should hide empty usage appropriately', function() {
|
||||
this.view.$('.hide-groups').click();
|
||||
assertHideEmptyUsages(this.view)
|
||||
assertHideEmptyUsages(this.view);
|
||||
});
|
||||
|
||||
it('should show non-empty usage appropriately', function() {
|
||||
@@ -1001,7 +1001,7 @@ define([
|
||||
'content-group-editor', 'content-group-details'
|
||||
], true);
|
||||
|
||||
this.model = new GroupModel({name: 'Content Group', id: 0});
|
||||
this.model = new GroupModel({name: 'Content Group', id: 0, courseOutlineUrl: 'CourseOutlineUrl'});
|
||||
|
||||
this.saveableModel = new GroupConfigurationModel({
|
||||
name: 'Content Group Configuration',
|
||||
|
||||
@@ -16,7 +16,8 @@ define([
|
||||
experimentsEnabled: true,
|
||||
experimentGroupConfigurations: new GroupConfigurationCollection({
|
||||
id: 0,
|
||||
name: 'Configuration 1'
|
||||
name: 'Configuration 1',
|
||||
courseOutlineUrl: "CourseOutlineUrl"
|
||||
}),
|
||||
contentGroupConfiguration: new GroupConfigurationModel({groups: []})
|
||||
});
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
* It is expected to be backed by a Group model.
|
||||
*/
|
||||
define([
|
||||
'js/views/baseview', 'underscore', 'gettext', 'underscore.string'
|
||||
], function(BaseView, _, gettext, str) {
|
||||
'js/views/baseview', 'underscore', 'gettext', 'underscore.string',
|
||||
'edx-ui-toolkit/js/utils/string-utils', 'edx-ui-toolkit/js/utils/html-utils'
|
||||
], function(BaseView, _, gettext, str, StringUtils, HtmlUtils) {
|
||||
'use strict';
|
||||
|
||||
var ContentGroupDetailsView = BaseView.extend({
|
||||
@@ -37,9 +38,10 @@ define([
|
||||
render: function(showContentGroupUsages) {
|
||||
var attrs = $.extend({}, this.model.attributes, {
|
||||
usageCountMessage: this.getUsageCountTitle(),
|
||||
outlineAnchorMessage: this.getOutlineAnchorMessage(),
|
||||
courseOutlineUrl: this.model.collection.parents[0].outlineUrl,
|
||||
index: this.model.collection.indexOf(this.model),
|
||||
showContentGroupUsages: showContentGroupUsages || false
|
||||
showContentGroupUsages: showContentGroupUsages || false,
|
||||
HtmlUtils: HtmlUtils
|
||||
});
|
||||
this.$el.html(this.template(attrs));
|
||||
return this;
|
||||
@@ -56,41 +58,23 @@ define([
|
||||
},
|
||||
|
||||
getUsageCountTitle: function () {
|
||||
var count = this.model.get('usage').length, message;
|
||||
var count = this.model.get('usage').length;
|
||||
|
||||
if (count === 0) {
|
||||
message = gettext('Not in Use');
|
||||
return gettext('Not in Use');
|
||||
} else {
|
||||
message = ngettext(
|
||||
/* globals ngettext */
|
||||
return StringUtils.interpolate(ngettext(
|
||||
/*
|
||||
Translators: 'count' is number of units that the group
|
||||
configuration is used in.
|
||||
*/
|
||||
'Used in %(count)s unit', 'Used in %(count)s units',
|
||||
'Used in {count} unit', 'Used in {count} units',
|
||||
count
|
||||
),
|
||||
{count: count}
|
||||
);
|
||||
}
|
||||
|
||||
return interpolate(message, { count: count }, true);
|
||||
},
|
||||
|
||||
getOutlineAnchorMessage: function () {
|
||||
var message = _.escape(gettext(
|
||||
/*
|
||||
Translators: 'outlineAnchor' is an anchor pointing to
|
||||
the course outline page.
|
||||
*/
|
||||
'This content group is not in use. Add a content group to any unit from the %(outlineAnchor)s.'
|
||||
)),
|
||||
anchor = str.sprintf(
|
||||
'<a href="%(url)s" title="%(text)s">%(text)s</a>',
|
||||
{
|
||||
url: this.model.collection.parents[0].outlineUrl,
|
||||
text: _.escape(gettext('Course Outline'))
|
||||
}
|
||||
);
|
||||
|
||||
return str.sprintf(message, {outlineAnchor: anchor});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ function(ListItemEditorView, _) {
|
||||
|
||||
getTemplateOptions: function() {
|
||||
return {
|
||||
id: this.model.escape('id'),
|
||||
name: this.model.escape('name'),
|
||||
id: this.model.get('id'),
|
||||
name: this.model.get('name'),
|
||||
index: this.model.collection.indexOf(this.model),
|
||||
isNew: this.model.isNew(),
|
||||
usage: this.model.get('usage'),
|
||||
|
||||
@@ -32,7 +32,7 @@ function(BaseView, _, str, gettext) {
|
||||
index = collection.indexOf(this.model);
|
||||
|
||||
this.$el.html(this.template({
|
||||
name: this.model.escape('name'),
|
||||
name: this.model.get('name'),
|
||||
allocation: this.getAllocation(),
|
||||
index: index,
|
||||
error: this.model.validationError
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
* It is expected to be instantiated with a GroupConfiguration model.
|
||||
*/
|
||||
define([
|
||||
'js/views/baseview', 'underscore', 'gettext', 'underscore.string'
|
||||
'js/views/baseview', 'underscore', 'gettext', 'underscore.string',
|
||||
'edx-ui-toolkit/js/utils/string-utils', 'edx-ui-toolkit/js/utils/html-utils'
|
||||
],
|
||||
function(BaseView, _, gettext, str) {
|
||||
function(BaseView, _, gettext, str, StringUtils, HtmlUtils) {
|
||||
'use strict';
|
||||
var GroupConfigurationDetailsView = BaseView.extend({
|
||||
tagName: 'div',
|
||||
@@ -26,7 +27,7 @@ function(BaseView, _, gettext, str) {
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.template = _.template(
|
||||
this.template = HtmlUtils.template(
|
||||
$('#group-configuration-details-tpl').text()
|
||||
);
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
@@ -36,11 +37,10 @@ function(BaseView, _, gettext, str) {
|
||||
var attrs = $.extend({}, this.model.attributes, {
|
||||
groupsCountMessage: this.getGroupsCountTitle(),
|
||||
usageCountMessage: this.getUsageCountTitle(),
|
||||
outlineAnchorMessage: this.getOutlineAnchorMessage(),
|
||||
courseOutlineUrl: this.model.collection.outlineUrl,
|
||||
index: this.model.collection.indexOf(this.model)
|
||||
});
|
||||
|
||||
this.$el.html(this.template(attrs));
|
||||
HtmlUtils.setHtml(this.$el, this.template(attrs));
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -61,54 +61,37 @@ function(BaseView, _, gettext, str) {
|
||||
|
||||
getGroupsCountTitle: function () {
|
||||
var count = this.model.get('groups').length,
|
||||
/* globals ngettext */
|
||||
message = ngettext(
|
||||
/*
|
||||
Translators: 'count' is number of groups that the group
|
||||
configuration contains.
|
||||
*/
|
||||
'Contains %(count)s group', 'Contains %(count)s groups',
|
||||
'Contains {count} group', 'Contains {count} groups',
|
||||
count
|
||||
);
|
||||
|
||||
return interpolate(message, { count: count }, true);
|
||||
return StringUtils.interpolate(message, { count: count });
|
||||
},
|
||||
|
||||
getUsageCountTitle: function () {
|
||||
var count = this.model.get('usage').length, message;
|
||||
var count = this.model.get('usage').length;
|
||||
|
||||
if (count === 0) {
|
||||
message = gettext('Not in Use');
|
||||
return gettext('Not in Use');
|
||||
} else {
|
||||
message = ngettext(
|
||||
return StringUtils.interpolate(ngettext(
|
||||
|
||||
/*
|
||||
Translators: 'count' is number of units that the group
|
||||
configuration is used in.
|
||||
*/
|
||||
'Used in %(count)s unit', 'Used in %(count)s units',
|
||||
'Used in {count} unit', 'Used in {count} units',
|
||||
count
|
||||
),
|
||||
{count: count}
|
||||
);
|
||||
}
|
||||
|
||||
return interpolate(message, { count: count }, true);
|
||||
},
|
||||
|
||||
getOutlineAnchorMessage: function () {
|
||||
var message = gettext(
|
||||
/*
|
||||
Translators: 'outlineAnchor' is an anchor pointing to
|
||||
the course outline page.
|
||||
*/
|
||||
'This Group Configuration is not in use. Start by adding a content experiment to any Unit via the %(outlineAnchor)s.'
|
||||
),
|
||||
anchor = str.sprintf(
|
||||
'<a href="%(url)s" title="%(text)s">%(text)s</a>',
|
||||
{
|
||||
url: this.model.collection.outlineUrl,
|
||||
text: gettext('Course Outline')
|
||||
}
|
||||
);
|
||||
|
||||
return str.sprintf(message, {outlineAnchor: anchor});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ function(ListItemEditorView, _, $, gettext, ExperimentGroupEditView) {
|
||||
return {
|
||||
id: this.model.get('id'),
|
||||
uniqueId: _.uniqueId(),
|
||||
name: this.model.escape('name'),
|
||||
description: this.model.escape('description'),
|
||||
name: this.model.get('name'),
|
||||
description: this.model.get('description'),
|
||||
usage: this.model.get('usage'),
|
||||
isNew: this.model.isNew()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user