Commit b5df53f9 by Tom Giannattasio

fixed merge conflict

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