Commit 1f808a1cecb1d2663594a2e95e1b89e2f40a585d

Authored by Victor Costa
1 parent 88070d96

show menu items after the user clicks on menu

app/controllers/public/comment_controller.rb
... ... @@ -160,6 +160,15 @@ class CommentController < ApplicationController
160 160 end
161 161 end
162 162 end
  163 +
  164 + #FIXME make this test
  165 + def check_actions
  166 + comment = profile.comments_received.find(params[:id])
  167 + ids = @plugins.dispatch(:check_comment_actions, comment).collect do |action|
  168 + action.kind_of?(Proc) ? self.instance_eval(&action) : action
  169 + end.flatten.compact
  170 + render :json => {:ids => ids}
  171 + end
163 172  
164 173 protected
165 174  
... ...
app/helpers/comment_helper.rb
... ... @@ -23,8 +23,9 @@ module CommentHelper
23 23 end
24 24  
25 25 def comment_actions(comment)
  26 + url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id)
26 27 links = links_for_comment_actions(comment)
27   - 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?
  28 + content_tag(:li, link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url), :class=> 'vcard') unless links.empty?
28 29 end
29 30  
30 31 private
... ...
lib/noosfero/plugin.rb
... ... @@ -289,6 +289,18 @@ class Noosfero::Plugin
289 289 nil
290 290 end
291 291  
  292 + # This method is called when the user click on comment actions menu.
  293 + # returns = list or lambda block that return ids of enabled menu items for comments
  294 + # example:
  295 + #
  296 + # def check_comment_actions(comment)
  297 + # ['#action1', '#action2']
  298 + # end
  299 + #
  300 + def check_comment_actions(comment)
  301 + []
  302 + end
  303 +
292 304 # -> Adds fields to the signup form
293 305 # returns = lambda block that creates html code
294 306 def signup_extra_contents
... ...
public/javascripts/add-and-join.js
... ... @@ -100,4 +100,24 @@ jQuery(function($) {
100 100 clicked.parent().find(".send-an-email").fadeOut();
101 101 })
102 102 })
  103 +
  104 + $(".comment-trigger").live('click', function(){
  105 + clicked = $(this);
  106 + url = clicked.attr("url");
  107 + $.get(url, function(data){
  108 + ids = [];
  109 + if(data && data.ids) {
  110 + for(var i=0; i<data.ids.length; i++) {
  111 + clicked.parent().find(data.ids[i]).fadeIn();
  112 + ids.push(data.ids[i]);
  113 + }
  114 + }
  115 + clicked.parent().find('.comment-action-extra').each(function() {
  116 + if($.inArray('#'+$(this).attr('id'), ids))
  117 + $(this).fadeOut();
  118 + });
  119 + })
  120 + return false;
  121 + })
  122 +
103 123 });
... ...
test/functional/comment_controller_test.rb
... ... @@ -501,7 +501,7 @@ class CommentControllerTest &lt; ActionController::TestCase
501 501 assert_equal 'Comment edited', Comment.find(comment.id).body
502 502 end
503 503  
504   - should 'not crash on update comment if comment does not exist' do
  504 + should 'not crash on update comment if comment does not exist' do
505 505 login_as profile.identifier
506 506 page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
507 507  
... ... @@ -509,4 +509,18 @@ class CommentControllerTest &lt; ActionController::TestCase
509 509 assert_response 404
510 510 end
511 511  
  512 + should 'returns ids of menu items that has to be displayed' do
  513 + class TestActionPlugin < Noosfero::Plugin
  514 + def check_comment_actions(c)
  515 + ['action1', 'action2']
  516 + end
  517 + end
  518 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestActionPlugin.new])
  519 + login_as profile.identifier
  520 + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
  521 + comment = fast_create(Comment, :body => 'Original comment', :source_id => page.id, :source_type => 'Article')
  522 + xhr :post, :check_actions, :profile => profile.identifier, :id => comment.id
  523 + assert_match /\{\"ids\":\[\"action1\",\"action2\"\]\}/, @response.body
  524 + end
  525 +
512 526 end
... ...