@@ -1,49 +1,53 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | layout 'base' |
|
19 | layout 'base' | |
20 | before_filter :require_login, :find_project, :check_project_privacy |
|
20 | before_filter :require_login, :find_project, :check_project_privacy | |
21 |
|
21 | |||
22 | def add |
|
22 | def add | |
23 | user = User.current |
|
23 | user = User.current | |
24 | @watched.add_watcher(user) |
|
24 | @watched.add_watcher(user) | |
25 | respond_to do |format| |
|
25 | respond_to do |format| | |
26 | format.html { render :text => 'Watcher added.', :layout => true } |
|
26 | format.html { redirect_to :back } | |
27 | format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} } |
|
27 | format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} } | |
28 | end |
|
28 | end | |
|
29 | rescue RedirectBackError | |||
|
30 | render :text => 'Watcher added.', :layout => true | |||
29 | end |
|
31 | end | |
30 |
|
32 | |||
31 | def remove |
|
33 | def remove | |
32 | user = User.current |
|
34 | user = User.current | |
33 | @watched.remove_watcher(user) |
|
35 | @watched.remove_watcher(user) | |
34 | respond_to do |format| |
|
36 | respond_to do |format| | |
35 | format.html { render :text => 'Watcher removed.', :layout => true } |
|
37 | format.html { redirect_to :back } | |
36 | format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} } |
|
38 | format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} } | |
37 | end |
|
39 | end | |
|
40 | rescue RedirectBackError | |||
|
41 | render :text => 'Watcher removed.', :layout => true | |||
38 | end |
|
42 | end | |
39 |
|
43 | |||
40 | private |
|
44 | private | |
41 | def find_project |
|
45 | def find_project | |
42 | klass = Object.const_get(params[:object_type].camelcase) |
|
46 | klass = Object.const_get(params[:object_type].camelcase) | |
43 | return false unless klass.respond_to?('watched_by') |
|
47 | return false unless klass.respond_to?('watched_by') | |
44 | @watched = klass.find(params[:object_id]) |
|
48 | @watched = klass.find(params[:object_id]) | |
45 | @project = @watched.project |
|
49 | @project = @watched.project | |
46 | rescue |
|
50 | rescue | |
47 | render_404 |
|
51 | render_404 | |
48 | end |
|
52 | end | |
49 | end |
|
53 | end |
General Comments 0
You need to be logged in to leave comments.
Login now