Commit 6ee27d02 by Matthew Mongeau

Searching and fixes.

parent 3cc3876b
...@@ -20,7 +20,7 @@ import django_comment_client.utils as utils ...@@ -20,7 +20,7 @@ import django_comment_client.utils as utils
import comment_client as cc import comment_client as cc
THREADS_PER_PAGE = 5 THREADS_PER_PAGE = 50000
PAGES_NEARBY_DELTA = 2 PAGES_NEARBY_DELTA = 2
......
...@@ -427,6 +427,22 @@ if Backbone? ...@@ -427,6 +427,22 @@ if Backbone?
unfollow: -> unfollow: ->
@trigger "thread:unfollow" @trigger "thread:unfollow"
display_body: ->
if @has("highlighted_body")
@get("highlighted_body")
else
@get("body")
display_title: ->
if @has("highlighted_title")
@get("highlighted_title")
else
@get("title")
toJSON: ->
json_attributes = _.clone(@attributes)
_.extend(json_attributes, { title: @display_title(), body: @display_body() })
class @ThreadView extends @ContentView class @ThreadView extends @ContentView
class @Comment extends @Content class @Comment extends @Content
......
...@@ -5,9 +5,10 @@ class @DiscussionRouter extends Backbone.Router ...@@ -5,9 +5,10 @@ class @DiscussionRouter extends Backbone.Router
initialize: (options) -> initialize: (options) ->
@discussion = options['discussion'] @discussion = options['discussion']
@nav = new DiscussionThreadListView(collection: @discussion, el: $(".post-list")) @nav = new DiscussionThreadListView(collection: @discussion, el: $(".sidebar"))
@nav.on "thread:selected", @navigateToThread @nav.on "thread:selected", @navigateToThread
@nav.render() @nav.render()
@main = new DiscussionThreadView(el: $(".discussion-column"))
allThreads: -> allThreads: ->
true true
...@@ -15,8 +16,8 @@ class @DiscussionRouter extends Backbone.Router ...@@ -15,8 +16,8 @@ class @DiscussionRouter extends Backbone.Router
showThread: (forum_name, thread_id) -> showThread: (forum_name, thread_id) ->
@nav.setActiveThread(thread_id) @nav.setActiveThread(thread_id)
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
view = new DiscussionThreadView(el: $(".discussion-column"), model: thread) @main.model = thread
view.render() @main.render()
navigateToThread: (thread_id) => navigateToThread: (thread_id) =>
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
......
class @DiscussionThreadListView extends Backbone.View class @DiscussionThreadListView extends Backbone.View
template: _.template($("#thread-list-template").html())
events:
"click .search": "showSearch"
"keyup .post-search-field": "performSearch"
render: -> render: ->
@collection.each @renderThreadListItem @timer = 0;
@$el.html(@template())
@collection.on "reset", @renderThreads
@renderThreads()
@ @
renderThreads: =>
@$(".post-list").html("")
@collection.each @renderThreadListItem
renderThreadListItem: (thread) => renderThreadListItem: (thread) =>
view = new ThreadListItemView(model: thread) view = new ThreadListItemView(model: thread)
view.on "thread:selected", @threadSelected view.on "thread:selected", @threadSelected
view.render() view.render()
@$el.append(view.el) @$(".post-list").append(view.el)
threadSelected: (thread_id) => threadSelected: (thread_id) =>
@setActiveThread(thread_id) @setActiveThread(thread_id)
...@@ -16,3 +29,28 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -16,3 +29,28 @@ class @DiscussionThreadListView extends Backbone.View
@$("a").removeClass("active") @$("a").removeClass("active")
@$("a[data-id='#{thread_id}']").addClass("active") @$("a[data-id='#{thread_id}']").addClass("active")
showSearch: ->
@$(".search").addClass('is-open');
@$(".browse").removeClass('is-open');
setTimeout (-> @$(".post-search-field").focus()), 200
delay: (callback, ms) =>
clearTimeout(@timer)
@timer = setTimeout(callback, ms)
performSearch: ->
callback = =>
url = DiscussionUtil.urlFor("search")
text = @$(".post-search-field").val()
DiscussionUtil.safeAjax
$elem: @$(".post-search-field")
data: { text: text }
url: url
type: "GET"
success: (response, textStatus) =>
console.log textStatus
if textStatus == 'success'
@collection.reset(response.discussion_data)
console.log(@collection)
@delay(callback, 300)
...@@ -5,14 +5,9 @@ class @DiscussionThreadView extends Backbone.View ...@@ -5,14 +5,9 @@ class @DiscussionThreadView extends Backbone.View
"click .discussion-submit-post": "submitComment" "click .discussion-submit-post": "submitComment"
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: (options) ->
@model.bind "change", @updateModelDetails
@$el.html(@template(@model.toJSON()))
updateModelDetails: =>
@$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"])
render: -> render: ->
@$el.html(@template(@model.toJSON()))
@model.bind "change", @updateModelDetails
if window.user.following(@model) if window.user.following(@model)
@$(".dogear").addClass("is-followed") @$(".dogear").addClass("is-followed")
...@@ -24,6 +19,9 @@ class @DiscussionThreadView extends Backbone.View ...@@ -24,6 +19,9 @@ class @DiscussionThreadView extends Backbone.View
@renderResponses() @renderResponses()
@ @
updateModelDetails: =>
@$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"])
convertMath: -> convertMath: ->
element = @$(".post-body") element = @$(".post-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html() element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html()
......
...@@ -19,8 +19,8 @@ var tooltipCoords; ...@@ -19,8 +19,8 @@ var tooltipCoords;
$(document).ready(function() { $(document).ready(function() {
$body = $('body'); $body = $('body');
$browse = $('.browse-search .browse'); $browse = $('.browse-search .browse');
$search = $('.browse-search .search'); // $search = $('.browse-search .search');
$searchField = $('.post-search-field'); // $searchField = $('.post-search-field');
$topicDrop = $('.board-drop-menu'); $topicDrop = $('.board-drop-menu');
$currentBoard = $('.current-board'); $currentBoard = $('.current-board');
$tooltip = $('<div class="tooltip"></div>'); $tooltip = $('<div class="tooltip"></div>');
...@@ -34,7 +34,7 @@ $(document).ready(function() { ...@@ -34,7 +34,7 @@ $(document).ready(function() {
sidebarWidth = $('.sidebar').width(); sidebarWidth = $('.sidebar').width();
$browse.bind('click', showTopicDrop); $browse.bind('click', showTopicDrop);
$search.bind('click', showSearch); // $search.bind('click', showSearch);
$topicDrop.bind('click', setTopic); $topicDrop.bind('click', setTopic);
$formTopicDropBtn.bind('click', showFormTopicDrop); $formTopicDropBtn.bind('click', showFormTopicDrop);
$formTopicDropMenu.bind('click', setFormTopic); $formTopicDropMenu.bind('click', setFormTopic);
...@@ -99,13 +99,13 @@ function showBrowse(e) { ...@@ -99,13 +99,13 @@ function showBrowse(e) {
$searchField.val(''); $searchField.val('');
} }
function showSearch(e) { // function showSearch(e) {
$search.addClass('is-open'); // $search.addClass('is-open');
$browse.removeClass('is-open'); // $browse.removeClass('is-open');
setTimeout(function() { // setTimeout(function() {
$searchField.focus(); // $searchField.focus();
}, 200); // }, 200);
} // }
function showTopicDrop(e) { function showTopicDrop(e) {
e.preventDefault(); e.preventDefault();
......
...@@ -116,7 +116,12 @@ ...@@ -116,7 +116,12 @@
<div class="discussion container"> <div class="discussion container">
<div class="discussion-body"> <div class="discussion-body">
<div class="sidebar"> <div class="sidebar"></div>
<div class="discussion-column"></div>
</div>
</div>
<script type="text/template" id="thread-list-template">
<div class="browse-search"> <div class="browse-search">
<div class="browse is-open"> <div class="browse is-open">
<a href="#" class="board-drop-icon"></a> <a href="#" class="board-drop-icon"></a>
...@@ -158,14 +163,7 @@ ...@@ -158,14 +163,7 @@
<ul class="post-list"> <ul class="post-list">
</ul> </ul>
</div> </div>
</div> </script>
<div class="discussion-column">
</div>
</div>
</div>
<script type="text/template" id="thread-template"> <script type="text/template" id="thread-template">
<article class="discussion-article" data-id="${'<%= id %>'}"> <article class="discussion-article" data-id="${'<%= id %>'}">
......
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