diff --git a/app/controllers/public/comment_controller.rb b/app/controllers/public/comment_controller.rb index 5cf52dd..a983746 100644 --- a/app/controllers/public/comment_controller.rb +++ b/app/controllers/public/comment_controller.rb @@ -160,6 +160,15 @@ class CommentController < ApplicationController end end end + + #FIXME make this test + def check_actions + comment = profile.comments_received.find(params[:id]) + ids = @plugins.dispatch(:check_comment_actions, comment).collect do |action| + action.kind_of?(Proc) ? self.instance_eval(&action) : action + end.flatten.compact + render :json => {:ids => ids} + end protected diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index b9a909a..aee6300 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -23,8 +23,9 @@ module CommentHelper end def comment_actions(comment) + url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id) links = links_for_comment_actions(comment) - 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? + 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? end private diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index 83e408b..28a87a1 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -289,6 +289,18 @@ class Noosfero::Plugin nil end + # This method is called when the user click on comment actions menu. + # returns = list or lambda block that return ids of enabled menu items for comments + # example: + # + # def check_comment_actions(comment) + # ['#action1', '#action2'] + # end + # + def check_comment_actions(comment) + [] + end + # -> Adds fields to the signup form # returns = lambda block that creates html code def signup_extra_contents diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js index 9055491..db5a4b9 100644 --- a/public/javascripts/add-and-join.js +++ b/public/javascripts/add-and-join.js @@ -100,4 +100,24 @@ jQuery(function($) { clicked.parent().find(".send-an-email").fadeOut(); }) }) + + $(".comment-trigger").live('click', function(){ + clicked = $(this); + url = clicked.attr("url"); + $.get(url, function(data){ + ids = []; + if(data && data.ids) { + for(var i=0; i 'myarticle', :body => 'the body of the text') @@ -509,4 +509,18 @@ class CommentControllerTest < ActionController::TestCase assert_response 404 end + should 'returns ids of menu items that has to be displayed' do + class TestActionPlugin < Noosfero::Plugin + def check_comment_actions(c) + ['action1', 'action2'] + end + end + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestActionPlugin.new]) + login_as profile.identifier + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') + comment = fast_create(Comment, :body => 'Original comment', :source_id => page.id, :source_type => 'Article') + xhr :post, :check_actions, :profile => profile.identifier, :id => comment.id + assert_match /\{\"ids\":\[\"action1\",\"action2\"\]\}/, @response.body + end + end -- libgit2 0.21.2