@@ -1,134 +1,134 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
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 | class WatchersController < ApplicationController |
|
18 | class WatchersController < ApplicationController | |
19 | before_filter :find_project |
|
19 | before_filter :find_project | |
20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] |
|
20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] | |
21 | before_filter :authorize, :only => [:new, :destroy] |
|
21 | before_filter :authorize, :only => [:new, :destroy] | |
22 |
|
22 | |||
23 | def watch |
|
23 | def watch | |
24 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) |
|
24 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) | |
25 | render_403 |
|
25 | render_403 | |
26 | else |
|
26 | else | |
27 | set_watcher(User.current, true) |
|
27 | set_watcher(User.current, true) | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def unwatch |
|
31 | def unwatch | |
32 | set_watcher(User.current, false) |
|
32 | set_watcher(User.current, false) | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def new |
|
35 | def new | |
36 | respond_to do |format| |
|
36 | respond_to do |format| | |
37 | format.js do |
|
37 | format.js do | |
38 | render :update do |page| |
|
38 | render :update do |page| | |
39 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
39 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} | |
40 | page << "showModal('ajax-modal', '400px');" |
|
40 | page << "showModal('ajax-modal', '400px');" | |
41 | page << "$('ajax-modal').addClassName('new-watcher');" |
|
41 | page << "$('ajax-modal').addClassName('new-watcher');" | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def create |
|
47 | def create | |
48 | if params[:watcher].is_a?(Hash) && request.post? |
|
48 | if params[:watcher].is_a?(Hash) && request.post? | |
49 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
|
49 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] | |
50 | user_ids.each do |user_id| |
|
50 | user_ids.each do |user_id| | |
51 | Watcher.create(:watchable => @watched, :user_id => user_id) |
|
51 | Watcher.create(:watchable => @watched, :user_id => user_id) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | respond_to do |format| |
|
54 | respond_to do |format| | |
55 | format.html { redirect_to :back } |
|
55 | format.html { redirect_to :back } | |
56 | format.js do |
|
56 | format.js do | |
57 | render :update do |page| |
|
57 | render :update do |page| | |
58 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
58 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} | |
59 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
59 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 | rescue ::ActionController::RedirectBackError |
|
63 | rescue ::ActionController::RedirectBackError | |
64 | render :text => 'Watcher added.', :layout => true |
|
64 | render :text => 'Watcher added.', :layout => true | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def append |
|
67 | def append | |
68 | if params[:watcher].is_a?(Hash) |
|
68 | if params[:watcher].is_a?(Hash) | |
69 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
|
69 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] | |
70 | users = User.active.find_all_by_id(user_ids) |
|
70 | users = User.active.find_all_by_id(user_ids) | |
71 | respond_to do |format| |
|
71 | respond_to do |format| | |
72 | format.js do |
|
72 | format.js do | |
73 | render :update do |page| |
|
73 | render :update do |page| | |
74 | users.each do |user| |
|
74 | users.each do |user| | |
75 |
page.select("#issue_watcher_user_ids_#{user.id}").each(&: |
|
75 | page.select("#issue_watcher_user_ids_#{user.id}").each(&:remove) | |
76 | end |
|
76 | end | |
77 | page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true) |
|
77 | page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true) | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def destroy |
|
84 | def destroy | |
85 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
|
85 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? | |
86 | respond_to do |format| |
|
86 | respond_to do |format| | |
87 | format.html { redirect_to :back } |
|
87 | format.html { redirect_to :back } | |
88 | format.js do |
|
88 | format.js do | |
89 | render :update do |page| |
|
89 | render :update do |page| | |
90 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
90 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} | |
91 | end |
|
91 | end | |
92 | end |
|
92 | end | |
93 | end |
|
93 | end | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def autocomplete_for_user |
|
96 | def autocomplete_for_user | |
97 | @users = User.active.like(params[:q]).find(:all, :limit => 100) |
|
97 | @users = User.active.like(params[:q]).find(:all, :limit => 100) | |
98 | if @watched |
|
98 | if @watched | |
99 | @user -= @watched.watcher_users |
|
99 | @user -= @watched.watcher_users | |
100 | end |
|
100 | end | |
101 | render :layout => false |
|
101 | render :layout => false | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | private |
|
104 | private | |
105 | def find_project |
|
105 | def find_project | |
106 | if params[:object_type] && params[:object_id] |
|
106 | if params[:object_type] && params[:object_id] | |
107 | klass = Object.const_get(params[:object_type].camelcase) |
|
107 | klass = Object.const_get(params[:object_type].camelcase) | |
108 | return false unless klass.respond_to?('watched_by') |
|
108 | return false unless klass.respond_to?('watched_by') | |
109 | @watched = klass.find(params[:object_id]) |
|
109 | @watched = klass.find(params[:object_id]) | |
110 | @project = @watched.project |
|
110 | @project = @watched.project | |
111 | elsif params[:project_id] |
|
111 | elsif params[:project_id] | |
112 | @project = Project.visible.find(params[:project_id]) |
|
112 | @project = Project.visible.find(params[:project_id]) | |
113 | end |
|
113 | end | |
114 | rescue |
|
114 | rescue | |
115 | render_404 |
|
115 | render_404 | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def set_watcher(user, watching) |
|
118 | def set_watcher(user, watching) | |
119 | @watched.set_watcher(user, watching) |
|
119 | @watched.set_watcher(user, watching) | |
120 | respond_to do |format| |
|
120 | respond_to do |format| | |
121 | format.html { redirect_to :back } |
|
121 | format.html { redirect_to :back } | |
122 | format.js do |
|
122 | format.js do | |
123 | render(:update) do |page| |
|
123 | render(:update) do |page| | |
124 | c = watcher_css(@watched) |
|
124 | c = watcher_css(@watched) | |
125 | page.select(".#{c}").each do |item| |
|
125 | page.select(".#{c}").each do |item| | |
126 | page.replace_html item, watcher_link(@watched, user) |
|
126 | page.replace_html item, watcher_link(@watched, user) | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 | end |
|
129 | end | |
130 | end |
|
130 | end | |
131 | rescue ::ActionController::RedirectBackError |
|
131 | rescue ::ActionController::RedirectBackError | |
132 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
|
132 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true | |
133 | end |
|
133 | end | |
134 | end |
|
134 | end |
General Comments 0
You need to be logged in to leave comments.
Login now