Skip to content

Commit

Permalink
Show transclusions better in the details of each comment, animate the…
Browse files Browse the repository at this point in the history
… scroll when selecting comments and transclusions.
  • Loading branch information
mikemintz committed Sep 14, 2011
1 parent 7f5de67 commit 29e4481
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
16 changes: 7 additions & 9 deletions deme_django/cms/templates/textdocument/show.html
Expand Up @@ -23,6 +23,9 @@

$(document).ready(function () {
DemeCanvasPointing.setup();
var comment_id = {% if highlighted_comment_id %}'{{ highlighted_comment_id }}'{% else %}null{% endif %};
var transclusion_id = {% if highlighted_transclusion_id %}'{{ highlighted_transclusion_id }}'{% else %}null{% endif %};
highlight_comment(comment_id, transclusion_id, true, true);
});

function highlight_comment(comment_id, transclusion_id, scroll_body, scroll_comments) {
Expand All @@ -48,7 +51,7 @@
// Scroll to the proper place in the comment sidebar
if (scroll_comments) {
var y = $('#right_pane_comment_' + comment_id).offset().top - $('#fixed_right_pane').offset().top;
$('#fixed_right_pane').scrollTop(y);
$('#fixed_right_pane').animate({scrollTop:y}, 500);
}
}
if (transclusion_id != null) {
Expand All @@ -61,7 +64,7 @@
// Scroll to the proper place in the document body
if (scroll_body) {
var y = $('#inline_transclusion_' + transclusion_id).offset().top;
$(document.body).scrollTop(y);
$(document.body).animate({scrollTop:y}, 500);
}
}
// Setup the canvas pointing line between transclusion and comment
Expand Down Expand Up @@ -292,14 +295,9 @@
{% endifagentcanglobal %}
{% endifagentcanglobal %}

<div id="show_located_comments"><a href="#" onclick="$('.commentref').show(); $('#hide_located_comments').show(); $('#show_located_comments').hide(); return false;">Show Located Comments</a></div>
<div id="hide_located_comments" style="display: none;"><a href="#" onclick="$('.commentref').hide(); $('#hide_located_comments').hide(); $('#show_located_comments').show(); DemeCanvasPointing.clearLine(); return false;">Hide Located Comments</a></div>
<div id="show_located_comments" style="display: none;"><a href="#" onclick="$('.commentref').show(); $('#hide_located_comments').show(); $('#show_located_comments').hide(); return false;">Show Located Comments</a></div>
<div id="hide_located_comments"><a href="#" onclick="$('.commentref').hide(); $('#hide_located_comments').hide(); $('#show_located_comments').show(); DemeCanvasPointing.clearLine(); return false;">Hide Located Comments</a></div>

<script type="text/javascript">
$(document).ready(function () {
$('.commentref').toggle();
});
</script>
{% endifagentcan %}

