Commit 19d65f81 by David Baumgold

Toggle show/hide chapters in textbook show view

parent 22e325af
<li class="textbook"> <li class="textbook">
<span class="name"><%= name %></span> <span class="name"><%= name %></span>
<% if(chapters.length > 1) {%> <% if(chapters.length > 1) {%>
<%= chapters.length %> PDF Chapters <a href="#" class="chapter-toggle
<% if(showChapters){ print('hide'); } else { print('show'); } %>-chapters">
<i class="icon-chevron-<% if(showChapters){ print('down'); } else { print('right'); } %>"></i>
<%= chapters.length %> PDF Chapters
</a>
<% } else if(chapters.length === 1) { %> <% } else if(chapters.length === 1) { %>
<%= chapters.at(0).get("asset_path") %> <%= chapters.at(0).get("asset_path") %>
<% } %> <% } %>
<a href="#" class="view"><%= gettext("view in course") %></a> <a href="#" class="view"><%= gettext("view in course") %></a>
<button class="edit"><%= gettext("Edit") %></button> <button class="edit"><%= gettext("Edit") %></button>
<button class="delete"><%= gettext("Delete") %></button> <button class="delete"><%= gettext("Delete") %></button>
<% if(showChapters) { %>
<hr>
<ol class="chapters">
<% chapters.each(function(chapter) { %>
<li><span class="chapter-name"><%= chapter.get('name') %></span>
<span class="chapter-asset-path"><%= chapter.get('asset_path') %></span>
</li>
<% }) %>
</ol>
<% } %>
</li> </li>
...@@ -29,6 +29,7 @@ window.UPLOAD_ASSET_CALLBACK_URL = "${upload_asset_callback_url}" ...@@ -29,6 +29,7 @@ window.UPLOAD_ASSET_CALLBACK_URL = "${upload_asset_callback_url}"
CMS.Models.Textbook = Backbone.Model.extend({ CMS.Models.Textbook = Backbone.Model.extend({
defaults: { defaults: {
name: "", name: "",
showChapters: false
}, },
initialize: function() { initialize: function() {
this.chapters = new CMS.Collections.ChapterSet; this.chapters = new CMS.Collections.ChapterSet;
...@@ -45,7 +46,9 @@ CMS.Views.TextbookShow = Backbone.View.extend({ ...@@ -45,7 +46,9 @@ CMS.Views.TextbookShow = Backbone.View.extend({
}, },
events: { events: {
"click .edit": "editTextbook", "click .edit": "editTextbook",
"click .delete": "removeSelf" "click .delete": "removeSelf",
"click .show-chapters": "showChapters",
"click .hide-chapters": "hideChapters"
}, },
render: function() { render: function() {
var attrs = $.extend({}, this.model.attributes); var attrs = $.extend({}, this.model.attributes);
...@@ -60,6 +63,14 @@ CMS.Views.TextbookShow = Backbone.View.extend({ ...@@ -60,6 +63,14 @@ CMS.Views.TextbookShow = Backbone.View.extend({
removeSelf: function(e) { removeSelf: function(e) {
if(e && e.preventDefault) { e.preventDefault(); } if(e && e.preventDefault) { e.preventDefault(); }
this.model.collection.remove(this.model); this.model.collection.remove(this.model);
},
showChapters: function(e) {
if(e && e.preventDefault) { e.preventDefault(); }
this.model.set('showChapters', true);
},
hideChapters: function(e) {
if(e && e.preventDefault) { e.preventDefault(); }
this.model.set('showChapters', false);
} }
}) })
CMS.Views.TextbookEdit = Backbone.View.extend({ CMS.Views.TextbookEdit = Backbone.View.extend({
......
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