annotate app/helpers/watchers_helper.rb @ 929:5f33065ddc4b redmine-1.3

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