Chris@909: # encoding: utf-8 Chris@909: # Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: module WatchersHelper Chris@909: Chris@909: def watcher_tag(object, user, options={}) Chris@909: content_tag("span", watcher_link(object, user), :class => watcher_css(object)) Chris@909: end Chris@909: Chris@909: def watcher_link(object, user) Chris@909: return '' unless user && user.logged? && object.respond_to?('watched_by?') Chris@909: watched = object.watched_by?(user) Chris@909: url = {:controller => 'watchers', Chris@909: :action => (watched ? 'unwatch' : 'watch'), Chris@909: :object_type => object.class.to_s.underscore, Chris@909: :object_id => object.id} Chris@909: link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), Chris@909: {:url => url}, Chris@909: :href => url_for(url), Chris@909: :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off')) Chris@909: Chris@909: end Chris@909: Chris@909: # Returns the css class used to identify watch links for a given +object+ Chris@909: def watcher_css(object) Chris@909: "#{object.class.to_s.underscore}-#{object.id}-watcher" Chris@909: end Chris@909: Chris@909: # Returns a comma separated list of users watching the given object Chris@909: def watchers_list(object) Chris@909: remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) Chris@909: lis = object.watcher_users.collect do |user| Chris@909: s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s Chris@909: if remove_allowed Chris@909: url = {:controller => 'watchers', Chris@909: :action => 'destroy', Chris@909: :object_type => object.class.to_s.underscore, Chris@909: :object_id => object.id, Chris@909: :user_id => user} Chris@909: s += ' ' + link_to_remote(image_tag('delete.png'), Chris@909: {:url => url}, Chris@909: :href => url_for(url), Chris@909: :style => "vertical-align: middle", Chris@909: :class => "delete") Chris@909: end Chris@909: "