diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index ad8d8be22..7678d9cca 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -76,21 +76,13 @@ private def set_watcher(user, watching) @watched.set_watcher(user, watching) - if params[:replace].present? - if params[:replace].is_a? Array - replace_ids = params[:replace] - else - replace_ids = [params[:replace]] - end - else - replace_ids = ['watcher'] - end respond_to do |format| format.html { redirect_to :back } format.js do render(:update) do |page| - replace_ids.each do |replace_id| - page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) + c = watcher_css(@watched) + page.select(".#{c}").each do |item| + page.replace_html item, watcher_link(@watched, user) end end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 2695ce9f6..e0010d834 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,28 +16,18 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module WatchersHelper - - # Valid options - # * :id - the element id - # * :replace - a string or array of element ids that will be - # replaced - def watcher_tag(object, user, options={:replace => 'watcher'}) - id = options[:id] - id ||= options[:replace] if options[:replace].is_a? String - content_tag("span", watcher_link(object, user, options), :id => id) + + def watcher_tag(object, user, options={}) + content_tag("span", watcher_link(object, user), :class => watcher_css(object)) end - # Valid options - # * :replace - a string or array of element ids that will be - # replaced - def watcher_link(object, user, options={:replace => 'watcher'}) + def watcher_link(object, user) return '' unless user && user.logged? && object.respond_to?('watched_by?') watched = object.watched_by?(user) url = {:controller => 'watchers', :action => (watched ? 'unwatch' : 'watch'), :object_type => object.class.to_s.underscore, - :object_id => object.id, - :replace => options[:replace]} + :object_id => object.id} link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), {:url => url}, :href => url_for(url), @@ -45,6 +35,11 @@ module WatchersHelper end + # Returns the css class used to identify watch links for a given +object+ + def watcher_css(object) + "#{object.class.to_s.underscore}-#{object.id}-watcher" + end + # Returns a comma separated list of users watching the given object def watchers_list(object) remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) diff --git a/app/views/issues/_action_menu.rhtml b/app/views/issues/_action_menu.rhtml index 3f4d89e2c..67eec6c78 100644 --- a/app/views/issues/_action_menu.rhtml +++ b/app/views/issues/_action_menu.rhtml @@ -1,8 +1,7 @@