Commit 8a58582e by Ibrahim Awwal

Add newly posted threads to the inline thread list.

parent b7e88a83
...@@ -15,7 +15,6 @@ if Backbone? ...@@ -15,7 +15,6 @@ if Backbone?
@newPostForm.slideUp(300) @newPostForm.slideUp(300)
toggleDiscussion: (event) -> toggleDiscussion: (event) ->
console.log "doing stuff yo"
if @showed if @showed
@$("section.discussion").hide() @$("section.discussion").hide()
$(event.target).html("Show Discussion") $(event.target).html("Show Discussion")
...@@ -38,22 +37,28 @@ if Backbone? ...@@ -38,22 +37,28 @@ if Backbone?
success: (response, textStatus, jqXHR) => @createDiscussion(event, response, textStatus) success: (response, textStatus, jqXHR) => @createDiscussion(event, response, textStatus)
createDiscussion: (event, response, textStatus) => createDiscussion: (event, response, textStatus) =>
console.log "HI"
console.log response
window.user = new DiscussionUser(response.user_info) window.user = new DiscussionUser(response.user_info)
Content.loadContentInfos(response.annotated_content_info) Content.loadContentInfos(response.annotated_content_info)
console.log "infod"
$(event.target).html("Hide Discussion") $(event.target).html("Hide Discussion")
discussion = new Discussion() @discussion = new Discussion()
discussion.reset(response.discussion_data, {silent: false}) @discussion.reset(response.discussion_data, {silent: false})
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data}) $discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data})
$(".discussion-module").append($discussion) $(".discussion-module").append($discussion)
@newPostForm = $('.new-post-article') @newPostForm = $('.new-post-article')
discussion.each (thread) -> @threadviews = @discussion.map (thread) ->
element = $("article#thread_#{thread.id}") new DiscussionThreadInlineView el: @$("article#thread_#{thread.id}"), model: thread
dtv = new DiscussionThreadInlineView el: element, model: thread _.each @threadviews, (dtv) -> dtv.render()
dtv.render()
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info) DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
@newPostView = new NewPostInlineView el: $('.new-post-article'), collection: discussion @newPostView = new NewPostInlineView el: @$('.new-post-article'), collection: @discussion
@discussion.on "add", @addThread
@retrieved = true @retrieved = true
@showed = true @showed = true
addThread: (thread, collection, options) =>
# TODO: When doing pagination, this will need to repaginate
article = $("<article class='discussion-thread' id='thread_#{thread.id}'></article>")
@$('section.discussion > .threads').prepend(article)
threadView = new DiscussionThreadInlineView el: article, model: thread
threadView.render()
@threadviews.unshift threadView
...@@ -29,9 +29,10 @@ ...@@ -29,9 +29,10 @@
</div> </div>
</article> </article>
<section class="threads">
{{#threads}} {{#threads}}
<article class="discussion-thread" id="thread_{{id}}"> <article class="discussion-thread" id="thread_{{id}}">
</article> </article>
{{/threads}} {{/threads}}
</section>
</section> </section>
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