Skip to content

Commit

Permalink
Fixes dynamic comment state change.
Browse files Browse the repository at this point in the history
Issue #447
  • Loading branch information
Frédéric de Villamil committed Sep 13, 2014
1 parent 6896341 commit 46d2433
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 46 deletions.
15 changes: 7 additions & 8 deletions app/controllers/admin/feedback_controller.rb
Expand Up @@ -88,21 +88,20 @@ def article
def change_state
return unless request.xhr?

feedback = Feedback.find(params[:id])
template = feedback.change_state!
@feedback = Feedback.find(params[:id])
template = @feedback.change_state!

render(:update) do |page|
respond_to do |format|

if params[:context] != 'listing'
@comments = Comment.last_published
page.replace_html('commentList', :partial => 'admin/dashboard/comment')
else
if template == "ham"
page.visual_effect :appear, "feedback_#{feedback.id}"
page.visual_effect :fade, "placeholder_#{feedback.id}"
format.js { render 'ham' }
else
page.visual_effect :appear, "placeholder_#{feedback.id}"
page.visual_effect :fade, "feedback_#{feedback.id}"
end
format.js { render 'spam'}
end
end
end
end
Expand Down
41 changes: 3 additions & 38 deletions app/views/admin/feedback/_feedback.html.erb
@@ -1,42 +1,7 @@
<tr id='feedback_<%= comment.id %>' class='<%= comment.state.to_s.downcase %>'>
<% if comment.state.to_s.downcase == 'spam'%>
<td></td>
<td style='text-align: center'>
<%= avatar_tag(:email => comment.email, :url => comment.url, :size => 48, :class => 'img-circle') %>
<p class='action'><span class='label label-danger'><%= t("admin.feedback.state.#{comment.state}") %></span></p>
</td>
<td colspan=4>
<%= link_to comment.article.title, :controller => 'feedback', :action => 'article', :id => comment.article_id %>
<p>
<small>
<%= t('.by:')%> <%= mail_to h(comment.email), h(comment.author) %>
<%= link_to "(#{h(comment.url)})".html_safe, comment.url unless comment.url.blank? %>
<%= t('.on') %> <%= l(comment.created_at) %>
</small>
</p>
<p>
<small>
<%= t(".this_comment_by_was_flagged_as_spam", author: comment.author, cancel_link: link_to(t('.cancel'), url: {action: 'change_state', id: comment.id, remote: true})) %>
<%= toggle_element "feedback_#{comment.id}" %>
</small>
</p>
</td>
<%= render :partial => 'spam', :locals => { :comment => comment } %>
<% else %>
<td><input class= "feedback_check" type="checkbox" name="feedback_check[<%= comment.id %>]"/></td>
<td style='text-align: center'>
<%= avatar_tag(:email => comment.email, :url => comment.url, :size => 80, :class => 'img-circle') %>
<p class='action'><span class='label <%= comment_class comment.state.to_s.downcase %>'><%= t("admin.feedback.state.#{comment.state}") %></span></p>
</td>
<td>
<%= link_to comment.article.title, :controller => 'feedback', :action => 'article', :id => comment.article_id %>
<p>
<small>
<%= t('.by:')%> <%= mail_to h(comment.email), h(comment.author) %>
<%= link_to "(#{h(comment.url)})".html_safe, comment.url unless comment.url.blank? %>
<%= t('.on') %> <%= l(comment.created_at) %>
</small>
</p>
<%= comment.html(:all) %>
<%= show_feedback_actions comment %>
</td>
<%= render :partial => 'ham', :locals => { :comment => comment } %>
<% end %>
</tr>
17 changes: 17 additions & 0 deletions app/views/admin/feedback/_ham.html.erb
@@ -0,0 +1,17 @@
<td><input class= "feedback_check" type="checkbox" name="feedback_check[<%= comment.id %>]"/></td>
<td style='text-align: center'>
<%= avatar_tag(:email => comment.email, :url => comment.url, :size => 80, :class => 'img-circle') %>
<p class='action'><span class='label <%= comment_class comment.state.to_s.downcase %>'><%= t("admin.feedback.state.#{comment.state}") %></span></p>
</td>
<td>
<%= link_to comment.article.title, :controller => 'feedback', :action => 'article', :id => comment.article_id %>
<p>
<small>
<%= t('.by:')%> <%= mail_to h(comment.email), h(comment.author) %>
<%= link_to "(#{h(comment.url)})".html_safe, comment.url unless comment.url.blank? %>
<%= t('.on') %> <%= l(comment.created_at) %>
</small>
</p>
<%= comment.html(:all) %>
<%= show_feedback_actions comment %>
</td>
21 changes: 21 additions & 0 deletions app/views/admin/feedback/_spam.html.erb
@@ -0,0 +1,21 @@
<td></td>
<td style='text-align: center'>
<%= avatar_tag(:email => comment.email, :url => comment.url, :size => 48, :class => 'img-circle') %>
<p class='action'><span class='label label-danger'><%= t("admin.feedback.state.#{comment.state}") %></span></p>
</td>
<td colspan=4>
<%= link_to comment.article.title, :controller => 'feedback', :action => 'article', :id => comment.article_id %>
<p>
<small>
<%= t('.by:')%> <%= mail_to h(comment.email), h(comment.author) %>
<%= link_to "(#{h(comment.url)})".html_safe, comment.url unless comment.url.blank? %>
<%= t('.on') %> <%= l(comment.created_at) %>
</small>
</p>
<p>
<small>
<%= t(".this_comment_by_was_flagged_as_spam", author: comment.author, cancel_link: link_to(t('.cancel'), url: {action: 'change_state', id: comment.id, remote: true})) %>
<%= toggle_element "feedback_#{comment.id}" %>
</small>
</p>
</td>
1 change: 1 addition & 0 deletions app/views/admin/feedback/ham.js
@@ -0,0 +1 @@
$("#feedback_<%= raw(@feedback.id) %>").html('<%= raw escape_javascript(render(partial: "ham", locals: { comment: @feedback })) %>');
1 change: 1 addition & 0 deletions app/views/admin/feedback/spam.js
@@ -0,0 +1 @@
$("#feedback_<%= raw (@feedback.id) %>").html('<%= raw escape_javascript(render(partial: "spam", locals: { comment: @feedback })) %>');

0 comments on commit 46d2433

Please sign in to comment.