Commit 0e2c46a7 by Arthur Barrett

Clicking "reply to annotation" scrolls to the problem (specified in xml by problem=index).

parent a8178de4
...@@ -13,9 +13,8 @@ ...@@ -13,9 +13,8 @@
% endfor % endfor
</ul> </ul>
<!-- <div style="display:none">
Value: ${value} <input type="text" name="input_${id}" id="input_${id}"/>
Value: ${value} <input type="text" style="" name="input_${id}" id="input_${id}"/>
TODO: make the textline hidden once it all works TODO: make the textline hidden once it all works
<span id="answer_${id}"></span> <span id="answer_${id}"></span>
...@@ -28,8 +27,7 @@ ...@@ -28,8 +27,7 @@
% elif status == 'incomplete': % elif status == 'incomplete':
<span class="incorrect" id="status_${id}"></span> <span class="incorrect" id="status_${id}"></span>
% endif % endif
</div>
-->
</div> </div>
</form> </form>
......
...@@ -50,16 +50,17 @@ class AnnotatableModule(XModule): ...@@ -50,16 +50,17 @@ class AnnotatableModule(XModule):
} }
def _get_annotation_data_attr(self, index, el): def _get_annotation_data_attr(self, index, el):
""" Returns a dict with the HTML data attributes to set on the annotation """ Returns a dict in which the keys are the HTML data attributes
and an XML key to delete from the element to set on the annotation element. Each data attribute has a
corresponding 'value' and (optional) '_delete' key to specify
an XML attribute to delete.
""" """
data_attrs = {}
attrs_map = { attrs_map = {
'body': 'data-comment-body', 'body': 'data-comment-body',
'title': 'data-comment-title' 'title': 'data-comment-title',
} 'problem': 'data-problem-id'
data_attrs = {
'data-span-id': { 'value': str(index) }
} }
for xml_key in attrs_map.keys(): for xml_key in attrs_map.keys():
...@@ -68,6 +69,8 @@ class AnnotatableModule(XModule): ...@@ -68,6 +69,8 @@ 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):
...@@ -78,9 +81,7 @@ class AnnotatableModule(XModule): ...@@ -78,9 +81,7 @@ class AnnotatableModule(XModule):
index = 0 index = 0
for el in xmltree.findall('.//annotation'): for el in xmltree.findall('.//annotation'):
index += 1 el.tag = 'span'
el.tag = 'div'
attr = {} attr = {}
attr.update(self._get_annotation_class_attr(index, el)) attr.update(self._get_annotation_class_attr(index, el))
...@@ -90,6 +91,7 @@ class AnnotatableModule(XModule): ...@@ -90,6 +91,7 @@ class AnnotatableModule(XModule):
if '_delete' in attr[key]: if '_delete' in attr[key]:
delete_key = attr[key]['_delete'] delete_key = attr[key]['_delete']
del el.attrib[delete_key] del el.attrib[delete_key]
index += 1
return etree.tostring(xmltree, encoding='unicode') return etree.tostring(xmltree, encoding='unicode')
......
class @Annotatable class @Annotatable
@_debug: true _debug: true
wrapperSelector: '.annotatable-wrapper' wrapperSelector: '.annotatable-wrapper'
toggleSelector: '.annotatable-toggle' toggleSelector: '.annotatable-toggle'
...@@ -7,6 +7,7 @@ class @Annotatable ...@@ -7,6 +7,7 @@ class @Annotatable
replySelector: '.annotatable-reply' replySelector: '.annotatable-reply'
helpSelector: '.annotatable-help-icon' helpSelector: '.annotatable-help-icon'
returnSelector: '.annotatable-return' returnSelector: '.annotatable-return'
problemSelector: 'section.problem'
discussionXModuleSelector: '.xmodule_DiscussionModule' discussionXModuleSelector: '.xmodule_DiscussionModule'
discussionSelector: '.discussion-module' discussionSelector: '.discussion-module'
...@@ -76,37 +77,36 @@ class @Annotatable ...@@ -76,37 +77,36 @@ class @Annotatable
onClickReply: (e) => onClickReply: (e) =>
e.preventDefault() e.preventDefault()
offset = -20
problem_el = @getProblemEl e.currentTarget el = @getProblem e.currentTarget
if problem_el.length == 1 @scrollTo(el, @afterScrollToProblem, offset)
@scrollTo(problem_el, @afterScrollToProblem)
else
console.log 'Problem not found! Event: ', e
onClickReturn: (e) => onClickReturn: (e) =>
e.preventDefault() e.preventDefault()
el = @getSpan e.currentTarget
offset = -200 offset = -200
el = @getSpan e.currentTarget
@scrollTo(el, @afterScrollToSpan, offset) @scrollTo(el, @afterScrollToSpan, offset)
getSpan: (el) -> getSpan: (el) ->
span_id = @getSpanId(el) span_id = @getSpanId(el)
@$(@spanSelector).filter("[data-span-id='#{span_id}']") @$(@spanSelector).filter("[data-span-id='#{span_id}']")
getProblem: (el) ->
problem_id = parseInt(@getProblemId(el), 10)
if isNaN(problem_id)
console.log 'invalid problem identifier' if @_debug
return $()
return $(@problemSelector).eq(problem_id - 1)
getDiscussion: (el) -> 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}']")
getProblem: (el) -> getSpanId: (el) ->
el # TODO $(el).data('span-id')
getProblemId: (el) -> getProblemId: (el) ->
$(el).data('problem-id') $(el).data('problem-id')
getSpanId: (el) ->
$(el).data('span-id')
getDiscussionId: () -> getDiscussionId: () ->
@$(@wrapperSelector).data('discussion-id') @$(@wrapperSelector).data('discussion-id')
...@@ -152,7 +152,8 @@ class @Annotatable ...@@ -152,7 +152,8 @@ class @Annotatable
(api) => (api) =>
text = $(el).data('comment-body') text = $(el).data('comment-body')
comment = @createCommentEl(text) comment = @createCommentEl(text)
reply = @createReplyLink('dummy-problem-id') problem_id = @getProblemId(el)
reply = @createReplyLink(problem_id)
$(comment).add(reply) $(comment).add(reply)
makeTipTitle: (el) -> makeTipTitle: (el) ->
...@@ -200,4 +201,4 @@ class @Annotatable ...@@ -200,4 +201,4 @@ class @Annotatable
done = false done = false
return => return =>
fn.call this unless done fn.call this unless done
done = true done = true
\ No newline at end of file
(function () { (function () {
console.log('annotation input loaded: ', this); console.log('annotation input loaded: ', this);
var update = function() { var update = function() {
alert("o hi"); console.log("annotation input update");
}; };
var inputs = $('.annotation-input input'); var inputs = $('.annotation-input input');
......
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