Commit dc107520d7e2d0b06d7e4588f692ce7f60a25db5

Authored by Victor Costa
1 parent e22e8356

adding a menu to display comment actions

app/helpers/application_helper.rb
@@ -30,6 +30,8 @@ module ApplicationHelper @@ -30,6 +30,8 @@ module ApplicationHelper
30 30
31 include AccountHelper 31 include AccountHelper
32 32
  33 + include CommentHelper
  34 +
33 def locale 35 def locale
34 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale 36 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
35 end 37 end
app/helpers/comment_helper.rb
@@ -21,5 +21,44 @@ module CommentHelper @@ -21,5 +21,44 @@ module CommentHelper
21 end 21 end
22 title 22 title
23 end 23 end
  24 +
  25 + #FIXME make this test
  26 + def comment_actions(comment)
  27 + links = links_for_comment_actions(comment)
  28 + content_tag(:li, link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger'), :class=> 'vcard') unless links.empty?
  29 + end
  30 +
  31 + private
  32 +
  33 + def links_for_comment_actions(comment)
  34 + [link_for_report_abuse(comment), link_for_spam(comment), link_for_edit(comment), link_for_remove(comment)].compact
  35 + end
  36 +
  37 + def link_for_report_abuse(comment)
  38 + if comment.author
  39 + report_abuse_link = report_abuse(comment.author, :comment_link, comment)
  40 + {:link => report_abuse_link} if report_abuse_link
  41 + end
  42 + end
  43 +
  44 + def link_for_spam(comment)
  45 + if comment.spam?
  46 + {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')}
  47 + elsif (logged_in? && (user == profile || user.has_permission?(:moderate_comments, profile)))
  48 + {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')}
  49 + end
  50 + end
  51 +
  52 + def link_for_edit(comment)
  53 + if comment.author && comment.author == user
  54 + {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')}
  55 + end
  56 + end
  57 +
  58 + def link_for_remove(comment)
  59 + if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile))
  60 + {:link => link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children')}
  61 + end
  62 + end
24 63
25 end 64 end
app/views/comment/_comment.rhtml
@@ -31,6 +31,21 @@ @@ -31,6 +31,21 @@
31 <% comment_balloon do %> 31 <% comment_balloon do %>
32 32
33 <div class="comment-details"> 33 <div class="comment-details">
  34 + <div class="comment-header">
  35 + <ul>
  36 + <div class="comment-actions">
  37 + <%= comment_actions(comment) %>
  38 + </div>
  39 + </ul>
  40 + <% unless comment.spam? %>
  41 + <%= link_to_function '',
  42 + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id,
  43 + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button',
  44 + :id => 'comment-reply-to-' + comment.id.to_s
  45 + %>
  46 + <% end %>
  47 + </div>
  48 +
34 <div class="comment-created-at"> 49 <div class="comment-created-at">
35 <%= show_time(comment.created_at) %> 50 <%= show_time(comment.created_at) %>
36 </div> 51 </div>
@@ -41,7 +56,7 @@ @@ -41,7 +56,7 @@
41 </div> 56 </div>
42 </div> 57 </div>
43 58
44 - <div class="comment_reply post_comment_box closed"> 59 + <div class="comment_reply post_comment_box closed" id="comment_reply_to_<%= comment.id %>">
45 <% if @comment && @comment.errors.any? && @comment.reply_of_id.to_i == comment.id %> 60 <% if @comment && @comment.errors.any? && @comment.reply_of_id.to_i == comment.id %>
46 <%= error_messages_for :comment %> 61 <%= error_messages_for :comment %>
47 <script type="text/javascript"> 62 <script type="text/javascript">
public/javascripts/application.js
@@ -295,11 +295,17 @@ function toggleSubmenu(trigger, title, link_list) { @@ -295,11 +295,17 @@ function toggleSubmenu(trigger, title, link_list) {
295 content.append('<h4>' + title + '</h4>'); 295 content.append('<h4>' + title + '</h4>');
296 jQuery.each(link_list, function(index, link_hash) { 296 jQuery.each(link_list, function(index, link_hash) {
297 for (label in link_hash) { 297 for (label in link_hash) {
298 - options = "";  
299 - jQuery.each(link_hash[label], function(option, value){  
300 - options += option +'="'+ value + '" ';  
301 - })  
302 - list.append('<li><a '+ options +'>' + label + '</a></li>'); 298 + if(link_hash[label]!=null) {
  299 + if(label=='link' && jQuery.type(link_hash[label])=="string") {
  300 + list.append('<li>' + link_hash[label] + '</li>');
  301 + } else {
  302 + options = "";
  303 + jQuery.each(link_hash[label], function(option, value){
  304 + options += option +'="'+ value + '" ';
  305 + })
  306 + list.append('<li><a '+ options +'>' + label + '</a></li>');
  307 + }
  308 + }
303 } 309 }
304 }); 310 });
305 content.append(list); 311 content.append(list);
@@ -323,9 +329,9 @@ function hideAllSubmenus() { @@ -323,9 +329,9 @@ function hideAllSubmenus() {
323 // Hide visible ballons when clicked outside them 329 // Hide visible ballons when clicked outside them
324 jQuery(document).ready(function() { 330 jQuery(document).ready(function() {
325 jQuery('body').live('click', function() { hideAllSubmenus(); }); 331 jQuery('body').live('click', function() { hideAllSubmenus(); });
326 - jQuery('.menu-submenu-trigger').click(function(e) { e.stopPropagation(); });  
327 - jQuery('.simplemenu-trigger').click(function(e) { e.stopPropagation(); });  
328 - jQuery('#chat-online-users').click(function(e) { e.stopPropagation(); }); 332 + jQuery('.menu-submenu-trigger').live('click', function(e) { e.stopPropagation(); });
  333 + jQuery('.simplemenu-trigger').live('click', function(e) { e.stopPropagation(); });
  334 + jQuery('#chat-online-users').live('click', function(e) { e.stopPropagation(); });
329 }); 335 });
330 336
331 function input_javascript_ordering_stuff() { 337 function input_javascript_ordering_stuff() {
@@ -689,8 +695,8 @@ jQuery(function($) { @@ -689,8 +695,8 @@ jQuery(function($) {
689 }); 695 });
690 696
691 function add_comment_reply_form(button, comment_id) { 697 function add_comment_reply_form(button, comment_id) {
692 - var container = jQuery(button).parents('.comment_reply');  
693 - 698 + //var container = jQuery(button).parents('.comment_reply');
  699 + var container = jQuery('#comment_reply_to_'+comment_id);
694 var f = container.find('.comment_form'); 700 var f = container.find('.comment_form');
695 if (f.length == 0) { 701 if (f.length == 0) {
696 comments_div = jQuery(button).parents('.comments'); 702 comments_div = jQuery(button).parents('.comments');
public/stylesheets/application.css
@@ -1755,13 +1755,31 @@ a.button.disabled, input.disabled { @@ -1755,13 +1755,31 @@ a.button.disabled, input.disabled {
1755 #content .profile-list-block ul { 1755 #content .profile-list-block ul {
1756 width: 200px; 1756 width: 200px;
1757 } 1757 }
1758 -#content .common-profile-list-block li {  
1759 - margin: 0px; 1758 +#content .comment-header .comment-actions-reply {
  1759 + float: right;
  1760 + background-image: url(/designs/icons/tango/Tango/16x16/actions/go-jump.png);
  1761 + height: 12px;
  1762 +}
  1763 +#content .comment-header ul {
  1764 + float: right;
  1765 +}
  1766 +#content .comment-actions .menu-submenu-header, #content .comment-actions .menu-submenu-footer, #content .comment-actions .menu-submenu h4 {
  1767 + display: none;
  1768 +}
  1769 +#content .comment-actions .menu-submenu ul {
  1770 + border: 1px solid #888a85;
  1771 + background-color: #efefef;
  1772 + padding-right: 2px;
  1773 + height: auto;
  1774 + display: block;
  1775 +}
  1776 +#content .common-profile-list-block li, #content .comment-actions li {
  1777 + margin: 0px !important;
1760 padding: 0px; 1778 padding: 0px;
1761 list-style: none; 1779 list-style: none;
1762 position: relative; 1780 position: relative;
1763 } 1781 }
1764 -.common-profile-list-block .vcard a { 1782 +.common-profile-list-block .vcard a, .comment-actions .vcard a {
1765 display: block; 1783 display: block;
1766 height: 112px; 1784 height: 112px;
1767 max-height: 112px; 1785 max-height: 112px;
@@ -1772,7 +1790,7 @@ a.button.disabled, input.disabled { @@ -1772,7 +1790,7 @@ a.button.disabled, input.disabled {
1772 text-align: center; 1790 text-align: center;
1773 overflow: hidden; 1791 overflow: hidden;
1774 font-size: 11px; 1792 font-size: 11px;
1775 - text-decoration: none; 1793 + text-decoration: none !important;
1776 color: #000; 1794 color: #000;
1777 position: relative; 1795 position: relative;
1778 cursor: pointer; /* work arround bug for MSIE */ 1796 cursor: pointer; /* work arround bug for MSIE */
@@ -4458,11 +4476,17 @@ h1#agenda-title { @@ -4458,11 +4476,17 @@ h1#agenda-title {
4458 } 4476 }
4459 /* Profile balloon */ 4477 /* Profile balloon */
4460 4478
4461 -.common-profile-list-block .vcard { 4479 +.common-profile-list-block .vcard, .comment-actions .vcard {
4462 position: relative !important; 4480 position: relative !important;
4463 float: left; 4481 float: left;
4464 } 4482 }
4465 -.common-profile-list-block .vcard .menu-submenu-trigger, .menu-submenu-trigger { 4483 +#content .comment-actions .vcard {
  4484 + padding-right: 20px;
  4485 +}
  4486 +#content .comment-actions .vcard .menu-submenu-trigger {
  4487 + display: block;
  4488 +}
  4489 +.common-profile-list-block .vcard .menu-submenu-trigger, .menu-submenu-trigger, .comment-actions .vcard .menu-submenu-trigger {
4466 display: none; 4490 display: none;
4467 width: 16px; 4491 width: 16px;
4468 height: 16px; 4492 height: 16px;
@@ -4476,7 +4500,7 @@ h1#agenda-title { @@ -4476,7 +4500,7 @@ h1#agenda-title {
4476 -moz-border-radius: 5px; 4500 -moz-border-radius: 5px;
4477 -webkit-border-radius: 5px; 4501 -webkit-border-radius: 5px;
4478 } 4502 }
4479 -.common-profile-list-block .vcard .menu-submenu-trigger:hover, .menu-submenu-trigger:hover { 4503 +.common-profile-list-block .vcard .menu-submenu-trigger:hover, .menu-submenu-trigger:hover, .comment-actions .vcard .menu-submenu-trigger:hover {
4480 background: #fff url(/images/top-arrow.png) center center no-repeat; 4504 background: #fff url(/images/top-arrow.png) center center no-repeat;
4481 border: 1px solid #ccc; 4505 border: 1px solid #ccc;
4482 } 4506 }
@@ -4495,6 +4519,10 @@ h1#agenda-title { @@ -4495,6 +4519,10 @@ h1#agenda-title {
4495 padding: 0; 4519 padding: 0;
4496 text-align: left; 4520 text-align: left;
4497 } 4521 }
  4522 +.comment-details .menu-submenu {
  4523 + bottom: 0px;
  4524 + right: -134px;
  4525 +}
4498 .box-2 .menu-submenu, .box-3 .menu-submenu { 4526 .box-2 .menu-submenu, .box-3 .menu-submenu {
4499 bottom: 78px; 4527 bottom: 78px;
4500 right: -44px; 4528 right: -44px;
@@ -4529,7 +4557,7 @@ h1#agenda-title { @@ -4529,7 +4557,7 @@ h1#agenda-title {
4529 .msie7 #search-results .menu-submenu-trigger { 4557 .msie7 #search-results .menu-submenu-trigger {
4530 width: 20px !important; 4558 width: 20px !important;
4531 } 4559 }
4532 -.common-profile-list-block .vcard .menu-submenu a { 4560 +.common-profile-list-block .vcard .menu-submenu a, .comment-actions .vcard .menu-submenu a {
4533 float: none; 4561 float: none;
4534 display: block; 4562 display: block;
4535 height: auto; 4563 height: auto;