1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # * :id - the element id
22 # * :replace - a string or array of element ids that will be
24 def watcher_tag(object, user, options={:replace => 'watcher'})
26 id ||= options[:replace] if options[:replace].is_a? String
27 content_tag("span", watcher_link(object, user, options), :id => id)
31 # * :replace - a string or array of element ids that will be
33 def watcher_link(object, user, options={:replace => 'watcher'})
34 return '' unless user && user.logged? && object.respond_to?('watched_by?')
35 watched = object.watched_by?(user)
36 url = {:controller => 'watchers',
37 :action => (watched ? 'unwatch' : 'watch'),
38 :object_type => object.class.to_s.underscore,
39 :object_id => object.id,
40 :replace => options[:replace]}
41 link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
43 :href => url_for(url),
44 :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
48 # Returns a comma separated list of users watching the given object
49 def watchers_list(object)
50 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
51 lis = object.watcher_users.collect do |user|
52 s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
54 url = {:controller => 'watchers',
56 :object_type => object.class.to_s.underscore,
57 :object_id => object.id,
59 s += ' ' + link_to_remote(image_tag('delete.png'),
61 :href => url_for(url),
62 :style => "vertical-align: middle",
67 lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"