Perform esacaping in the templates.
Use new best practices.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
;(function (define) {
|
||||
'use strict';
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions'],
|
||||
function ($, _, Backbone, gettext, CohortDiscussionConfigurationView) {
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions',
|
||||
'edx-ui-toolkit/js/utils/html-utils'],
|
||||
function ($, _, Backbone, gettext, CohortDiscussionConfigurationView, HtmlUtils) {
|
||||
var CourseWideDiscussionsView = CohortDiscussionConfigurationView.extend({
|
||||
events: {
|
||||
'change .check-discussion-subcategory-course-wide': 'discussionCategoryStateChanged',
|
||||
@@ -9,13 +10,13 @@
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
this.template = _.template($('#cohort-discussions-course-wide-tpl').text());
|
||||
this.template = HtmlUtils.template($('#cohort-discussions-course-wide-tpl').text());
|
||||
this.cohortSettings = options.cohortSettings;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
this.$('.cohort-course-wide-discussions-nav').html(this.template({
|
||||
courseWideTopics: this.getCourseWideDiscussionsHtml(
|
||||
HtmlUtils.setHtml(this.$('.cohort-course-wide-discussions-nav'), this.template({
|
||||
courseWideTopicsHtml: this.getCourseWideDiscussionsHtml(
|
||||
this.model.get('course_wide_discussions')
|
||||
)
|
||||
}));
|
||||
@@ -25,14 +26,14 @@
|
||||
/**
|
||||
* Returns the html list for course-wide discussion topics.
|
||||
* @param {object} courseWideDiscussions - course-wide discussions object from server.
|
||||
* @returns {Array} - HTML list for course-wide discussion topics.
|
||||
* @returns {HtmlSnippet} - HTML list for course-wide discussion topics.
|
||||
*/
|
||||
getCourseWideDiscussionsHtml: function (courseWideDiscussions) {
|
||||
var subCategoryTemplate = _.template($('#cohort-discussions-subcategory-tpl').html()),
|
||||
var subCategoryTemplate = HtmlUtils.template($('#cohort-discussions-subcategory-tpl').html()),
|
||||
entries = courseWideDiscussions.entries,
|
||||
children = courseWideDiscussions.children;
|
||||
|
||||
return _.map(children, function (name) {
|
||||
return HtmlUtils.joinHtml.apply(this, _.map(children, function (name) {
|
||||
var entry = entries[name];
|
||||
return subCategoryTemplate({
|
||||
name: name,
|
||||
@@ -40,7 +41,7 @@
|
||||
is_cohorted: entry.is_cohorted,
|
||||
type: 'course-wide'
|
||||
});
|
||||
}).join('');
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
;(function (define) {
|
||||
'use strict';
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions', 'js/vendor/jquery.qubit'],
|
||||
function ($, _, Backbone, gettext, CohortDiscussionConfigurationView) {
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/views/cohort_discussions',
|
||||
'edx-ui-toolkit/js/utils/html-utils', 'js/vendor/jquery.qubit'],
|
||||
function ($, _, Backbone, gettext, CohortDiscussionConfigurationView, HtmlUtils) {
|
||||
var InlineDiscussionsView = CohortDiscussionConfigurationView.extend({
|
||||
events: {
|
||||
'change .check-discussion-category': 'setSaveButton',
|
||||
@@ -12,15 +13,16 @@
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
this.template = _.template($('#cohort-discussions-inline-tpl').text());
|
||||
this.template = HtmlUtils.template($('#cohort-discussions-inline-tpl').text());
|
||||
this.cohortSettings = options.cohortSettings;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var alwaysCohortInlineDiscussions = this.cohortSettings.get('always_cohort_inline_discussions');
|
||||
var alwaysCohortInlineDiscussions = this.cohortSettings.get('always_cohort_inline_discussions'),
|
||||
inline_discussions = this.model.get('inline_discussions');
|
||||
|
||||
this.$('.cohort-inline-discussions-nav').html(this.template({
|
||||
inlineDiscussionTopics: this.getInlineDiscussionsHtml(this.model.get('inline_discussions')),
|
||||
HtmlUtils.setHtml(this.$('.cohort-inline-discussions-nav'), this.template({
|
||||
inlineDiscussionTopicsHtml: this.getInlineDiscussionsHtml(inline_discussions),
|
||||
alwaysCohortInlineDiscussions:alwaysCohortInlineDiscussions
|
||||
}));
|
||||
|
||||
@@ -36,35 +38,35 @@
|
||||
/**
|
||||
* Generate html list for inline discussion topics.
|
||||
* @params {object} inlineDiscussions - inline discussions object from server.
|
||||
* @returns {Array} - HTML for inline discussion topics.
|
||||
* @returns {HtmlSnippet} - HTML for inline discussion topics.
|
||||
*/
|
||||
getInlineDiscussionsHtml: function (inlineDiscussions) {
|
||||
var categoryTemplate = _.template($('#cohort-discussions-category-tpl').html()),
|
||||
entryTemplate = _.template($('#cohort-discussions-subcategory-tpl').html()),
|
||||
var categoryTemplate = HtmlUtils.template($('#cohort-discussions-category-tpl').html()),
|
||||
entryTemplate = HtmlUtils.template($('#cohort-discussions-subcategory-tpl').html()),
|
||||
isCategoryCohorted = false,
|
||||
children = inlineDiscussions.children,
|
||||
entries = inlineDiscussions.entries,
|
||||
subcategories = inlineDiscussions.subcategories;
|
||||
|
||||
return _.map(children, function (name) {
|
||||
var html = '', entry;
|
||||
return HtmlUtils.joinHtml.apply(this, _.map(children, function (name) {
|
||||
var htmlSnippet = '', entry;
|
||||
if (entries && _.has(entries, name)) {
|
||||
entry = entries[name];
|
||||
html = entryTemplate({
|
||||
htmlSnippet = entryTemplate({
|
||||
name: name,
|
||||
id: entry.id,
|
||||
is_cohorted: entry.is_cohorted,
|
||||
type: 'inline'
|
||||
});
|
||||
} else { // subcategory
|
||||
html = categoryTemplate({
|
||||
htmlSnippet = categoryTemplate({
|
||||
name: name,
|
||||
entries: this.getInlineDiscussionsHtml(subcategories[name]),
|
||||
entriesHtml: this.getInlineDiscussionsHtml(subcategories[name]),
|
||||
isCategoryCohorted: isCategoryCohorted
|
||||
});
|
||||
}
|
||||
return html;
|
||||
}, this).join('');
|
||||
return htmlSnippet;
|
||||
}, this));
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
;(function (define) {
|
||||
'use strict';
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'js/groups/models/cohort',
|
||||
define(['jquery', 'underscore', 'backbone', 'gettext', 'edx-ui-toolkit/js/utils/html-utils',
|
||||
'js/models/notification', 'js/views/notification'],
|
||||
function($, _, Backbone, gettext, CohortModel) {
|
||||
function($, _, Backbone, gettext, HtmlUtils) {
|
||||
|
||||
var CohortFormView = Backbone.View.extend({
|
||||
events : {
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
this.template = _.template($('#cohort-form-tpl').text());
|
||||
this.template = HtmlUtils.template($('#cohort-form-tpl').text());
|
||||
this.contentGroups = options.contentGroups;
|
||||
this.context = options.context;
|
||||
},
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template({
|
||||
HtmlUtils.setHtml(this.$el, this.template({
|
||||
cohort: this.model,
|
||||
isDefaultCohort: this.isDefault(this.model.get('name')),
|
||||
contentGroups: this.contentGroups,
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
'js/groups/views/cohort_editor', 'js/groups/views/cohort_form',
|
||||
'js/groups/views/course_cohort_settings_notification',
|
||||
'js/groups/views/cohort_discussions_inline', 'js/groups/views/cohort_discussions_course_wide',
|
||||
'edx-ui-toolkit/js/utils/html-utils',
|
||||
'js/views/file_uploader', 'js/models/notification', 'js/views/notification', 'string_utils'],
|
||||
function($, _, Backbone, gettext, CohortModel, CohortEditorView, CohortFormView,
|
||||
CourseCohortSettingsNotificationView, InlineDiscussionsView, CourseWideDiscussionsView) {
|
||||
CourseCohortSettingsNotificationView, InlineDiscussionsView, CourseWideDiscussionsView, HtmlUtils) {
|
||||
|
||||
var hiddenClass = 'is-hidden',
|
||||
disabledClass = 'is-disabled';
|
||||
@@ -27,8 +28,8 @@
|
||||
initialize: function(options) {
|
||||
var model = this.model;
|
||||
|
||||
this.template = _.template($('#cohorts-tpl').text());
|
||||
this.selectorTemplate = _.template($('#cohort-selector-tpl').text());
|
||||
this.template = HtmlUtils.template($('#cohorts-tpl').text());
|
||||
this.selectorTemplate = HtmlUtils.template($('#cohort-selector-tpl').text());
|
||||
this.context = options.context;
|
||||
this.contentGroups = options.contentGroups;
|
||||
this.cohortSettings = options.cohortSettings;
|
||||
@@ -43,7 +44,7 @@
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template({
|
||||
HtmlUtils.setHtml(this.$el, this.template({
|
||||
cohorts: this.model.models,
|
||||
cohortsEnabled: this.cohortSettings.get('is_cohorted')
|
||||
}));
|
||||
@@ -52,7 +53,7 @@
|
||||
},
|
||||
|
||||
renderSelector: function(selectedCohort) {
|
||||
this.$('.cohort-select').html(this.selectorTemplate({
|
||||
HtmlUtils.setHtml(this.$('.cohort-select'), this.selectorTemplate({
|
||||
cohorts: this.model.models,
|
||||
selectedCohort: selectedCohort
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user