@@ -1,101 +1,101 | |||||
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 | 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 | verify :method => :post, |
|
23 | verify :method => :post, | |
24 | :only => [ :watch, :unwatch ], |
|
24 | :only => [ :watch, :unwatch ], | |
25 | :render => { :nothing => true, :status => :method_not_allowed } |
|
25 | :render => { :nothing => true, :status => :method_not_allowed } | |
26 |
|
26 | |||
27 | def watch |
|
27 | def watch | |
28 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) |
|
28 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) | |
29 | render_403 |
|
29 | render_403 | |
30 | else |
|
30 | else | |
31 | set_watcher(User.current, true) |
|
31 | set_watcher(User.current, true) | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def unwatch |
|
35 | def unwatch | |
36 | set_watcher(User.current, false) |
|
36 | set_watcher(User.current, false) | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def new |
|
39 | def new | |
40 | @watcher = Watcher.new(params[:watcher]) |
|
40 | @watcher = Watcher.new(params[:watcher]) | |
41 | @watcher.watchable = @watched |
|
41 | @watcher.watchable = @watched | |
42 | @watcher.save if request.post? |
|
42 | @watcher.save if request.post? | |
43 | respond_to do |format| |
|
43 | respond_to do |format| | |
44 | format.html { redirect_to :back } |
|
44 | format.html { redirect_to :back } | |
45 | format.js do |
|
45 | format.js do | |
46 | render :update do |page| |
|
46 | render :update do |page| | |
47 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
47 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} | |
48 | end |
|
48 | end | |
49 | end |
|
49 | end | |
50 | end |
|
50 | end | |
51 | rescue ::ActionController::RedirectBackError |
|
51 | rescue ::ActionController::RedirectBackError | |
52 | render :text => 'Watcher added.', :layout => true |
|
52 | render :text => 'Watcher added.', :layout => true | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def destroy |
|
55 | def destroy | |
56 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
|
56 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? | |
57 | respond_to do |format| |
|
57 | respond_to do |format| | |
58 | format.html { redirect_to :back } |
|
58 | format.html { redirect_to :back } | |
59 | format.js do |
|
59 | format.js do | |
60 | render :update do |page| |
|
60 | render :update do |page| | |
61 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
61 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} | |
62 | end |
|
62 | end | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | private |
|
67 | private | |
68 | def find_project |
|
68 | def find_project | |
69 | klass = Object.const_get(params[:object_type].camelcase) |
|
69 | klass = Object.const_get(params[:object_type].camelcase) | |
70 | return false unless klass.respond_to?('watched_by') |
|
70 | return false unless klass.respond_to?('watched_by') | |
71 | @watched = klass.find(params[:object_id]) |
|
71 | @watched = klass.find(params[:object_id]) | |
72 | @project = @watched.project |
|
72 | @project = @watched.project | |
73 | rescue |
|
73 | rescue | |
74 | render_404 |
|
74 | render_404 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def set_watcher(user, watching) |
|
77 | def set_watcher(user, watching) | |
78 | @watched.set_watcher(user, watching) |
|
78 | @watched.set_watcher(user, watching) | |
79 | if params[:replace].present? |
|
79 | if params[:replace].present? | |
80 | if params[:replace].is_a? Array |
|
80 | if params[:replace].is_a? Array | |
81 | replace_ids = params[:replace] |
|
81 | replace_ids = params[:replace] | |
82 | else |
|
82 | else | |
83 | replace_ids = [params[:replace]] |
|
83 | replace_ids = [params[:replace]] | |
84 | end |
|
84 | end | |
85 | else |
|
85 | else | |
86 | replace_ids = 'watcher' |
|
86 | replace_ids = ['watcher'] | |
87 | end |
|
87 | end | |
88 | respond_to do |format| |
|
88 | respond_to do |format| | |
89 | format.html { redirect_to :back } |
|
89 | format.html { redirect_to :back } | |
90 | format.js do |
|
90 | format.js do | |
91 | render(:update) do |page| |
|
91 | render(:update) do |page| | |
92 | replace_ids.each do |replace_id| |
|
92 | replace_ids.each do |replace_id| | |
93 | page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) |
|
93 | page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) | |
94 | end |
|
94 | end | |
95 | end |
|
95 | end | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 | rescue ::ActionController::RedirectBackError |
|
98 | rescue ::ActionController::RedirectBackError | |
99 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
|
99 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true | |
100 | end |
|
100 | end | |
101 | end |
|
101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now