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