Commit 71209989 by Arthur Barrett

refactoring notes js

parent 76e338d8
......@@ -326,7 +326,7 @@ def get_default_tabs(user, course, active_page):
tabs.extend(_wiki({'name': 'Wiki', 'type': 'wiki'}, user, course, active_page))
tabs.extend(_student_notes({'name': 'My Notes', 'type': 'notes'}, user, course, active_page))
tabs.extend(_student_notes({'name': 'Notes', 'type': 'notes'}, user, course, active_page))
if user.is_authenticated() and not course.hide_progress_tab:
tabs.extend(_progress({'name': 'Progress'}, user, course, active_page))
......
......@@ -6,20 +6,19 @@ import logging
log = logging.getLogger(__name__)
#----------------------------------------------------------------------#
# HTML views.
#
# Example for enabling annotator.js (snippet):
#
# $('body').annotator()
# .annotator('addPlugin', 'Tags')
# .annotator('addPlugin', 'Store', { 'prefix': '/courses/HarvardX/CB22x/2013_Spring/notes/api' });
#
# See annotator.js docs:
#
# https://github.com/okfn/annotator/wiki
def notes(request, course_id):
''' Displays a student's notes in a course.
$('body').annotator()
.annotator('addPlugin', 'Tags')
.annotator('addPlugin', 'Store', {
'prefix': /^(\/courses\/[^/]+\/[^/]+\/[^/]+)/.exec(window.location.href.toString().split(window.location.host)[1]
'annotationData': {
'uri': window.location.href.toString().split(window.location.host)[1]
}
});
'''
course = get_course_with_access(request.user, course_id, 'load')
notes = Note.objects.filter(user_id=request.user.id)
......
......@@ -2,6 +2,7 @@ from lxml import etree
from django.contrib.auth.decorators import login_required
from django.http import Http404
from django.core.urlresolvers import reverse
from mitxmako.shortcuts import render_to_response
from courseware.access import has_access
......@@ -25,7 +26,9 @@ def index(request, course_id, book_index, page=None):
return render_to_response('staticbook.html',
{'book_index': book_index, 'page': int(page),
'course': course, 'book_url': textbook.book_url,
'course': course,
'book_url': textbook.book_url,
'notes_api_url': reverse('notes_api_root', {'course_id': course_id}),
'table_of_contents': table_of_contents,
'start_page': textbook.start_page,
'end_page': textbook.end_page,
......@@ -99,10 +102,10 @@ def html_index(request, course_id, book_index, chapter=None, anchor_id=None):
for entry in textbook['chapters']:
entry['url'] = remap_static_url(entry['url'], course)
return render_to_response('static_htmlbook.html',
{'book_index': book_index,
'course': course,
'notes_api_url': reverse('notes_api_root', kwargs={'course_id': course_id}),
'textbook': textbook,
'chapter': chapter,
'anchor_id': anchor_id,
......
......@@ -427,6 +427,7 @@ main_vendor_js = [
discussion_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/discussion/**/*.coffee'))
staff_grading_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/staff_grading/**/*.coffee'))
open_ended_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/open_ended/**/*.coffee'))
notes_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/notes/**/*.coffee'))
PIPELINE_CSS = {
'application': {
......@@ -458,7 +459,7 @@ PIPELINE_JS = {
'source_filenames': sorted(
set(rooted_glob(COMMON_ROOT / 'static', 'coffee/src/**/*.coffee') +
rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/**/*.coffee')) -
set(courseware_js + discussion_js + staff_grading_js + open_ended_js)
set(courseware_js + discussion_js + staff_grading_js + open_ended_js + notes_js)
) + [
'js/form.ext.js',
'js/my_courses_dropdown.js',
......@@ -491,7 +492,11 @@ PIPELINE_JS = {
'open_ended': {
'source_filenames': open_ended_js,
'output_filename': 'js/open_ended.js'
}
},
'notes': {
'source_filenames': notes_js,
'output_filename': 'js/notes.js'
},
}
PIPELINE_DISABLE_WRAPPER = True
......
class @StudentNotes
targets: []
storeConfig:
prefix: ''
annotationData:
uri: ''
constructor: () ->
@storeConfig =
prefix: @getPrefix()
annotationData:
uri: @getURIPath()
$(document).ready(@init)
init: ($) =>
if not StudentNotes.ready
$(document).delegate('*', {
'notes:init': @onInitNotes,
'notes:load': @onLoadNotes
})
StudentNotes.ready = true
onInitNotes: (event, annotationData=null) =>
found = (target for target in @targets when target is event.target)
storeConfig = $.extend {}, @storeConfig
$.extend(storeConfig.annotationData, annotationData) if annotationData
if found.length is 0
$(event.target).annotator()
.annotator('addPlugin', 'Tags')
.annotator('addPlugin', 'Store', storeConfig)
@targets.push(event.target)
onLoadNotes: (event) =>
if event.target in @targets
$(event.target).annotator().annotator('loadAnnotations')
getPrefix: () ->
re = /^(\/courses\/[^/]+\/[^/]+\/[^/]+)/
match = re.exec(@getURIPath())
prefix = (if match then match[1] else '')
return "#{prefix}/notes/api"
getURIPath: () ->
window.location.href.toString().split(window.location.host)[1]
......@@ -31,13 +31,20 @@
anchorToLoad = options.anchor_id;
}
var onComplete = function(url) {
return function() {
annotationData = { 'uri': url }
$(this).trigger('notes:init', [annotationData]);
}
};
loadUrl = function htmlViewLoadUrl(url, anchorId) {
// clear out previous load, if any:
parentElement = document.getElementById('bookpage');
while (parentElement.hasChildNodes())
parentElement.removeChild(parentElement.lastChild);
// load new URL in:
$('#bookpage').load(url);
$('#bookpage').load(url, null, onComplete(url));
// if there is an anchor set, then go to that location:
if (anchorId != null) {
......
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