some progress
This commit is contained in:
@@ -164,9 +164,9 @@ def forum_form_discussion(request, course_id):
|
||||
|
||||
def render_single_thread(request, discussion_id, course_id, thread_id):
|
||||
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True)
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True).to_dict()
|
||||
|
||||
annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread.to_dict(), user=request.user)
|
||||
annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread, user=request.user)
|
||||
|
||||
context = {
|
||||
'discussion_id': discussion_id,
|
||||
@@ -175,6 +175,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id):
|
||||
'annotated_content_info': json.dumps(annotated_content_info),
|
||||
'course_id': course_id,
|
||||
'request': request,
|
||||
'discussion_data': json.dumps({ discussion_id: [thread] }),
|
||||
}
|
||||
return render_to_string('discussion/_single_thread.html', context)
|
||||
|
||||
@@ -201,7 +202,6 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'init': '',
|
||||
'content': render_single_thread(request, discussion_id, course_id, thread_id),
|
||||
'accordion': render_accordion(request, course, discussion_id),
|
||||
'course': course,
|
||||
'course_id': course.id,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import json
|
||||
|
||||
class AjaxExceptionMiddleware(object):
|
||||
def process_exception(self, request, exception):
|
||||
import pdb; pdb.set_trace()
|
||||
if isinstance(exception, CommentClientError) and request.is_ajax():
|
||||
return JsonError(json.loads(exception.message))
|
||||
return None
|
||||
|
||||
@@ -43,6 +43,9 @@ class Model(object):
|
||||
raise KeyError("Field {0} does not exist".format(key))
|
||||
self.attributes.__setitem__(key, value)
|
||||
|
||||
def items(self, *args, **kwargs):
|
||||
return self.attributes.items(*args, **kwargs)
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
return self.attributes.get(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -29,6 +29,32 @@ class @ContentView extends Backbone.View
|
||||
@$local.find(selector)
|
||||
|
||||
showSingleThread: (event) ->
|
||||
if @showed
|
||||
@$el.children(".comments").hide()
|
||||
@showed = false
|
||||
$showComments = @$(".discussion-show-comments")
|
||||
prevHtml = $showComments.html()
|
||||
$showComments.html prevHtml.replace "Hide", "Show"
|
||||
else
|
||||
if @retrieved
|
||||
@$el.children(".comments").show()
|
||||
@showed = true
|
||||
else
|
||||
discussion_id = @model.discussion.id
|
||||
url = DiscussionUtil.urlFor('retrieve_single_thread', discussion_id, @model.id)
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: $.merge @$(".thread-title"), @$(".discussion-show-comments")
|
||||
url: url
|
||||
type: "GET"
|
||||
dataType: 'json'
|
||||
success: (response, textStatus) =>
|
||||
DiscussionUtil.bulkExtendContentInfo response['annotated_content_info']
|
||||
@retrieved = true
|
||||
@showed = true
|
||||
@$el.append(response['html'])
|
||||
@model.get('comments').reset response.content.children, {silent: false}
|
||||
@initCommentViews()
|
||||
return
|
||||
$threadTitle = @$(".thread-title")
|
||||
$showComments = @$(".discussion-show-comments")
|
||||
|
||||
@@ -133,15 +159,15 @@ class @ContentView extends Backbone.View
|
||||
@$(".discussion-votes-point").html response.votes.point
|
||||
|
||||
endorse: (event) ->
|
||||
url = DiscussionUtil.urlFor('endorse_comment', id)
|
||||
endorsed = not @model.get('endorsed')
|
||||
url = DiscussionUtil.urlFor('endorse_comment', @model.id)
|
||||
endorsed = not @$el.hasClass("endorsed")
|
||||
Discussion.safeAjax
|
||||
$elem: $(event.target)
|
||||
url: url
|
||||
type: "POST"
|
||||
dataType: "json"
|
||||
data: {endorsed: endorsed}
|
||||
success: (response, textStatus) ->
|
||||
success: (response, textStatus) =>
|
||||
if textStatus == "success"
|
||||
if endorsed
|
||||
@$el.addClass("endorsed")
|
||||
@@ -211,6 +237,7 @@ class @ContentView extends Backbone.View
|
||||
Discussion.extendContentInfo response.content['id'], response['annotated_content_info']
|
||||
Discussion.initializeContent($content)
|
||||
Discussion.bindContentEvents($content)
|
||||
|
||||
delete: ->
|
||||
if $content.hasClass("thread")
|
||||
url = Discussion.urlFor('delete_thread', id)
|
||||
@@ -274,12 +301,25 @@ class @ContentView extends Backbone.View
|
||||
initTimeago: ->
|
||||
@$("span.timeago").timeago()
|
||||
|
||||
initPermalink: ->
|
||||
|
||||
if @model.get('type') == 'thread'
|
||||
discussion_id = @model.get('commentable_id')
|
||||
permalink = Discussion.urlFor("permanent_link_thread", discussion_id, @model.id)
|
||||
else
|
||||
thread_id = @model.get('thread_id')
|
||||
discussion_id = @$el.parents(".thread").attr("_discussion_id")
|
||||
permalink = Discussion.urlFor("permanent_link_comment", discussion_id, thread_id, @model.id)
|
||||
|
||||
@$(".discussion-permanent-link").attr "href", permalink
|
||||
|
||||
initialize: ->
|
||||
@model.view = @
|
||||
@initLocal()
|
||||
@initVote()
|
||||
@initTimeago()
|
||||
@initBody()
|
||||
@initPermalink()
|
||||
@initActions()
|
||||
@initCommentViews()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="discussion-content">
|
||||
<div class="discussion-content local">
|
||||
<div class="discussion-content-wrapper">
|
||||
<div class="discussion-votes">
|
||||
<a class="discussion-vote discussion-vote-up" href="javascript:void(0)" value="up">▲</a>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<%def name="render_content_with_comments(content)">
|
||||
<div class="${content['type']}${helpers.show_if(' endorsed', content.get('endorsed'))}" _id="${content['id']}" _discussion_id="${content.get('commentable_id', '')}" _author_id="${helpers.show_if(content['user_id'], not content.get('anonymous'))}">
|
||||
<div class="local">${render_content(content)}</div>
|
||||
${render_content(content)}
|
||||
% if content.get('children') is not None:
|
||||
${render_comments(content['children'])}
|
||||
% endif
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
</div>
|
||||
<div class="threads"></div>
|
||||
% else:
|
||||
<div class="local"><%include file="_sort.html" /></div>
|
||||
<%include file="_sort.html" />
|
||||
<div class="threads">
|
||||
% for thread in threads:
|
||||
${renderer.render_content_with_comments(thread)}
|
||||
% endfor
|
||||
</div>
|
||||
<div class="local"><%include file="_paginator.html" /></div>
|
||||
<%include file="_paginator.html" />
|
||||
% endif
|
||||
</section>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
% endfor
|
||||
</div>
|
||||
|
||||
<div class="local"><%include file="_paginator.html" /></div>
|
||||
<%include file="_paginator.html" />
|
||||
</section>
|
||||
|
||||
<%include file="_js_data.html" />
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
% endfor
|
||||
</%def>
|
||||
|
||||
<div class="discussion-${discussion_type}-paginator discussion-paginator">
|
||||
<div class="discussion-${discussion_type}-paginator discussion-paginator local">
|
||||
<div class="prev-page">
|
||||
% if page > 1:
|
||||
${link_to_page(page - 1, "< Previous page")}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
<section class="discussion" _id="${discussion_id}">
|
||||
<a class="discussion-title" href="javascript:void(0)">Discussion</a>
|
||||
${renderer.render_content_with_comments(thread)}
|
||||
<div class="threads">
|
||||
${renderer.render_content_with_comments(thread)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<%include file="_js_data.html" />
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<a class="discussion-sort-link ${cls}" href="javascript:void(0)" sort-url="${url_for_sort(key, order)}">${title}</a>
|
||||
</%def>
|
||||
|
||||
<div class="discussion-sort discussion-local">
|
||||
<div class="discussion-sort local">
|
||||
<span class="discussion-label">Sort by:</span>
|
||||
${link_to_sort('activity', 'top')}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user