You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

watchers_helper.rb 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. module WatchersHelper
  18. def watcher_tag(object, user, options={})
  19. content_tag("span", watcher_link(object, user), :class => watcher_css(object))
  20. end
  21. def watcher_link(object, user)
  22. return '' unless user && user.logged? && object.respond_to?('watched_by?')
  23. watched = object.watched_by?(user)
  24. url = {:controller => 'watchers',
  25. :action => (watched ? 'unwatch' : 'watch'),
  26. :object_type => object.class.to_s.underscore,
  27. :object_id => object.id}
  28. link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
  29. {:url => url},
  30. :href => url_for(url),
  31. :class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
  32. end
  33. # Returns the css class used to identify watch links for a given +object+
  34. def watcher_css(object)
  35. "#{object.class.to_s.underscore}-#{object.id}-watcher"
  36. end
  37. # Returns a comma separated list of users watching the given object
  38. def watchers_list(object)
  39. remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
  40. lis = object.watcher_users.collect do |user|
  41. s = avatar(user, :size => "16").to_s + link_to_user(user, :class => 'user').to_s
  42. if remove_allowed
  43. url = {:controller => 'watchers',
  44. :action => 'destroy',
  45. :object_type => object.class.to_s.underscore,
  46. :object_id => object.id,
  47. :user_id => user}
  48. s += ' ' + link_to_remote(image_tag('delete.png'),
  49. {:url => url},
  50. :href => url_for(url),
  51. :style => "vertical-align: middle",
  52. :class => "delete")
  53. end
  54. "<li>#{ s }</li>"
  55. end
  56. lis.empty? ? "" : "<ul>#{ lis.join("\n") }</ul>"
  57. end
  58. end