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 @ 1534:b31caaed9d4d

History | View | Annotate | Download (3.24 KB)

1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2014  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

    
20
module WatchersHelper
21

    
22
  def watcher_tag(object, user, options={})
23
    ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
24
    watcher_link(object, user)
25
  end
26

    
27
  def watcher_link(objects, user)
28
    return '' unless user && user.logged?
29
    objects = Array.wrap(objects)
30
    return '' unless objects.any?
31

    
32
    watched = Watcher.any_watched?(objects, user)
33
    css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
34
    text = watched ? l(:button_unwatch) : l(:button_watch)
35
    url = watch_path(
36
      :object_type => objects.first.class.to_s.underscore,
37
      :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
38
    )
39
    method = watched ? 'delete' : 'post'
40

    
41
    link_to text, url, :remote => true, :method => method, :class => css
42
  end
43

    
44
  # Returns the css class used to identify watch links for a given +object+
45
  def watcher_css(objects)
46
    objects = Array.wrap(objects)
47
    id = (objects.size == 1 ? objects.first.id : 'bulk')
48
    "#{objects.first.class.to_s.underscore}-#{id}-watcher"
49
  end
50

    
51
  # Returns a comma separated list of users watching the given object
52
  def watchers_list(object)
53
    remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
54
    content = ''.html_safe
55
    lis = object.watcher_users.collect do |user|
56
      s = ''.html_safe
57
      s << avatar(user, :size => "16").to_s
58
      s << link_to_user(user, :class => 'user')
59
      if remove_allowed
60
        url = {:controller => 'watchers',
61
               :action => 'destroy',
62
               :object_type => object.class.to_s.underscore,
63
               :object_id => object.id,
64
               :user_id => user}
65
        s << ' '
66
        s << link_to(image_tag('delete.png'), url,
67
                     :remote => true, :method => 'delete', :class => "delete")
68
      end
69
      content << content_tag('li', s, :class => "user-#{user.id}")
70
    end
71
    content.present? ? content_tag('ul', content, :class => 'watchers') : content
72
  end
73

    
74
  def watchers_checkboxes(object, users, checked=nil)
75
    users.map do |user|
76
      c = checked.nil? ? object.watched_by?(user) : checked
77
      tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
78
      content_tag 'label', "#{tag} #{h(user)}".html_safe,
79
                  :id => "issue_watcher_user_ids_#{user.id}",
80
                  :class => "floating"
81
    end.join.html_safe
82
  end
83
end