Commit 0375710d by Rocky Duan

i meant sort before...this time it's search ajax

parent 7b65663e
......@@ -41,7 +41,7 @@ def render_accordion(request, course, discussion_id):
return render_to_string('discussion/_accordion.html', context)
def render_discussion(request, course_id, threads, discussion_id=None, with_search_bar=True, \
def render_discussion(request, course_id, threads, discussion_id=None, \
discussion_type='inline', query_params={}):
template = {
......@@ -57,8 +57,6 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear
context = {
'threads': threads,
'discussion_id': discussion_id,
'search_bar': '' if not with_search_bar \
else render_search_bar(request, course_id, discussion_id, text=query_params.get('text', '')),
'user_info': comment_client.get_user_info(request.user.id, raw=True),
'course_id': course_id,
'request': request,
......
......@@ -527,8 +527,25 @@ Discussion =
handleCancelNewPost(this)
$(elem).hide()
handleAjaxSearch = (elem) ->
console.log $(elem).attr("action")
$elem = $(elem)
$discussionModule = $elem.parents(".discussion-module")
$discussion = $discussionModule.find(".discussion")
Discussion.safeAjax
$elem: $elem
url: $elem.attr("action")
data:
text: $local(".search-input").val()
method: "GET"
success: (data, textStatus) ->
$discussion.replaceWith(data)
$discussion = $discussionModule.find(".discussion")
Discussion.initializeDiscussion($discussion)
Discussion.bindDiscussionEvents($discussion)
dataType: 'html'
handleSort = (elem) ->
handleAjaxSort = (elem) ->
$elem = $(elem)
$discussionModule = $elem.parents(".discussion-module")
$discussion = $discussionModule.find(".discussion")
......@@ -543,7 +560,7 @@ Discussion =
Discussion.bindDiscussionEvents($discussion)
dataType: 'html'
$local(".discussion-search-form").submit (event) ->
$local(".search-wrapper-forum > .discussion-search-form").submit (event) ->
event.preventDefault()
text = $local(".search-input").val()
isSearchWithinBoard = $local(".discussion-search-within-board").is(":checked")
......@@ -552,11 +569,16 @@ Discussion =
$local(".discussion-new-post").click ->
handleNewPost(this)
$local(".discussion-search").click ->
$local(".new-post-form").submit()
$local(".discussion-search-link").click ->
handleAjaxSearch(this)
$local(".search-wrapper-inline > .discussion-search-form").submit (e)->
e.preventDefault()
handleAjaxSearch(this)
$local(".discussion-inline-sort-link").click ->
handleAjaxSort(this)
$discussion.children(".discussion-sort").find(".discussion-inline-sort-link").click ->
handleSort(this)
$discussion.find(".thread").each (index, thread) ->
Discussion.initializeContent(thread)
......
......@@ -5,14 +5,16 @@
<div class="discussion-title-wrapper">
<a class="discussion-title" href="javascript:void(0)">Discussion</a>
</div>
${search_bar}
<div class="search-wrapper-forum">
<%include file="_search_bar.html" />
</div>
<div class="search-within">
<input type="checkbox" id="discussion-search-within-board-${discussion_id}" class="discussion-search-within-board" checked/>
<label for="discussion-search-within-board-${discussion_id}" class="discussion-search-within-board">Search within board</label>
</div>
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
<%include file="_sort.html" />
</div>
<%include file="_sort.html" />
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
......
......@@ -3,11 +3,11 @@
<section class="discussion inline-discussion" _id="${discussion_id}">
<div class="discussion-non-content">
<div class="search-wrapper-inline">
${search_bar}
<%include file="_search_bar.html" />
</div>
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
<%include file="_sort.html" />
</div>
<%include file="_sort.html" />
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
......
<%! from django.core.urlresolvers import reverse %>
<%! from urllib import urlencode %>
<%
def url_for_search():
return reverse('django_comment_client.forum.views.search', args=[course_id])
def merge(dic1, dic2):
return dict(dic1.items() + dic2.items())
def base_url_for_search():
return base_url + '?' + urlencode(merge(query_params, {'page': 1}))
%>
<form action="${url_for_search()}" method="get" class="discussion-search-form">
<form action="${base_url_for_search()}" method="get" class="discussion-search-form">
<input class="search-input" type="text" value="${text}" id="keywords" autocomplete="off"/>
<div class="discussion-link" href="javascript:void(0)">Search posts</div>
<div class="discussion-link discussion-search-link" href="javascript:void(0)">Search posts</div>
</form>
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