* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * chore: apply amnesty on all existing issues * fix: failing xss-lint issues * refactor: apply amnesty on remaining issues * refactor: apply amnesty on new issues * fix: remove file level suppressions * refactor: apply amnesty on new issues
82 lines
2.7 KiB
JavaScript
82 lines
2.7 KiB
JavaScript
// eslint-disable-next-line no-shadow-restricted-names
|
|
(function(define, undefined) {
|
|
'use strict';
|
|
|
|
define([
|
|
'gettext', 'underscore', 'backbone', 'edx-ui-toolkit/js/utils/html-utils'
|
|
], function(gettext, _, Backbone, HtmlUtils) {
|
|
var GroupView, ChapterView;
|
|
|
|
GroupView = Backbone.View.extend({
|
|
tagName: 'section',
|
|
id: function() {
|
|
return 'note-section-' + _.uniqueId();
|
|
},
|
|
|
|
initialize: function(options) {
|
|
this.options = _.extend({}, options);
|
|
this.template = HtmlUtils.template(this.options.template);
|
|
this.className = this.options.className;
|
|
},
|
|
|
|
render: function() {
|
|
HtmlUtils.prepend(this.$el, this.template({
|
|
displayName: this.options.displayName
|
|
}));
|
|
|
|
return this;
|
|
},
|
|
|
|
addChild: function(child) {
|
|
this.$el.append(HtmlUtils.HTML(child).toString());
|
|
}
|
|
});
|
|
|
|
ChapterView = Backbone.View.extend({
|
|
tagName: 'section',
|
|
className: 'note-group',
|
|
id: function() {
|
|
return 'note-group-' + _.uniqueId();
|
|
},
|
|
template: HtmlUtils.template('<h3 class="course-title"><%- chapterName %></h3>'),
|
|
|
|
initialize: function(options) {
|
|
this.children = [];
|
|
this.options = _.extend({}, options);
|
|
},
|
|
|
|
render: function() {
|
|
var container = document.createDocumentFragment();
|
|
HtmlUtils.setHtml(this.$el, this.template({chapterName: this.options.chapter.display_name || ''}));
|
|
_.each(this.children, function(section) {
|
|
container.appendChild(section.render().el);
|
|
});
|
|
this.$el.append(HtmlUtils.HTML(container).toString());
|
|
|
|
return this;
|
|
},
|
|
|
|
addChild: function(sectionInfo) {
|
|
var section = new GroupView(
|
|
{
|
|
displayName: sectionInfo.display_name,
|
|
template: '<h4 class="course-subtitle"><%- displayName %></h4>',
|
|
className: 'note-section'
|
|
}
|
|
);
|
|
this.children.push(section);
|
|
return section;
|
|
},
|
|
|
|
remove: function() {
|
|
_.invoke(this.children, 'remove');
|
|
this.children = null;
|
|
Backbone.View.prototype.remove.call(this);
|
|
return this;
|
|
}
|
|
});
|
|
|
|
return {GroupView: GroupView, ChapterView: ChapterView};
|
|
});
|
|
}).call(this, define || RequireJS.define);
|