Commit 91379aa9 by Arjun Singh

improve date search, fix respnding, make sidebar expand when discussion column does

parent 9064f81b
...@@ -24,7 +24,6 @@ if Backbone? ...@@ -24,7 +24,6 @@ if Backbone?
updateInfo: (info) -> updateInfo: (info) ->
if info if info
console.log info.ability
@set('ability', info.ability) @set('ability', info.ability)
@set('voted', info.voted) @set('voted', info.voted)
@set('subscribed', info.subscribed) @set('subscribed', info.subscribed)
......
...@@ -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})
......
...@@ -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"
......
...@@ -111,7 +111,7 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -111,7 +111,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 }) 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()
......
...@@ -8,6 +8,8 @@ class @ThreadResponseView extends DiscussionContentView ...@@ -8,6 +8,8 @@ class @ThreadResponseView extends DiscussionContentView
"click .action-endorse": "toggleEndorse" "click .action-endorse": "toggleEndorse"
render: -> render: ->
console.log @model
console.log @model.toJSON()
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
if window.user.voted(@model) if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast") @$(".vote-btn").addClass("is-cast")
...@@ -65,7 +67,7 @@ class @ThreadResponseView extends DiscussionContentView ...@@ -65,7 +67,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("")
......
...@@ -68,6 +68,11 @@ $(document).ready(function() { ...@@ -68,6 +68,11 @@ $(document).ready(function() {
$(window).bind('resize', updateSidebarDimensions); $(window).bind('resize', updateSidebarDimensions);
$(window).bind('scroll', updateSidebarCoordinates); $(window).bind('scroll', updateSidebarCoordinates);
$('.discussion-column').bind("input", function (e) {
console.log("resized");
updateSidebarCoordinates();
updateSidebarDimensions();
})
updateSidebarCoordinates(); updateSidebarCoordinates();
updateSidebarDimensions(); updateSidebarDimensions();
}); });
......
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