Commit bad84669 by Rocky Duan

Merge branch 'master' into discussion2

parents 55ce53f9 0375710d
...@@ -41,7 +41,7 @@ def render_accordion(request, course, discussion_id): ...@@ -41,7 +41,7 @@ def render_accordion(request, course, discussion_id):
return render_to_string('discussion/_accordion.html', context) 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={}): discussion_type='inline', query_params={}):
template = { template = {
...@@ -57,8 +57,6 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear ...@@ -57,8 +57,6 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear
context = { context = {
'threads': threads, 'threads': threads,
'discussion_id': discussion_id, '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), 'user_info': comment_client.get_user_info(request.user.id, raw=True),
'course_id': course_id, 'course_id': course_id,
'request': request, 'request': request,
......
...@@ -527,8 +527,25 @@ Discussion = ...@@ -527,8 +527,25 @@ Discussion =
handleCancelNewPost(this) handleCancelNewPost(this)
$(elem).hide() $(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) $elem = $(elem)
$discussionModule = $elem.parents(".discussion-module") $discussionModule = $elem.parents(".discussion-module")
$discussion = $discussionModule.find(".discussion") $discussion = $discussionModule.find(".discussion")
...@@ -543,7 +560,7 @@ Discussion = ...@@ -543,7 +560,7 @@ Discussion =
Discussion.bindDiscussionEvents($discussion) Discussion.bindDiscussionEvents($discussion)
dataType: 'html' dataType: 'html'
$local(".discussion-search-form").submit (event) -> $local(".search-wrapper-forum > .discussion-search-form").submit (event) ->
event.preventDefault() event.preventDefault()
text = $local(".search-input").val() text = $local(".search-input").val()
isSearchWithinBoard = $local(".discussion-search-within-board").is(":checked") isSearchWithinBoard = $local(".discussion-search-within-board").is(":checked")
...@@ -552,11 +569,16 @@ Discussion = ...@@ -552,11 +569,16 @@ Discussion =
$local(".discussion-new-post").click -> $local(".discussion-new-post").click ->
handleNewPost(this) handleNewPost(this)
$local(".discussion-search").click -> $local(".discussion-search-link").click ->
$local(".new-post-form").submit() 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.find(".thread").each (index, thread) ->
Discussion.initializeContent(thread) Discussion.initializeContent(thread)
......
...@@ -5,14 +5,16 @@ ...@@ -5,14 +5,16 @@
<div class="discussion-title-wrapper"> <div class="discussion-title-wrapper">
<a class="discussion-title" href="javascript:void(0)">Discussion</a> <a class="discussion-title" href="javascript:void(0)">Discussion</a>
</div> </div>
${search_bar} <div class="search-wrapper-forum">
<%include file="_search_bar.html" />
</div>
<div class="search-within"> <div class="search-within">
<input type="checkbox" id="discussion-search-within-board-${discussion_id}" class="discussion-search-within-board" checked/> <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> <label for="discussion-search-within-board-${discussion_id}" class="discussion-search-within-board">Search within board</label>
</div> </div>
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div> <div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
<%include file="_sort.html" />
</div> </div>
<%include file="_sort.html" />
% for thread in threads: % for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor % endfor
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<section class="discussion inline-discussion" _id="${discussion_id}"> <section class="discussion inline-discussion" _id="${discussion_id}">
<div class="discussion-non-content"> <div class="discussion-non-content">
<div class="search-wrapper-inline"> <div class="search-wrapper-inline">
${search_bar} <%include file="_search_bar.html" />
</div> </div>
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div> <div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
<%include file="_sort.html" />
</div> </div>
<%include file="_sort.html" />
% for thread in threads: % for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor % 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"/> <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> </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