From 19d65f81a45e0c0bf63d414d2def6249bbc9868e Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 11 Jun 2013 09:36:54 -0400 Subject: [PATCH] Toggle show/hide chapters in textbook show view --- cms/templates/js/textbook-show.underscore | 16 +++++++++++++++- cms/templates/textbooks.html | 13 ++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cms/templates/js/textbook-show.underscore b/cms/templates/js/textbook-show.underscore index 0afcdea4d3..260d8a51e7 100644 --- a/cms/templates/js/textbook-show.underscore +++ b/cms/templates/js/textbook-show.underscore @@ -1,11 +1,25 @@
  • <%= name %> <% if(chapters.length > 1) {%> - <%= chapters.length %> PDF Chapters + + + <%= chapters.length %> PDF Chapters + <% } else if(chapters.length === 1) { %> <%= chapters.at(0).get("asset_path") %> <% } %> <%= gettext("view in course") %> + <% if(showChapters) { %> +
    +
      + <% chapters.each(function(chapter) { %> +
    1. <%= chapter.get('name') %> + <%= chapter.get('asset_path') %> +
    2. + <% }) %> +
    + <% } %>
  • diff --git a/cms/templates/textbooks.html b/cms/templates/textbooks.html index 8f02e0ddf4..273d399566 100644 --- a/cms/templates/textbooks.html +++ b/cms/templates/textbooks.html @@ -29,6 +29,7 @@ window.UPLOAD_ASSET_CALLBACK_URL = "${upload_asset_callback_url}" CMS.Models.Textbook = Backbone.Model.extend({ defaults: { name: "", + showChapters: false }, initialize: function() { this.chapters = new CMS.Collections.ChapterSet; @@ -45,7 +46,9 @@ CMS.Views.TextbookShow = Backbone.View.extend({ }, events: { "click .edit": "editTextbook", - "click .delete": "removeSelf" + "click .delete": "removeSelf", + "click .show-chapters": "showChapters", + "click .hide-chapters": "hideChapters" }, render: function() { var attrs = $.extend({}, this.model.attributes); @@ -60,6 +63,14 @@ CMS.Views.TextbookShow = Backbone.View.extend({ removeSelf: function(e) { if(e && e.preventDefault) { e.preventDefault(); } 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({