diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 37cce1ada4..8050dbce7c 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -234,7 +234,6 @@ def single_thread(request, course_id, discussion_id, thread_id): 'discussion_id': discussion_id, 'csrf': csrf(request)['csrf_token'], 'init': '', - 'thread': json.dumps(utils.safe_content(thread)), 'annotated_content_info': json.dumps(annotated_content_info), 'content': render_single_thread(request, discussion_id, course_id, thread_id), 'course': course, diff --git a/lms/static/coffee/src/discussion/main.coffee b/lms/static/coffee/src/discussion/main.coffee index 0daa0ebdf3..e69de29bb2 100644 --- a/lms/static/coffee/src/discussion/main.coffee +++ b/lms/static/coffee/src/discussion/main.coffee @@ -1,108 +0,0 @@ -class @DiscussionUser - constructor: (content_info) -> - @content_info = content_info - - following: (thread) -> - @content_info[thread.id]['subscribed'] == true - - voted: (thread) -> - @content_info[thread.id]['voted'] == 'up' - -class @ThreadListItemView extends Backbone.View - tagName: "li" - template: _.template($("#thread-list-item-template").html()) - initialize: -> - @model.on "change", @render - render: => - @$el.html(@template(@model.toJSON())) - @ - -class @DiscussionThreadListView extends Backbone.View - render: -> - @collection.each @renderThreadListItem - renderThreadListItem: (thread) => - view = new ThreadListItemView(model: thread) - view.render() - @$el.append(view.el) - -class @DiscussionThreadView extends Backbone.View - events: - "click .discussion-vote-up": "toggleVote" - "click .dogear": "toggleFollowing" - initialize: (options) -> - @user = options['user'] - @model.bind "change", @updateModelDetails - - updateModelDetails: => - @$(".votes-count-number").html(@model.get("votes")["up_count"]) - - render: -> - if @user.following(@model) - @$(".dogear").addClass("is-followed") - - if @user.voted(@model) - @$(".vote-btn").addClass("is-cast") - - toggleVote: -> - @$(".vote-btn").toggleClass("is-cast") - if @$(".vote-btn").hasClass("is-cast") - @vote() - else - @unvote() - - toggleFollowing: (event) -> - $elem = $(event.target) - @$(".dogear").toggleClass("is-followed") - url = null - if @$(".dogear").hasClass("is-followed") - url = @model.urlFor("follow") - else - url = @model.urlFor("unfollow") - DiscussionUtil.safeAjax - $elem: $elem - url: url - type: "POST" - - vote: -> - url = @model.urlFor("upvote") - @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) + 1) - DiscussionUtil.safeAjax - $elem: @$(".discussion-vote") - url: url - type: "POST" - success: (response, textStatus) => - if textStatus == 'success' - @model.set(response) - - unvote: -> - url = @model.urlFor("unvote") - @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) - 1) - DiscussionUtil.safeAjax - $elem: @$(".discussion-vote") - url: url - type: "POST" - success: (response, textStatus) => - if textStatus == 'success' - @model.set(response) - -$ -> - window.$$contents = {} - window.$$discussions = {} - - # $(".discussion-module").each (index, elem) -> - # view = new DiscussionModuleView(el: elem) - - # $("section.discussion").each (index, elem) -> - # discussionData = DiscussionUtil.getDiscussionData($(elem).attr("_id")) - # discussion = new Discussion() - # discussion.reset(discussionData, {silent: false}) - # view = new DiscussionView(el: elem, model: discussion) - - # if window.$$annotated_content_info? - # DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info) - - # $userProfile = $(".discussion-sidebar>.user-profile") - # if $userProfile.length - # console.log "initialize user profile" - # view = new DiscussionUserProfileView(el: $userProfile[0]) - diff --git a/lms/static/coffee/src/discussion/models/discussion_user.coffee b/lms/static/coffee/src/discussion/models/discussion_user.coffee new file mode 100644 index 0000000000..c12006494f --- /dev/null +++ b/lms/static/coffee/src/discussion/models/discussion_user.coffee @@ -0,0 +1,10 @@ +class @DiscussionUser + constructor: (content_info) -> + @content_info = content_info + + following: (thread) -> + @content_info[thread.id]['subscribed'] == true + + voted: (thread) -> + @content_info[thread.id]['voted'] == 'up' + diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee new file mode 100644 index 0000000000..c22db5bb5b --- /dev/null +++ b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -0,0 +1,8 @@ +class @DiscussionThreadListView extends Backbone.View + render: -> + @collection.each @renderThreadListItem + @ + renderThreadListItem: (thread) => + view = new ThreadListItemView(model: thread) + view.render() + @$el.append(view.el) diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee new file mode 100644 index 0000000000..925e12ff73 --- /dev/null +++ b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee @@ -0,0 +1,61 @@ +class @DiscussionThreadView extends Backbone.View + events: + "click .discussion-vote-up": "toggleVote" + "click .dogear": "toggleFollowing" + initialize: (options) -> + @user = options['user'] + @model.bind "change", @updateModelDetails + + updateModelDetails: => + @$(".votes-count-number").html(@model.get("votes")["up_count"]) + + render: -> + if @user.following(@model) + @$(".dogear").addClass("is-followed") + + if @user.voted(@model) + @$(".vote-btn").addClass("is-cast") + + @ + + toggleVote: -> + @$(".vote-btn").toggleClass("is-cast") + if @$(".vote-btn").hasClass("is-cast") + @vote() + else + @unvote() + + toggleFollowing: (event) -> + $elem = $(event.target) + @$(".dogear").toggleClass("is-followed") + url = null + if @$(".dogear").hasClass("is-followed") + url = @model.urlFor("follow") + else + url = @model.urlFor("unfollow") + DiscussionUtil.safeAjax + $elem: $elem + url: url + type: "POST" + + vote: -> + url = @model.urlFor("upvote") + @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) + 1) + DiscussionUtil.safeAjax + $elem: @$(".discussion-vote") + url: url + type: "POST" + success: (response, textStatus) => + if textStatus == 'success' + @model.set(response) + + unvote: -> + url = @model.urlFor("unvote") + @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) - 1) + DiscussionUtil.safeAjax + $elem: @$(".discussion-vote") + url: url + type: "POST" + success: (response, textStatus) => + if textStatus == 'success' + @model.set(response) diff --git a/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee b/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee new file mode 100644 index 0000000000..28afbdc668 --- /dev/null +++ b/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee @@ -0,0 +1,8 @@ +class @ThreadListItemView extends Backbone.View + tagName: "li" + template: _.template($("#thread-list-item-template").html()) + initialize: -> + @model.on "change", @render + render: => + @$el.html(@template(@model.toJSON())) + @