annotate .svn/pristine/4c/4cf77a2b32a1d7fab6c4d61f9bd7b1adc3ae8f61.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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