Commit c88efb1b by Tom Giannattasio

fixed merge conflict

parents 1b2f8c3e dc3f06e5
...@@ -162,22 +162,22 @@ def forum_form_discussion(request, course_id): ...@@ -162,22 +162,22 @@ def forum_form_discussion(request, course_id):
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
}) })
else: else:
recent_active_threads = cc.search_recent_active_threads( #recent_active_threads = cc.search_recent_active_threads(
course_id, # course_id,
recursive=False, # recursive=False,
query_params={'follower_id': request.user.id}, # query_params={'follower_id': request.user.id},
) #)
trending_tags = cc.search_trending_tags( #trending_tags = cc.search_trending_tags(
course_id, # course_id,
) #)
escapedict = {'"': '"'} escapedict = {'"': '"'}
context = { context = {
'csrf': csrf(request)['csrf_token'], 'csrf': csrf(request)['csrf_token'],
'course': course, 'course': course,
'content': content, 'content': content,
'recent_active_threads': recent_active_threads, #'recent_active_threads': recent_active_threads,
'trending_tags': trending_tags, #'trending_tags': trending_tags,
'staff_access' : has_access(request.user, course, 'staff'), 'staff_access' : has_access(request.user, course, 'staff'),
'threads': saxutils.escape(json.dumps(threads),escapedict), 'threads': saxutils.escape(json.dumps(threads),escapedict),
'user_info': saxutils.escape(json.dumps(user_info),escapedict), 'user_info': saxutils.escape(json.dumps(user_info),escapedict),
......
...@@ -447,6 +447,14 @@ if Backbone? ...@@ -447,6 +447,14 @@ if Backbone?
@set('subscribed', false) @set('subscribed', false)
@trigger "thread:unfollow" @trigger "thread:unfollow"
vote: ->
@get("votes")["up_count"] = parseInt(@get("votes")["up_count"]) + 1
@trigger "change"
unvote: ->
@get("votes")["up_count"] = parseInt(@get("votes")["up_count"]) - 1
@trigger "change"
display_body: -> display_body: ->
if @has("highlighted_body") if @has("highlighted_body")
String(@get("highlighted_body")).replace(/<highlight>/g, '<mark>').replace(/<\/highlight>/g, '</mark>') String(@get("highlighted_body")).replace(/<highlight>/g, '<mark>').replace(/<\/highlight>/g, '</mark>')
......
...@@ -5,7 +5,7 @@ if Backbone? ...@@ -5,7 +5,7 @@ if Backbone?
initialize: -> initialize: ->
@bind "add", (item) => @bind "add", (item) =>
item.discussion = @ item.discussion = @
@comparator = @sortByDate @comparator = @sortByDateRecentFirst
find: (id) -> find: (id) ->
_.first @where(id: id) _.first @where(id: id)
...@@ -19,6 +19,13 @@ if Backbone? ...@@ -19,6 +19,13 @@ if Backbone?
sortByDate: (thread) -> sortByDate: (thread) ->
thread.get("created_at") thread.get("created_at")
sortByDateRecentFirst: (thread) ->
-(new Date(thread.get("created_at")).getTime())
#return String.fromCharCode.apply(String,
# _.map(thread.get("created_at").split(""),
# ((c) -> return 0xffff - c.charChodeAt()))
#)
sortByVotes: (thread1, thread2) -> sortByVotes: (thread1, thread2) ->
thread1_count = parseInt(thread1.get("votes")['up_count']) thread1_count = parseInt(thread1.get("votes")['up_count'])
thread2_count = parseInt(thread2.get("votes")['up_count']) thread2_count = parseInt(thread2.get("votes")['up_count'])
......
...@@ -8,6 +8,7 @@ DiscussionApp = ...@@ -8,6 +8,7 @@ DiscussionApp =
threads = element.data("threads") threads = element.data("threads")
content_info = element.data("content-info") content_info = element.data("content-info")
window.user = new DiscussionUser(user_info) window.user = new DiscussionUser(user_info)
console.log content_info
Content.loadContentInfos(content_info) Content.loadContentInfos(content_info)
discussion = new Discussion(threads) discussion = new Discussion(threads)
new DiscussionRouter({discussion: discussion}) new DiscussionRouter({discussion: discussion})
......
...@@ -4,3 +4,11 @@ class @DiscussionUser extends Backbone.Model ...@@ -4,3 +4,11 @@ class @DiscussionUser extends Backbone.Model
voted: (thread) -> voted: (thread) ->
_.include(@get('upvoted_ids'), thread.id) _.include(@get('upvoted_ids'), thread.id)
vote: (thread) ->
@get('upvoted_ids').push(thread.id)
thread.vote()
unvote: (thread) ->
@set('upvoted_ids', _.without(@get('upvoted_ids'), thread.id))
thread.unvote()
...@@ -3,7 +3,7 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -3,7 +3,7 @@ class @DiscussionThreadListView extends Backbone.View
events: events:
"click .search": "showSearch" "click .search": "showSearch"
"click .browse": "toggleTopicDrop" "click .browse": "toggleTopicDrop"
"keyup .post-search-field": "performSearch" "keydown .post-search-field": "performSearch"
"click .sort-bar a": "sortThreads" "click .sort-bar a": "sortThreads"
"click .browse-topic-drop-menu": "filterTopic" "click .browse-topic-drop-menu": "filterTopic"
"click .browse-topic-drop-search-input": "ignoreClick" "click .browse-topic-drop-search-input": "ignoreClick"
...@@ -89,7 +89,7 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -89,7 +89,7 @@ class @DiscussionThreadListView extends Backbone.View
$(event.target).addClass("active") $(event.target).addClass("active")
sortBy = $(event.target).data("sort") sortBy = $(event.target).data("sort")
if sortBy == "date" if sortBy == "date"
@displayedCollection.comparator = @displayedCollection.sortByDate @displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst
else if sortBy == "votes" else if sortBy == "votes"
@displayedCollection.comparator = @displayedCollection.sortByVotes @displayedCollection.comparator = @displayedCollection.sortByVotes
else if sortBy == "comments" else if sortBy == "comments"
...@@ -100,8 +100,9 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -100,8 +100,9 @@ class @DiscussionThreadListView extends Backbone.View
clearTimeout(@timer) clearTimeout(@timer)
@timer = setTimeout(callback, ms) @timer = setTimeout(callback, ms)
performSearch: -> performSearch: (event) ->
callback = => if event.which == 13
event.preventDefault()
url = DiscussionUtil.urlFor("search") url = DiscussionUtil.urlFor("search")
text = @$(".post-search-field").val() text = @$(".post-search-field").val()
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
...@@ -112,6 +113,4 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -112,6 +113,4 @@ class @DiscussionThreadListView extends Backbone.View
success: (response, textStatus) => success: (response, textStatus) =>
if textStatus == 'success' if textStatus == 'success'
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
@displayedCollection.reset(@collection) @displayedCollection.reset(@collection.models)
@delay(callback, 300)
...@@ -22,22 +22,32 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -22,22 +22,32 @@ class @DiscussionThreadView extends DiscussionContentView
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: ->
@model.on "change", @updateModelDetails
render: -> render: ->
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
@model.bind "change", @updateModelDetails @renderDogear()
if window.user.following(@model) @renderVoted()
@$(".dogear").addClass("is-followed")
if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast")
@$("span.timeago").timeago() @$("span.timeago").timeago()
Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text) Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text)
@convertMath() @convertMath()
@renderResponses() @renderResponses()
@ @
renderDogear: ->
if window.user.following(@model)
@$(".dogear").addClass("is-followed")
renderVoted: =>
if window.user.voted(@model)
@$("[data-role=discussion-vote]").addClass("is-cast")
else
@$("[data-role=discussion-vote]").removeClass("is-cast")
updateModelDetails: => updateModelDetails: =>
@$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"]) @renderVoted()
@$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"])
convertMath: -> convertMath: ->
element = @$(".post-body") element = @$(".post-body")
...@@ -64,10 +74,10 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -64,10 +74,10 @@ class @DiscussionThreadView extends DiscussionContentView
toggleVote: (event) -> toggleVote: (event) ->
event.preventDefault() event.preventDefault()
if not @model.get('voted')#@$(".discussion-vote").hasClass("is-cast") if window.user.voted(@model)
@vote()
else
@unvote() @unvote()
else
@vote()
toggleFollowing: (event) -> toggleFollowing: (event) ->
$elem = $(event.target) $elem = $(event.target)
...@@ -84,9 +94,8 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -84,9 +94,8 @@ class @DiscussionThreadView extends DiscussionContentView
type: "POST" type: "POST"
vote: -> vote: ->
window.user.vote(@model)
url = @model.urlFor("upvote") url = @model.urlFor("upvote")
@model.set('votes_point', parseInt(@model.get('votes_point')) + 1)
#@$(".discussion-vote .votes-count-number").html(parseInt(@$(".discussion-vote .votes-count-number").html()) + 1)
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-vote") $elem: @$(".discussion-vote")
url: url url: url
...@@ -96,9 +105,8 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -96,9 +105,8 @@ class @DiscussionThreadView extends DiscussionContentView
@model.set(response) @model.set(response)
unvote: -> unvote: ->
window.user.unvote(@model)
url = @model.urlFor("unvote") url = @model.urlFor("unvote")
@model.set('votes_point', parseInt(@model.get('votes_point')) - 1)
#@$(".discussion-vote .votes-count-number").html(parseInt(@$(".discussion-vote .votes-count-number").html()) - 1)
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-vote") $elem: @$(".discussion-vote")
url: url url: url
...@@ -111,7 +119,7 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -111,7 +119,7 @@ class @DiscussionThreadView extends DiscussionContentView
event.preventDefault() event.preventDefault()
url = @model.urlFor('reply') url = @model.urlFor('reply')
body = @$("#wmd-input").val() body = @$("#wmd-input").val()
response = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), votes: { up_count: 0 }, endorsed: false) response = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), votes: { up_count: 0 }, endorsed: false, user_id: window.user.get("id"))
@renderResponse(response) @renderResponse(response)
@addComment() @addComment()
......
...@@ -65,7 +65,7 @@ class @ThreadResponseView extends DiscussionContentView ...@@ -65,7 +65,7 @@ class @ThreadResponseView extends DiscussionContentView
body = @$(".comment-form-input").val() body = @$(".comment-form-input").val()
if not body.trim().length if not body.trim().length
return return
comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username")) comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"))
@renderComment(comment) @renderComment(comment)
@trigger "comment:add" @trigger "comment:add"
@$(".comment-form-input").val("") @$(".comment-form-input").val("")
......
...@@ -69,6 +69,10 @@ $(document).ready(function() { ...@@ -69,6 +69,10 @@ $(document).ready(function() {
$(window).bind('resize', updateSidebar); $(window).bind('resize', updateSidebar);
$(window).bind('scroll', updateSidebar); $(window).bind('scroll', updateSidebar);
$('.discussion-column').bind("input", function (e) {
console.log("resized");
updateSidebar();
})
updateSidebar(); updateSidebar();
}); });
...@@ -349,4 +353,4 @@ function updateSidebar(e) { ...@@ -349,4 +353,4 @@ function updateSidebar(e) {
// update title wrappers // update title wrappers
var titleWidth = sidebarWidth - 115; var titleWidth = sidebarWidth - 115;
$sidebarWidthStyles.html('.discussion-body .post-list a .title { width: ' + titleWidth + 'px !important; }'); $sidebarWidthStyles.html('.discussion-body .post-list a .title { width: ' + titleWidth + 'px !important; }');
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<a href="javascript:void(0)" class="dogear action-follow"></a> <a href="javascript:void(0)" class="dogear action-follow"></a>
<div class="discussion-post"> <div class="discussion-post">
<header> <header>
<a href="#" class="vote-btn discussion-vote discussion-vote-up"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a> <a href="#" class="vote-btn discussion-vote discussion-vote-up" data-role="discussion-vote"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a>
<h1>${'<%- title %>'}</h1> <h1>${'<%- title %>'}</h1>
<p class="posted-details"> <p class="posted-details">
<span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span> by <span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span> by
......
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