comparison app/helpers/.svn/text-base/watchers_helper.rb.svn-base @ 514:7eba09d624db live

Merge
author Chris Cannam
date Thu, 14 Jul 2011 10:50:53 +0100
parents cbce1fd3b1b7
children
comparison
equal deleted inserted replaced
512:b9aebdd7dd40 514:7eba09d624db
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 module WatchersHelper 18 module WatchersHelper
19 19
20 # Valid options 20 def watcher_tag(object, user, options={})
21 # * :id - the element id 21 content_tag("span", watcher_link(object, user), :class => watcher_css(object))
22 # * :replace - a string or array of element ids that will be
23 # replaced
24 def watcher_tag(object, user, options={:replace => 'watcher'})
25 id = options[:id]
26 id ||= options[:replace] if options[:replace].is_a? String
27 content_tag("span", watcher_link(object, user, options), :id => id)
28 end 22 end
29 23
30 # Valid options 24 def watcher_link(object, user)
31 # * :replace - a string or array of element ids that will be
32 # replaced
33 def watcher_link(object, user, options={:replace => 'watcher'})
34 return '' unless user && user.logged? && object.respond_to?('watched_by?') 25 return '' unless user && user.logged? && object.respond_to?('watched_by?')
35 watched = object.watched_by?(user) 26 watched = object.watched_by?(user)
36 url = {:controller => 'watchers', 27 url = {:controller => 'watchers',
37 :action => (watched ? 'unwatch' : 'watch'), 28 :action => (watched ? 'unwatch' : 'watch'),
38 :object_type => object.class.to_s.underscore, 29 :object_type => object.class.to_s.underscore,
39 :object_id => object.id, 30 :object_id => object.id}
40 :replace => options[:replace]}
41 link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), 31 link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
42 {:url => url}, 32 {:url => url},
43 :href => url_for(url), 33 :href => url_for(url),
44 :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off')) 34 :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
45 35
36 end
37
38 # Returns the css class used to identify watch links for a given +object+
39 def watcher_css(object)
40 "#{object.class.to_s.underscore}-#{object.id}-watcher"
46 end 41 end
47 42
48 # Returns a comma separated list of users watching the given object 43 # Returns a comma separated list of users watching the given object
49 def watchers_list(object) 44 def watchers_list(object)
50 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) 45 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)