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