{% endblock content %}
Expand Down
20 changes: 14 additions & 6 deletions deme_django/cms/templatetags/item_tags.py
Expand Up @@ -705,15 +705,17 @@ def render(self, context):
result.append(u'<div style="clear: both;"></div>')
result.append(u'</div>')
def add_comment_to_div(comment_info, parents):
comment = comment_info['comment']
transclusions_to = []
for node in parents + (comment_info,):
transclusions_to.extend(node['transclusions_to'])
relevant_transclusions = [x for x in transclusions_to if x.from_item_version_number == x.from_item.version_number]
relevant_transclusions.sort(key=lambda x: (x.to_item_id != comment.pk, x.from_item_id == item.pk, x.from_item_index))
for node in parents + (comment_info,):
if node['siblings'][-1]['comment'].pk == node['comment'].pk:
result.append(u'<div class="subcomments_last">')
else:
result.append(u'<div class="subcomments">')
comment = comment_info['comment']
original_comment = parents[0]['comment'] if parents else comment
result.append(u'<div id="comment%s" style="display: none;"><form method="post" action="%s?redirect=%s">'% (comment.pk, reverse('item_type_url', kwargs={'viewer': 'textcomment', 'action': 'accordioncreate'}), urlquote(full_path)))
result.append(u'<input name="title" type="hidden" value="Re: %s" /><p>Body: <br><textarea name="body" style="height: 200px; width: 250px;"></textarea> </p> ' % (comment.name))
Expand All @@ -731,9 +733,8 @@ def add_comment_to_div(comment_info, parents):
result.append(u'<div class="comment_header" id="right_pane_comment_%d">' % comment.pk)
result.append(u'<div style="position: relative;"><div style="position: absolute; top: 0; left: 0;">')
if original_comment.item.pk == item.pk:
relevant_transclusions = [x for x in transclusions_to if x.from_item_id == item.pk and x.from_item_version_number == item.version_number]
#TODO point to all transclusions
transclusion = relevant_transclusions[0] if relevant_transclusions else None #TODO less arbitrary way to calculate
transclusion = relevant_transclusions[0] if relevant_transclusions else None
if context.get('in_textdocument_show', False):
if transclusion:
transclusion_html_id = ('' if transclusion.to_item_id == comment.pk else 'replies') + ('%d' % transclusion.pk)
Expand Down Expand Up @@ -768,8 +769,15 @@ def add_comment_to_div(comment_info, parents):
for i in xrange(len(parents) + 1):
result.append(u'</div>')
transclusion_text = ''
for transclusion in transclusions_to:
transclusion_text += u'<div>%s</div>' % get_item_link_tag(context, transclusion)
for transclusion in relevant_transclusions:
transclusion_text += u'<div style="float: left; border: thin dotted #aaa; margin: 3px; padding: 3px;">'
if transclusion.from_item_id == item.pk:
transclusion_html_id = ('' if transclusion.to_item_id == comment.pk else 'replies') + ('%d' % transclusion.pk)
transclusion_text += u'<a href="#" onclick="highlight_comment(\'%s\', \'%s\', true, false); return false;">%s</a>' % (comment.pk, transclusion_html_id, get_viewable_name(context, transclusion.from_item))
else:
transclusion_text += u'<a href="%s?highlighted_transclusion=%s">%s</a>' % (transclusion.from_item.get_absolute_url(), transclusion.pk, get_viewable_name(context, transclusion.from_item))
transclusion_text += u'</div>'
transclusion_text += u'<div style="clear: both;"></div>'
if isinstance(comment, TextComment):
if agentcan_helper(context, 'view TextDocument.body', comment):
comment_body = escape(comment.body).replace('\n', '<br />')
Expand All @@ -779,7 +787,7 @@ def add_comment_to_div(comment_info, parents):
comment_body = ''
comment_url = u'%s?crumb_filter=recursive_comments_as_child.parent.%d' % (comment.get_absolute_url(), item.pk)
result.append(u'<div id="comment_body%d" class="comment_body" style="display: none;">' % comment.pk)
if transclusions_to:
if relevant_transclusions:
result.append(u'<div style="margin-bottom: 5px; padding-bottom: 5px; border-bottom: thin solid #ccc;">%s</div>' % transclusion_text)
result.append(u'<div>%s</div>' % comment_body)
result.append(u'<div style="clear: both; font-size: smaller; margin-top: 5px; padding-top: 5px; border-top: thin solid #ccc;">')
Expand Down
2 changes: 2 additions & 0 deletions deme_django/cms/views.py
Expand Up @@ -1009,6 +1009,8 @@ class TextDocumentViewer(DocumentViewer):
def item_show_html(self):
self.context['action_title'] = ''
self.context['in_textdocument_show'] = True
self.context['highlighted_transclusion_id'] = self.request.GET.get('highlighted_transclusion')
self.context['highlighted_comment_id'] = self.request.GET.get('highlighted_comment')
self.require_ability('view ', self.item, wildcard_suffix=True)
template = loader.get_template('textdocument/show.html')
self.context['is_html'] = issubclass(self.accepted_item_type, HtmlDocument)
Expand Down

0 comments on commit 29e4481

Please sign in to comment.