Commit 3970ea33 by Arthur Barrett

return from capa problem

parent 0e2c46a7
<form class="annotation-input"> <form class="annotation-input">
<div class="script_placeholder" data-src="/static/js/capa/annotationinput.js"/> <div class="script_placeholder" data-src="/static/js/capa/annotationinput.js"/>
<div class="header">${title}</div> <div class="annotation-header">${title}</div>
<div class="body"> <div class="annotation-body">
<div class="prompt prompt-text">${text}</div> <div class="prompt prompt-text">${text}</div>
<div class="prompt">${comment_prompt}</div> <div class="prompt">${comment_prompt}</div>
<textarea id="input_${id}_comment" name="input_${id}_comment"/> <textarea id="input_${id}_comment" name="input_${id}_comment"/>
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
<span class="incorrect" id="status_${id}"></span> <span class="incorrect" id="status_${id}"></span>
% endif % endif
</div> </div>
<a class="annotation-return" href="javascript:void(0)">Return to Annotation</a><br/>
</div> </div>
</form> </form>
......
...@@ -69,8 +69,6 @@ class AnnotatableModule(XModule): ...@@ -69,8 +69,6 @@ class AnnotatableModule(XModule):
html_key = attrs_map[xml_key] html_key = attrs_map[xml_key]
data_attrs[html_key] = { 'value': value, '_delete': xml_key } data_attrs[html_key] = { 'value': value, '_delete': xml_key }
data_attrs['data-span-id'] = { 'value': str(index) }
return data_attrs return data_attrs
def _render_content(self): def _render_content(self):
......
...@@ -809,12 +809,14 @@ section.problem { ...@@ -809,12 +809,14 @@ section.problem {
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 1em; border-radius: 1em;
margin: 0 0 1em 0; margin: 0 0 1em 0;
.header { .annotation-header {
font-weight: bold; font-weight: bold;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding: .5em 1em; padding: .5em 1em;
} }
.body { padding: .5em 1em; } .annotation-body { padding: .5em 1em; }
.annotation-return { float: right; }
.annotation-return:after { content: " \2191" }
.prompt { font-style: italic; } .prompt { font-style: italic; }
.prompt.prompt-text { .prompt.prompt-text {
padding: .5em; padding: .5em;
......
...@@ -6,8 +6,10 @@ class @Annotatable ...@@ -6,8 +6,10 @@ class @Annotatable
spanSelector: '.annotatable-span' spanSelector: '.annotatable-span'
replySelector: '.annotatable-reply' replySelector: '.annotatable-reply'
helpSelector: '.annotatable-help-icon' helpSelector: '.annotatable-help-icon'
returnSelector: '.annotatable-return'
problemXModuleSelector: '.xmodule_CapaModule'
problemSelector: 'section.problem' problemSelector: 'section.problem'
problemReturnSelector: 'section.problem .annotation-return'
discussionXModuleSelector: '.xmodule_DiscussionModule' discussionXModuleSelector: '.xmodule_DiscussionModule'
discussionSelector: '.discussion-module' discussionSelector: '.discussion-module'
...@@ -26,24 +28,38 @@ class @Annotatable ...@@ -26,24 +28,38 @@ class @Annotatable
@initDiscussion() @initDiscussion()
initEvents: () -> initEvents: () ->
# For handling hide/show of annotations
@annotationsHidden = false @annotationsHidden = false
@$(@toggleSelector).bind 'click', @onClickToggleAnnotations @$(@toggleSelector).bind 'click', @onClickToggleAnnotations
# For handling 'reply to annotation' events that scroll to the associated capa problem.
# These are contained in the tooltips, which should be rendered somewhere in the wrapper
# (see the qtip2 options, this must be set explicitly, otherwise they render in the body).
@$(@wrapperSelector).delegate @replySelector, 'click', @onClickReply @$(@wrapperSelector).delegate @replySelector, 'click', @onClickReply
$(@discussionXModuleSelector).delegate @returnSelector, 'click', @onClickReturn
initDiscussion: () -> # This is a silly hack, but it assumes two things:
1 # 1) There are annotationinput capa problems rendered on the page
# 2) Each one has its an embedded "return to annotation" link.
# The capa problem's html is injected via AJAX so this just sets a listener on the body and
# handles the click event there.
$('body').delegate @problemReturnSelector, 'click', @onClickReturn
initDiscussion: () -> 1
initTips: () -> initTips: () ->
@savedTips = [] @savedTips = []
@$(@spanSelector).each (index, el) => $(el).qtip(@getTipOptions el)
# Adds a tooltip to each annotation span to display the instructor prompt
@$(@spanSelector).each (index, el) =>
$(el).qtip(@getTipOptions el)
@$(@helpSelector).qtip @$(@helpSelector).qtip
position: position:
my: 'right top' my: 'right top'
at: 'bottom left' at: 'bottom left'
container: @$(@wrapperSelector) container: @$(@wrapperSelector)
content: content:
title: 'Annotated Reading' title: 'Instructions'
text: true # use title attribute of this element text: true # use title attribute of this element
getTipOptions: (el) -> getTipOptions: (el) ->
...@@ -79,32 +95,32 @@ class @Annotatable ...@@ -79,32 +95,32 @@ class @Annotatable
e.preventDefault() e.preventDefault()
offset = -20 offset = -20
el = @getProblem e.currentTarget el = @getProblem e.currentTarget
@scrollTo(el, @afterScrollToProblem, offset) if el.length > 0
@scrollTo(el, @afterScrollToProblem, offset)
else
console.log('problem not found. event: ', e) if @_debug
onClickReturn: (e) => onClickReturn: (e) =>
e.preventDefault() e.preventDefault()
offset = -200 offset = -200
el = @getSpan e.currentTarget el = @getSpanForProblemReturn e.currentTarget
@scrollTo(el, @afterScrollToSpan, offset) if el.length > 0
@scrollTo(el, @afterScrollToSpan, offset)
else
console.log('span not found. event:', e) if @_debug
getSpan: (el) -> getSpanForProblemReturn: (el) ->
span_id = @getSpanId(el) problem_id = $(@problemReturnSelector).index(el)
@$(@spanSelector).filter("[data-span-id='#{span_id}']") @$(@spanSelector).filter("[data-problem-id='#{problem_id}']")
getProblem: (el) -> getProblem: (el) ->
problem_id = parseInt(@getProblemId(el), 10) problem_id = @getProblemId(el)
if isNaN(problem_id) $(@problemSelector).eq(problem_id)
console.log 'invalid problem identifier' if @_debug
return $()
return $(@problemSelector).eq(problem_id - 1)
getDiscussion: () -> getDiscussion: () ->
discussion_id = @getDiscussionId() discussion_id = @getDiscussionId()
$(@discussionXModuleSelector).find(@discussionSelector).filter("[data-discussion-id='#{discussion_id}']") $(@discussionXModuleSelector).find(@discussionSelector).filter("[data-discussion-id='#{discussion_id}']")
getSpanId: (el) ->
$(el).data('span-id')
getProblemId: (el) -> getProblemId: (el) ->
$(el).data('problem-id') $(el).data('problem-id')
...@@ -136,7 +152,7 @@ class @Annotatable ...@@ -136,7 +152,7 @@ class @Annotatable
duration: 500 duration: 500
onAfter: @_once => after?.call this, el onAfter: @_once => after?.call this, el
offset: offset offset: offset
}) if el }) if $(el).length > 0
afterScrollToDiscussion: (discussion_el) -> afterScrollToDiscussion: (discussion_el) ->
btn = $('.discussion-show', discussion_el) btn = $('.discussion-show', discussion_el)
...@@ -151,7 +167,7 @@ class @Annotatable ...@@ -151,7 +167,7 @@ class @Annotatable
makeTipContent: (el) -> makeTipContent: (el) ->
(api) => (api) =>
text = $(el).data('comment-body') text = $(el).data('comment-body')
comment = @createCommentEl(text) comment = @createComment(text)
problem_id = @getProblemId(el) problem_id = @getProblemId(el)
reply = @createReplyLink(problem_id) reply = @createReplyLink(problem_id)
$(comment).add(reply) $(comment).add(reply)
...@@ -161,15 +177,12 @@ class @Annotatable ...@@ -161,15 +177,12 @@ class @Annotatable
title = $(el).data('comment-title') title = $(el).data('comment-title')
(if title then title else 'Commentary') (if title then title else 'Commentary')
createCommentEl: (text) -> createComment: (text) ->
$("<div class=\"annotatable-comment\">#{text}</div>") $("<div class=\"annotatable-comment\">#{text}</div>")
createReplyLink: (problem_id) -> createReplyLink: (problem_id) ->
$("<a class=\"annotatable-reply\" href=\"javascript:void(0);\" data-problem-id=\"#{problem_id}\">Reply to Annotation</a>") $("<a class=\"annotatable-reply\" href=\"javascript:void(0);\" data-problem-id=\"#{problem_id}\">Reply to Annotation</a>")
createReturnLink: (span_id) ->
$("<a class=\"annotatable-return\" href=\"javascript:void(0);\" data-span-id=\"#{span_id}\">Return to annotation</a>")
openSavedTips: () -> openSavedTips: () ->
@showTips @savedTips @showTips @savedTips
......
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