annotate app/helpers/.svn/text-base/watchers_helper.rb.svn-base @ 507:0c939c159af4 redmine-1.2

Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author Chris Cannam
date Thu, 14 Jul 2011 10:32:19 +0100
parents cbce1fd3b1b7
children
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@441 19
Chris@441 20 def watcher_tag(object, user, options={})
Chris@441 21 content_tag("span", watcher_link(object, user), :class => watcher_css(object))
Chris@0 22 end
Chris@0 23
Chris@441 24 def watcher_link(object, user)
Chris@0 25 return '' unless user && user.logged? && object.respond_to?('watched_by?')
Chris@0 26 watched = object.watched_by?(user)
Chris@0 27 url = {:controller => 'watchers',
Chris@0 28 :action => (watched ? 'unwatch' : 'watch'),
Chris@0 29 :object_type => object.class.to_s.underscore,
Chris@441 30 :object_id => object.id}
Chris@0 31 link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
Chris@0 32 {:url => url},
Chris@0 33 :href => url_for(url),
Chris@0 34 :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
Chris@0 35
Chris@0 36 end
Chris@0 37
Chris@441 38 # Returns the css class used to identify watch links for a given +object+
Chris@441 39 def watcher_css(object)
Chris@441 40 "#{object.class.to_s.underscore}-#{object.id}-watcher"
Chris@441 41 end
Chris@441 42
Chris@0 43 # Returns a comma separated list of users watching the given object
Chris@0 44 def watchers_list(object)
Chris@0 45 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
Chris@0 46 lis = object.watcher_users.collect do |user|
Chris@0 47 s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
Chris@0 48 if remove_allowed
Chris@0 49 url = {:controller => 'watchers',
Chris@0 50 :action => 'destroy',
Chris@0 51 :object_type => object.class.to_s.underscore,
Chris@0 52 :object_id => object.id,
Chris@0 53 :user_id => user}
Chris@0 54 s += ' ' + link_to_remote(image_tag('delete.png'),
Chris@0 55 {:url => url},
Chris@0 56 :href => url_for(url),
Chris@0 57 :style => "vertical-align: middle",
Chris@0 58 :class => "delete")
Chris@0 59 end
Chris@0 60 "<li>#{ s }</li>"
Chris@0 61 end
Chris@0 62 lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"
Chris@0 63 end
Chris@0 64 end