Commit 5836286f by David Baumgold

PDF textbooks: unified naming conventions

parent c45dbca7
../../../templates/js/chapter.underscore
\ No newline at end of file
../../../templates/js/edit-chapter.underscore
\ No newline at end of file
../../../templates/js/edit-textbook.underscore
\ No newline at end of file
../../../templates/js/show-textbook.underscore
\ No newline at end of file
../../../templates/js/textbook-edit.underscore
\ No newline at end of file
../../../templates/js/textbook-show.underscore
\ No newline at end of file
...@@ -10,9 +10,9 @@ beforeEach -> ...@@ -10,9 +10,9 @@ beforeEach ->
else else
return trimmedText.indexOf(text) != -1; return trimmedText.indexOf(text) != -1;
describe "CMS.Views.TextbookShow", -> describe "CMS.Views.ShowTextbook", ->
describe "Basic", -> describe "Basic", ->
tpl = readFixtures('textbook-show.underscore') tpl = readFixtures('show-textbook.underscore')
beforeEach -> beforeEach ->
setFixtures($("<script>", {id: "show-textbook-tpl", type: "text/template"}).text(tpl)) setFixtures($("<script>", {id: "show-textbook-tpl", type: "text/template"}).text(tpl))
...@@ -23,7 +23,7 @@ describe "CMS.Views.TextbookShow", -> ...@@ -23,7 +23,7 @@ describe "CMS.Views.TextbookShow", ->
@collection = new CMS.Collections.TextbookSet() @collection = new CMS.Collections.TextbookSet()
spyOn(@collection, 'save') spyOn(@collection, 'save')
@collection.add(@model) @collection.add(@model)
@view = new CMS.Views.TextbookShow({model: @model}) @view = new CMS.Views.ShowTextbook({model: @model})
it "should render properly", -> it "should render properly", ->
@view.render() @view.render()
...@@ -66,14 +66,14 @@ describe "CMS.Views.TextbookShow", -> ...@@ -66,14 +66,14 @@ describe "CMS.Views.TextbookShow", ->
describe "CMS.Views.TextbookEdit", -> describe "CMS.Views.EditTextbook", ->
describe "Basic", -> describe "Basic", ->
tpl = readFixtures('textbook-edit.underscore') tpl = readFixtures('edit-textbook.underscore')
chapterTpl = readFixtures('chapter.underscore') chapterTpl = readFixtures('edit-chapter.underscore')
beforeEach -> beforeEach ->
setFixtures($("<script>", {id: "new-textbook-tpl", type: "text/template"}).text(tpl)) setFixtures($("<script>", {id: "edit-textbook-tpl", type: "text/template"}).text(tpl))
appendSetFixtures($("<script>", {id: "new-chapter-tpl", type: "text/template"}).text(chapterTpl)) appendSetFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(chapterTpl))
appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl)) appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl))
appendSetFixtures(sandbox({id: "page-notification"})) appendSetFixtures(sandbox({id: "page-notification"}))
appendSetFixtures(sandbox({id: "page-prompt"})) appendSetFixtures(sandbox({id: "page-prompt"}))
...@@ -82,7 +82,7 @@ describe "CMS.Views.TextbookEdit", -> ...@@ -82,7 +82,7 @@ describe "CMS.Views.TextbookEdit", ->
spyOn(@collection, 'save') spyOn(@collection, 'save')
@collection.add(@model) @collection.add(@model)
@collection.editing = @model @collection.editing = @model
@view = new CMS.Views.TextbookEdit({model: @model}) @view = new CMS.Views.EditTextbook({model: @model})
spyOn(@view, 'render').andCallThrough() spyOn(@view, 'render').andCallThrough()
it "should render properly", -> it "should render properly", ->
...@@ -137,12 +137,12 @@ describe "CMS.Views.ListTextbooks", -> ...@@ -137,12 +137,12 @@ describe "CMS.Views.ListTextbooks", ->
beforeEach -> beforeEach ->
setFixtures($("<script>", {id: "no-textbooks-tpl", type: "text/template"}).text(noTextbooksTpl)) setFixtures($("<script>", {id: "no-textbooks-tpl", type: "text/template"}).text(noTextbooksTpl))
appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl)) appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl))
@showSpies = spyOnConstructor(CMS.Views, "TextbookShow", ["render"]) @showSpies = spyOnConstructor(CMS.Views, "ShowTextbook", ["render"])
@showSpies.render.andReturn(@showSpies) # equivalent of `return this` @showSpies.render.andReturn(@showSpies) # equivalent of `return this`
showEl = $("<li>") showEl = $("<li>")
@showSpies.$el = showEl @showSpies.$el = showEl
@showSpies.el = showEl.get(0) @showSpies.el = showEl.get(0)
@editSpies = spyOnConstructor(CMS.Views, "TextbookEdit", ["render"]) @editSpies = spyOnConstructor(CMS.Views, "EditTextbook", ["render"])
editEl = $("<li>") editEl = $("<li>")
@editSpies.render.andReturn(@editSpies) @editSpies.render.andReturn(@editSpies)
@editSpies.$el = editEl @editSpies.$el = editEl
...@@ -158,7 +158,7 @@ describe "CMS.Views.ListTextbooks", -> ...@@ -158,7 +158,7 @@ describe "CMS.Views.ListTextbooks", ->
expect(@showSpies.constructor).not.toHaveBeenCalled() expect(@showSpies.constructor).not.toHaveBeenCalled()
expect(@editSpies.constructor).not.toHaveBeenCalled() expect(@editSpies.constructor).not.toHaveBeenCalled()
it "should render TextbookShow views by default if no textbook is being edited", -> it "should render ShowTextbook views by default if no textbook is being edited", ->
# add three empty textbooks to the collection # add three empty textbooks to the collection
@collection.add([{}, {}, {}]) @collection.add([{}, {}, {}])
# reset spies due to re-rendering on collection modification # reset spies due to re-rendering on collection modification
...@@ -173,7 +173,7 @@ describe "CMS.Views.ListTextbooks", -> ...@@ -173,7 +173,7 @@ describe "CMS.Views.ListTextbooks", ->
expect(@showSpies.constructor.calls.length).toEqual(3); expect(@showSpies.constructor.calls.length).toEqual(3);
expect(@editSpies.constructor).not.toHaveBeenCalled() expect(@editSpies.constructor).not.toHaveBeenCalled()
it "should render a TextbookEdit view for a textbook being edited", -> it "should render an EditTextbook view for a textbook being edited", ->
# add three empty textbooks to the collection # add three empty textbooks to the collection
@collection.add([{}, {}, {}]) @collection.add([{}, {}, {}])
# mark the second one as being edited # mark the second one as being edited
...@@ -208,18 +208,18 @@ describe "CMS.Views.ListTextbooks", -> ...@@ -208,18 +208,18 @@ describe "CMS.Views.ListTextbooks", ->
expect(@view.$el).not.toContain(@showSpies.$el) expect(@view.$el).not.toContain(@showSpies.$el)
describe "CMS.Views.ChapterEdit", -> describe "CMS.Views.EditChapter", ->
tpl = readFixtures("chapter.underscore") tpl = readFixtures("edit-chapter.underscore")
beforeEach -> beforeEach ->
setFixtures($("<script>", {id: "new-chapter-tpl", type: "text/template"}).text(tpl)) setFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(tpl))
appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl)) appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl))
@model = new CMS.Models.Chapter @model = new CMS.Models.Chapter
name: "Chapter 1" name: "Chapter 1"
asset_path: "/ch1.pdf" asset_path: "/ch1.pdf"
@collection = new CMS.Collections.ChapterSet() @collection = new CMS.Collections.ChapterSet()
@collection.add(@model) @collection.add(@model)
@view = new CMS.Views.ChapterEdit({model: @model}) @view = new CMS.Views.EditChapter({model: @model})
spyOn(@view, "remove").andCallThrough() spyOn(@view, "remove").andCallThrough()
window.UPLOAD_ASSET_CALLBACK_URL = "/upload" window.UPLOAD_ASSET_CALLBACK_URL = "/upload"
window.section = new CMS.Models.Section({name: "abcde"}) window.section = new CMS.Models.Section({name: "abcde"})
......
...@@ -9,7 +9,7 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({ ...@@ -9,7 +9,7 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
relations: [{ relations: [{
type: Backbone.Many, type: Backbone.Many,
key: "chapters", key: "chapters",
relatedModel: "CMS.Models.Chapter", relatedModel: "CMS.Models.EditChapter",
collectionType: "CMS.Collections.ChapterSet" collectionType: "CMS.Collections.ChapterSet"
}], }],
isEmpty: function() { isEmpty: function() {
......
CMS.Views.TextbookShow = Backbone.View.extend({ CMS.Views.ShowTextbook = Backbone.View.extend({
initialize: function() { initialize: function() {
this.template = _.template($("#show-textbook-tpl").text()); this.template = _.template($("#show-textbook-tpl").text());
this.listenTo(this.model, "change", this.render); this.listenTo(this.model, "change", this.render);
...@@ -62,9 +62,9 @@ CMS.Views.TextbookShow = Backbone.View.extend({ ...@@ -62,9 +62,9 @@ CMS.Views.TextbookShow = Backbone.View.extend({
this.model.set('showChapters', false); this.model.set('showChapters', false);
} }
}); });
CMS.Views.TextbookEdit = Backbone.View.extend({ CMS.Views.EditTextbook = Backbone.View.extend({
initialize: function() { initialize: function() {
this.template = _.template($("#new-textbook-tpl").text()); this.template = _.template($("#edit-textbook-tpl").text());
var chapters = this.model.get('chapters'); var chapters = this.model.get('chapters');
this.listenTo(chapters, "add", this.addOne); this.listenTo(chapters, "add", this.addOne);
this.listenTo(chapters, "reset", this.addAll); this.listenTo(chapters, "reset", this.addAll);
...@@ -92,7 +92,7 @@ CMS.Views.TextbookEdit = Backbone.View.extend({ ...@@ -92,7 +92,7 @@ CMS.Views.TextbookEdit = Backbone.View.extend({
"click .action-add-chapter": "createChapter" "click .action-add-chapter": "createChapter"
}, },
addOne: function(chapter) { addOne: function(chapter) {
var view = new CMS.Views.ChapterEdit({model: chapter}); var view = new CMS.Views.EditChapter({model: chapter});
this.$("ol.chapters").append(view.render().el); this.$("ol.chapters").append(view.render().el);
return this; return this;
}, },
...@@ -177,9 +177,9 @@ CMS.Views.ListTextbooks = Backbone.View.extend({ ...@@ -177,9 +177,9 @@ CMS.Views.ListTextbooks = Backbone.View.extend({
textbooks.each(function(textbook) { textbooks.each(function(textbook) {
var view; var view;
if (textbook === textbooks.editing) { if (textbook === textbooks.editing) {
view = new CMS.Views.TextbookEdit({model: textbook}); view = new CMS.Views.EditTextbook({model: textbook});
} else { } else {
view = new CMS.Views.TextbookShow({model: textbook}); view = new CMS.Views.ShowTextbook({model: textbook});
} }
$el.append(view.render().el); $el.append(view.render().el);
}); });
...@@ -198,9 +198,9 @@ CMS.Views.ListTextbooks = Backbone.View.extend({ ...@@ -198,9 +198,9 @@ CMS.Views.ListTextbooks = Backbone.View.extend({
this.collection.trigger("editOne", m); this.collection.trigger("editOne", m);
} }
}); });
CMS.Views.ChapterEdit = Backbone.View.extend({ CMS.Views.EditChapter = Backbone.View.extend({
initialize: function() { initialize: function() {
this.template = _.template($("#new-chapter-tpl").text()); this.template = _.template($("#edit-chapter-tpl").text());
this.listenTo(this.model, "change", this.render); this.listenTo(this.model, "change", this.render);
}, },
tagName: "li", tagName: "li",
......
...@@ -7,21 +7,11 @@ ...@@ -7,21 +7,11 @@
<%block name="bodyclass">is-signedin course textbooks</%block> <%block name="bodyclass">is-signedin course textbooks</%block>
<%block name="header_extras"> <%block name="header_extras">
<script type="text/template" id="new-textbook-tpl"> % for template_name in ["edit-textbook", "show-textbook", "edit-chapter", "no-textbooks", "upload-dialog"]:
<%static:include path="js/textbook-edit.underscore" /> <script type="text/template" id="${template_name}-tpl">
</script> <%static:include path="js/${template_name}.underscore" />
<script type="text/template" id="show-textbook-tpl">
<%static:include path="js/textbook-show.underscore" />
</script>
<script type="text/template" id="new-chapter-tpl">
<%static:include path="js/chapter.underscore" />
</script>
<script type="text/template" id="no-textbooks-tpl">
<%static:include path="js/no-textbooks.underscore" />
</script>
<script type="text/template" id="upload-dialog-tpl">
<%static:include path="js/upload-dialog.underscore" />
</script> </script>
% endfor
</%block> </%block>
<%block name="jsextra"> <%block name="jsextra">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment