Mercurial > hg > soundsoftware-site
comparison app/helpers/watchers_helper.rb @ 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 |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2012 Jean-Philippe Lang | 4 # Copyright (C) 2006-2013 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 |
20 module WatchersHelper | 20 module WatchersHelper |
21 | 21 |
22 def watcher_tag(object, user, options={}) | 22 def watcher_tag(object, user, options={}) |
23 content_tag("span", watcher_link(object, user), :class => watcher_css(object)) | 23 ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead." |
24 watcher_link(object, user) | |
24 end | 25 end |
25 | 26 |
26 def watcher_link(object, user) | 27 def watcher_link(objects, user) |
27 return '' unless user && user.logged? && object.respond_to?('watched_by?') | 28 return '' unless user && user.logged? |
28 watched = object.watched_by?(user) | 29 objects = Array.wrap(objects) |
29 url = {:controller => 'watchers', | |
30 :action => (watched ? 'unwatch' : 'watch'), | |
31 :object_type => object.class.to_s.underscore, | |
32 :object_id => object.id} | |
33 link_to((watched ? l(:button_unwatch) : l(:button_watch)), url, | |
34 :remote => true, :method => 'post', :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off')) | |
35 | 30 |
31 watched = objects.any? {|object| object.watched_by?(user)} | |
32 css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ') | |
33 text = watched ? l(:button_unwatch) : l(:button_watch) | |
34 url = watch_path( | |
35 :object_type => objects.first.class.to_s.underscore, | |
36 :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) | |
37 ) | |
38 method = watched ? 'delete' : 'post' | |
39 | |
40 link_to text, url, :remote => true, :method => method, :class => css | |
36 end | 41 end |
37 | 42 |
38 # Returns the css class used to identify watch links for a given +object+ | 43 # Returns the css class used to identify watch links for a given +object+ |
39 def watcher_css(object) | 44 def watcher_css(objects) |
40 "#{object.class.to_s.underscore}-#{object.id}-watcher" | 45 objects = Array.wrap(objects) |
46 id = (objects.size == 1 ? objects.first.id : 'bulk') | |
47 "#{objects.first.class.to_s.underscore}-#{id}-watcher" | |
41 end | 48 end |
42 | 49 |
43 # Returns a comma separated list of users watching the given object | 50 # Returns a comma separated list of users watching the given object |
44 def watchers_list(object) | 51 def watchers_list(object) |
45 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) | 52 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) |
54 :object_type => object.class.to_s.underscore, | 61 :object_type => object.class.to_s.underscore, |
55 :object_id => object.id, | 62 :object_id => object.id, |
56 :user_id => user} | 63 :user_id => user} |
57 s << ' ' | 64 s << ' ' |
58 s << link_to(image_tag('delete.png'), url, | 65 s << link_to(image_tag('delete.png'), url, |
59 :remote => true, :method => 'post', :style => "vertical-align: middle", :class => "delete") | 66 :remote => true, :method => 'delete', :class => "delete") |
60 end | 67 end |
61 content << content_tag('li', s) | 68 content << content_tag('li', s, :class => "user-#{user.id}") |
62 end | 69 end |
63 content.present? ? content_tag('ul', content) : content | 70 content.present? ? content_tag('ul', content, :class => 'watchers') : content |
64 end | 71 end |
65 | 72 |
66 def watchers_checkboxes(object, users, checked=nil) | 73 def watchers_checkboxes(object, users, checked=nil) |
67 users.map do |user| | 74 users.map do |user| |
68 c = checked.nil? ? object.watched_by?(user) : checked | 75 c = checked.nil? ? object.watched_by?(user) : checked |