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 3.1KB

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