Commit fd1e91ae by Rocky Duan

display show comments button

parent 1e7e2f25
...@@ -16,7 +16,6 @@ $ -> ...@@ -16,7 +16,6 @@ $ ->
Discussion.initializeDiscussion(discussion) Discussion.initializeDiscussion(discussion)
Discussion.bindDiscussionEvents(discussion) Discussion.bindDiscussionEvents(discussion)
generateLocal = (elem) -> generateLocal = (elem) ->
(selector) -> $(elem).find(selector) (selector) -> $(elem).find(selector)
...@@ -104,6 +103,14 @@ Discussion = ...@@ -104,6 +103,14 @@ Discussion =
retrieve_single_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" retrieve_single_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}"
}[name] }[name]
safeAjax: (params) ->
$elem = params.$elem
if $elem.attr("disabled")
return
$elem.attr("disabled", "disabled")
$.ajax(params).always ->
$elem.removeAttr("disabled")
handleAnchorAndReload: (response) -> handleAnchorAndReload: (response) ->
#window.location = window.location.pathname + "#" + response['id'] #window.location = window.location.pathname + "#" + response['id']
window.location.reload() window.location.reload()
...@@ -113,13 +120,10 @@ Discussion = ...@@ -113,13 +120,10 @@ Discussion =
$local = generateLocal($discussionModule) $local = generateLocal($discussionModule)
handleShowDiscussion = (elem) -> handleShowDiscussion = (elem) ->
$elem = $(elem) $elem = $(elem)
if $elem.attr("disabled")
return
if not $local("section.discussion").length if not $local("section.discussion").length
$elem.attr("disabled", "disabled")
discussion_id = $elem.attr("discussion_id") discussion_id = $elem.attr("discussion_id")
url = Discussion.urlFor 'retrieve_discussion', discussion_id url = Discussion.urlFor 'retrieve_discussion', discussion_id
$.ajax( Discussion.safeAjax
url: url url: url
method: "GET" method: "GET"
success: (data, textStatus, xhr) -> success: (data, textStatus, xhr) ->
...@@ -131,14 +135,12 @@ Discussion = ...@@ -131,14 +135,12 @@ Discussion =
$elem.unbind('click').click -> $elem.unbind('click').click ->
handleHideDiscussion(this) handleHideDiscussion(this)
dataType: 'html' dataType: 'html'
).always ->
$elem.removeAttr("disabled")
else else
$local("section.discussion").show() $local("section.discussion").show()
$elem.html("Hide Discussion") $elem.html("Hide Discussion")
$elem.unbind('click').click -> $elem.unbind('click').click ->
handleHideDiscussion(this) handleHideDiscussion(this)
handleHideDiscussion = (elem) -> handleHideDiscussion = (elem) ->
$local("section.discussion").hide() $local("section.discussion").hide()
$elem = $(elem) $elem = $(elem)
...@@ -381,25 +383,32 @@ Discussion = ...@@ -381,25 +383,32 @@ Discussion =
, 'json' , 'json'
handleHideSingleThread = (elem) -> handleHideSingleThread = (elem) ->
$elem = $(elem) $threadTitle = $local(".thread-title")
$showComments = $local(".discussion-show-comments")
$content.children(".comments").hide() $content.children(".comments").hide()
$elem.unbind('click').click -> $threadTitle.unbind('click').click handleShowSingleThread
handleShowSingleThread(this) $showComments.unbind('click').click handleShowSingleThread
prevHtml = $showComments.html()
$showComments.html prevHtml.replace "Hide", "Show"
handleShowSingleThread = ->
$threadTitle = $local(".thread-title")
$showComments = $local(".discussion-show-comments")
rebindHideEvents = ->
$threadTitle.unbind('click').click handleHideSingleThread
$showComments.unbind('click').click handleHideSingleThread
prevHtml = $showComments.html()
$showComments.html prevHtml.replace "Show", "Hide"
handleShowSingleThread = (elem) ->
$elem = $(elem)
if $elem.attr("disabled")
return
if $content.children(".comments").length if $content.children(".comments").length
$content.children(".comments").show() $content.children(".comments").show()
$elem.unbind('click').click -> rebindHideEvents()
handleHideSingleThread(this)
else else
$elem.attr("disabled", "disabled") discussion_id = $threadTitle.parents(".discussion").attr("_id")
discussion_id = $elem.parents(".discussion").attr("_id")
url = Discussion.urlFor('retrieve_single_thread', discussion_id, id) url = Discussion.urlFor('retrieve_single_thread', discussion_id, id)
console.log url Discussion.safeAjax
$.ajax( $elem: $.merge($threadTitle, $showComments)
url: url url: url
method: "GET" method: "GET"
success: (response, textStatus) -> success: (response, textStatus) ->
...@@ -412,15 +421,12 @@ Discussion = ...@@ -412,15 +421,12 @@ Discussion =
$content.find(".comment").each (index, comment) -> $content.find(".comment").each (index, comment) ->
Discussion.initializeContent(comment) Discussion.initializeContent(comment)
Discussion.bindContentEvents(comment) Discussion.bindContentEvents(comment)
$elem.unbind('click').click -> rebindHideEvents()
handleHideSingleThread(this)
dataType: 'json' dataType: 'json'
).always ->
$elem.removeAttr("disabled")
$local(".thread-title").click -> $local(".thread-title").click handleShowSingleThread
handleShowSingleThread(this) $local(".discussion-show-comments").click handleShowSingleThread
$local(".discussion-reply").click -> $local(".discussion-reply").click ->
handleShowSingleThread($local(".thread-title")) handleShowSingleThread($local(".thread-title"))
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
user No.${content['user_id']} user No.${content['user_id']}
% endif % endif
% if content.get('comments_count', -1) >= 0: % if content.get('comments_count', -1) >= 0:
, ${content['comments_count']} comment(s) , <a href="javascript:void(0)" class="discussion-show-comments"> Show ${content['comments_count']} comment(s)</a>
% endif % endif
</%def> </%def>
......
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