To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / watchers_helper.rb @ 823:73057b65abcb

History | View | Annotate | Download (2.63 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
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.
8
# 
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.
13
# 
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.
17

    
18
module WatchersHelper
19
  
20
  def watcher_tag(object, user, options={})
21
    content_tag("span", watcher_link(object, user), :class => watcher_css(object))
22
  end
23
  
24
  def watcher_link(object, user)
25
    return '' unless user && user.logged? && object.respond_to?('watched_by?')
26
    watched = object.watched_by?(user)
27
    url = {:controller => 'watchers',
28
           :action => (watched ? 'unwatch' : 'watch'),
29
           :object_type => object.class.to_s.underscore,
30
           :object_id => object.id}
31
    link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
32
                   {:url => url},
33
                   :href => url_for(url),
34
                   :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
35
  
36
  end
37
  
38
  # Returns the css class used to identify watch links for a given +object+
39
  def watcher_css(object)
40
    "#{object.class.to_s.underscore}-#{object.id}-watcher"
41
  end
42
  
43
  # Returns a comma separated list of users watching the given object
44
  def watchers_list(object)
45
    remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
46
    lis = object.watcher_users.collect do |user|
47
      s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
48
      if remove_allowed
49
        url = {:controller => 'watchers',
50
               :action => 'destroy',
51
               :object_type => object.class.to_s.underscore,
52
               :object_id => object.id,
53
               :user_id => user}
54
        s += ' ' + link_to_remote(image_tag('delete.png'),
55
                                  {:url => url},
56
                                  :href => url_for(url),
57
                                  :style => "vertical-align: middle",
58
                                  :class => "delete")
59
      end
60
      "<li>#{ s }</li>"
61
    end
62
    lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"
63
  end
64
end