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