To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / watchers_helper.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (3.22 KB)
| 1 | 909:cbb26bc654de | Chris | # encoding: utf-8
|
|---|---|---|---|
| 2 | #
|
||
| 3 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
| 4 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 5 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 11 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 16 | 0:513646585e45 | Chris | # 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 | |||
| 20 | module WatchersHelper |
||
| 21 | 909:cbb26bc654de | Chris | |
| 22 | 441:cbce1fd3b1b7 | Chris | def watcher_tag(object, user, options={}) |
| 23 | 1295:622f24f53b42 | Chris | ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead." |
| 24 | watcher_link(object, user) |
||
| 25 | 0:513646585e45 | Chris | end
|
| 26 | 909:cbb26bc654de | Chris | |
| 27 | 1295:622f24f53b42 | Chris | def watcher_link(objects, user) |
| 28 | return '' unless user && user.logged? |
||
| 29 | objects = Array.wrap(objects)
|
||
| 30 | 909:cbb26bc654de | Chris | |
| 31 | 1295:622f24f53b42 | Chris | 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 |
||
| 41 | 0:513646585e45 | Chris | end
|
| 42 | 909:cbb26bc654de | Chris | |
| 43 | 441:cbce1fd3b1b7 | Chris | # Returns the css class used to identify watch links for a given +object+
|
| 44 | 1295:622f24f53b42 | Chris | def watcher_css(objects) |
| 45 | objects = Array.wrap(objects)
|
||
| 46 | id = (objects.size == 1 ? objects.first.id : 'bulk') |
||
| 47 | "#{objects.first.class.to_s.underscore}-#{id}-watcher"
|
||
| 48 | 441:cbce1fd3b1b7 | Chris | end
|
| 49 | 909:cbb26bc654de | Chris | |
| 50 | 0:513646585e45 | Chris | # Returns a comma separated list of users watching the given object
|
| 51 | def watchers_list(object) |
||
| 52 | remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) |
||
| 53 | 1115:433d4f72a19b | Chris | content = ''.html_safe
|
| 54 | 0:513646585e45 | Chris | lis = object.watcher_users.collect do |user|
|
| 55 | 1115:433d4f72a19b | Chris | s = ''.html_safe
|
| 56 | s << avatar(user, :size => "16").to_s |
||
| 57 | s << link_to_user(user, :class => 'user') |
||
| 58 | 0:513646585e45 | Chris | if remove_allowed
|
| 59 | url = {:controller => 'watchers',
|
||
| 60 | :action => 'destroy', |
||
| 61 | :object_type => object.class.to_s.underscore,
|
||
| 62 | :object_id => object.id,
|
||
| 63 | :user_id => user}
|
||
| 64 | 1115:433d4f72a19b | Chris | s << ' '
|
| 65 | s << link_to(image_tag('delete.png'), url,
|
||
| 66 | 1295:622f24f53b42 | Chris | :remote => true, :method => 'delete', :class => "delete") |
| 67 | 0:513646585e45 | Chris | end
|
| 68 | 1295:622f24f53b42 | Chris | content << content_tag('li', s, :class => "user-#{user.id}") |
| 69 | 0:513646585e45 | Chris | end
|
| 70 | 1295:622f24f53b42 | Chris | content.present? ? content_tag('ul', content, :class => 'watchers') : content |
| 71 | 1115:433d4f72a19b | Chris | end
|
| 72 | |||
| 73 | def watchers_checkboxes(object, users, checked=nil) |
||
| 74 | users.map do |user|
|
||
| 75 | c = checked.nil? ? object.watched_by?(user) : checked |
||
| 76 | tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil |
||
| 77 | content_tag 'label', "#{tag} #{h(user)}".html_safe, |
||
| 78 | :id => "issue_watcher_user_ids_#{user.id}", |
||
| 79 | :class => "floating" |
||
| 80 | end.join.html_safe
|
||
| 81 | 0:513646585e45 | Chris | end
|
| 82 | end |