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