From 10a838cb0134574f05dd16103f2cc4aa1373b99a Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 19 Sep 2012 11:13:47 -0400 Subject: [PATCH 1/3] remove hardcoding of 6.002x in textbook page --- lms/templates/staticbook.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/templates/staticbook.html b/lms/templates/staticbook.html index c31cf0e7b1..6eec836c3a 100644 --- a/lms/templates/staticbook.html +++ b/lms/templates/staticbook.html @@ -1,6 +1,6 @@ <%inherit file="main.html" /> <%namespace name='static' file='static_content.html'/> -<%block name="title">Textbook – MITx 6.002x +<%block name="title">${course.number} Textbook <%block name="headextra"> <%static:css group='course'/> From f9a49ece6f98aaa0e71dcc2f760fd2ae803eb017 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 19 Sep 2012 17:12:08 -0400 Subject: [PATCH 2/3] Dynamically find the start and end pages of a textbook instead of hardcoding to 6.002 values --- common/lib/xmodule/xmodule/course_module.py | 10 +++++++++- lms/djangoapps/staticbook/views.py | 7 ++++++- lms/templates/staticbook.html | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 54e532cb24..71c0d761ef 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -21,7 +21,15 @@ class CourseDescriptor(SequenceDescriptor): self.title = title self.book_url = book_url self.table_of_contents = self._get_toc_from_s3() - + self.start_page = int(self.table_of_contents[0].attrib['page']) + + # The last page should be the last element in the table of contents, + # but it may be nested. So recurse all the way down the last element + last_el = self.table_of_contents[-1] + while last_el.getchildren(): + last_el = last_el[-1] + + self.end_page = int(last_el.attrib['page']) @property def table_of_contents(self): diff --git a/lms/djangoapps/staticbook/views.py b/lms/djangoapps/staticbook/views.py index 37087af597..fabb8b861c 100644 --- a/lms/djangoapps/staticbook/views.py +++ b/lms/djangoapps/staticbook/views.py @@ -7,7 +7,7 @@ from courseware.courses import get_course_with_access from lxml import etree @login_required -def index(request, course_id, book_index, page=0): +def index(request, course_id, book_index, page=None): course = get_course_with_access(request.user, course_id, 'load') staff_access = has_access(request.user, course, 'staff') @@ -15,10 +15,15 @@ def index(request, course_id, book_index, page=0): textbook = course.textbooks[book_index] table_of_contents = textbook.table_of_contents + if page is None: + page = textbook.start_page + return render_to_response('staticbook.html', {'book_index': book_index, 'page': int(page), 'course': course, 'book_url': textbook.book_url, 'table_of_contents': table_of_contents, + 'start_page' : textbook.start_page, + 'end_page' : textbook.end_page, 'staff_access': staff_access}) def index_shifted(request, course_id, page): diff --git a/lms/templates/staticbook.html b/lms/templates/staticbook.html index 6eec836c3a..ab92d22257 100644 --- a/lms/templates/staticbook.html +++ b/lms/templates/staticbook.html @@ -38,14 +38,14 @@ function goto_page(n) { function prev_page() { var newpage=page-1; - if(newpage<0) newpage=0; + if(newpage< ${start_page}) newpage=${start_page}; goto_page(newpage); log_event("book", {"type":"prevpage","new":page}); } function next_page() { var newpage=page+1; - if(newpage>1008) newpage=1008; + if(newpage> ${end_page}) newpage=${end_page}; goto_page(newpage); log_event("book", {"type":"nextpage","new":page}); } From 3cde783bdf6722b58428d6e3fbbb30540fc27cdb Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 19 Sep 2012 17:37:15 -0400 Subject: [PATCH 3/3] Display the last top level element in the Table of Contents as expandable. This isn't a great fix, but I'm confused what's going on. It's something in JQuery.TreeView. We write out the HTML correctly, but the lastExpandable style causes the list item to not be expandable. This didn't bite us in 6.002x because the last item was an appendix that isn't expandable anyway. It does affect 6.00x, where the last item is Chapter 5 at the moment. --- lms/templates/staticbook.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lms/templates/staticbook.html b/lms/templates/staticbook.html index ab92d22257..f99bfb6d92 100644 --- a/lms/templates/staticbook.html +++ b/lms/templates/staticbook.html @@ -97,6 +97,10 @@ $("#open_close_accordion a").click(function(){ % for entry in table_of_contents: ${print_entry(entry)} % endfor + + ## Don't delete this empty list item. Without it, Jquery.TreeView won't + ## render the last list item as expandable. +