annotate .svn/pristine/58/58b9e1838c5a7e00090791cde1a148c4ef4ea8e1.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # encoding: utf-8
Chris@1295 2 #
Chris@1295 3 # Redmine - project management software
Chris@1295 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 5 #
Chris@1295 6 # This program is free software; you can redistribute it and/or
Chris@1295 7 # modify it under the terms of the GNU General Public License
Chris@1295 8 # as published by the Free Software Foundation; either version 2
Chris@1295 9 # of the License, or (at your option) any later version.
Chris@1295 10 #
Chris@1295 11 # This program is distributed in the hope that it will be useful,
Chris@1295 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 14 # GNU General Public License for more details.
Chris@1295 15 #
Chris@1295 16 # You should have received a copy of the GNU General Public License
Chris@1295 17 # along with this program; if not, write to the Free Software
Chris@1295 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 19
Chris@1295 20 module WatchersHelper
Chris@1295 21
Chris@1295 22 def watcher_tag(object, user, options={})
Chris@1295 23 ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
Chris@1295 24 watcher_link(object, user)
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def watcher_link(objects, user)
Chris@1295 28 return '' unless user && user.logged?
Chris@1295 29 objects = Array.wrap(objects)
Chris@1295 30
Chris@1295 31 watched = objects.any? {|object| object.watched_by?(user)}
Chris@1295 32 css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
Chris@1295 33 text = watched ? l(:button_unwatch) : l(:button_watch)
Chris@1295 34 url = watch_path(
Chris@1295 35 :object_type => objects.first.class.to_s.underscore,
Chris@1295 36 :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
Chris@1295 37 )
Chris@1295 38 method = watched ? 'delete' : 'post'
Chris@1295 39
Chris@1295 40 link_to text, url, :remote => true, :method => method, :class => css
Chris@1295 41 end
Chris@1295 42
Chris@1295 43 # Returns the css class used to identify watch links for a given +object+
Chris@1295 44 def watcher_css(objects)
Chris@1295 45 objects = Array.wrap(objects)
Chris@1295 46 id = (objects.size == 1 ? objects.first.id : 'bulk')
Chris@1295 47 "#{objects.first.class.to_s.underscore}-#{id}-watcher"
Chris@1295 48 end
Chris@1295 49
Chris@1295 50 # Returns a comma separated list of users watching the given object
Chris@1295 51 def watchers_list(object)
Chris@1295 52 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
Chris@1295 53 content = ''.html_safe
Chris@1295 54 lis = object.watcher_users.collect do |user|
Chris@1295 55 s = ''.html_safe
Chris@1295 56 s << avatar(user, :size => "16").to_s
Chris@1295 57 s << link_to_user(user, :class => 'user')
Chris@1295 58 if remove_allowed
Chris@1295 59 url = {:controller => 'watchers',
Chris@1295 60 :action => 'destroy',
Chris@1295 61 :object_type => object.class.to_s.underscore,
Chris@1295 62 :object_id => object.id,
Chris@1295 63 :user_id => user}
Chris@1295 64 s << ' '
Chris@1295 65 s << link_to(image_tag('delete.png'), url,
Chris@1295 66 :remote => true, :method => 'delete', :class => "delete")
Chris@1295 67 end
Chris@1295 68 content << content_tag('li', s, :class => "user-#{user.id}")
Chris@1295 69 end
Chris@1295 70 content.present? ? content_tag('ul', content, :class => 'watchers') : content
Chris@1295 71 end
Chris@1295 72
Chris@1295 73 def watchers_checkboxes(object, users, checked=nil)
Chris@1295 74 users.map do |user|
Chris@1295 75 c = checked.nil? ? object.watched_by?(user) : checked
Chris@1295 76 tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
Chris@1295 77 content_tag 'label', "#{tag} #{h(user)}".html_safe,
Chris@1295 78 :id => "issue_watcher_user_ids_#{user.id}",
Chris@1295 79 :class => "floating"
Chris@1295 80 end.join.html_safe
Chris@1295 81 end
Chris@1295 82 end