@@ -1,101 +1,101 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class WatchersController < ApplicationController |
|
19 | 19 | before_filter :find_project |
|
20 | 20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] |
|
21 | 21 | before_filter :authorize, :only => [:new, :destroy] |
|
22 | 22 | |
|
23 | 23 | verify :method => :post, |
|
24 | 24 | :only => [ :watch, :unwatch ], |
|
25 | 25 | :render => { :nothing => true, :status => :method_not_allowed } |
|
26 | 26 | |
|
27 | 27 | def watch |
|
28 | 28 | if @watched.respond_to?(:visible?) && !@watched.visible?(User.current) |
|
29 | 29 | render_403 |
|
30 | 30 | else |
|
31 | 31 | set_watcher(User.current, true) |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def unwatch |
|
36 | 36 | set_watcher(User.current, false) |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def new |
|
40 | 40 | @watcher = Watcher.new(params[:watcher]) |
|
41 | 41 | @watcher.watchable = @watched |
|
42 | 42 | @watcher.save if request.post? |
|
43 | 43 | respond_to do |format| |
|
44 | 44 | format.html { redirect_to :back } |
|
45 | 45 | format.js do |
|
46 | 46 | render :update do |page| |
|
47 | 47 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
48 | 48 | end |
|
49 | 49 | end |
|
50 | 50 | end |
|
51 | 51 | rescue ::ActionController::RedirectBackError |
|
52 | 52 | render :text => 'Watcher added.', :layout => true |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def destroy |
|
56 | 56 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
|
57 | 57 | respond_to do |format| |
|
58 | 58 | format.html { redirect_to :back } |
|
59 | 59 | format.js do |
|
60 | 60 | render :update do |page| |
|
61 | 61 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | private |
|
68 | 68 | def find_project |
|
69 | 69 | klass = Object.const_get(params[:object_type].camelcase) |
|
70 | 70 | return false unless klass.respond_to?('watched_by') |
|
71 | 71 | @watched = klass.find(params[:object_id]) |
|
72 | 72 | @project = @watched.project |
|
73 | 73 | rescue |
|
74 | 74 | render_404 |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def set_watcher(user, watching) |
|
78 | 78 | @watched.set_watcher(user, watching) |
|
79 | 79 | if params[:replace].present? |
|
80 | 80 | if params[:replace].is_a? Array |
|
81 | 81 | replace_ids = params[:replace] |
|
82 | 82 | else |
|
83 | 83 | replace_ids = [params[:replace]] |
|
84 | 84 | end |
|
85 | 85 | else |
|
86 | replace_ids = 'watcher' | |
|
86 | replace_ids = ['watcher'] | |
|
87 | 87 | end |
|
88 | 88 | respond_to do |format| |
|
89 | 89 | format.html { redirect_to :back } |
|
90 | 90 | format.js do |
|
91 | 91 | render(:update) do |page| |
|
92 | 92 | replace_ids.each do |replace_id| |
|
93 | 93 | page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | rescue ::ActionController::RedirectBackError |
|
99 | 99 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
|
100 | 100 | end |
|
101 | 101 | end |
General Comments 0
You need to be logged in to leave comments.
Login now