annotate .svn/pristine/b5/b5853b637c67cfc0aed37f236eb8fa380a6714c9.svn-base @ 1296:038ba2d95de8 redmine-2.2

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