##// END OF EJS Templates
Manually generates the javascript that prototype_helper fails to do with ruby1.9.2....
Jean-Philippe Lang -
r9347:d15ab86459a7
parent child
Show More
@@ -1,132 +1,128
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_referer_or {render :text => 'Watcher added.', :layout => true}}
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 end
64 64
65 65 def append
66 66 if params[:watcher].is_a?(Hash)
67 67 user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
68 68 users = User.active.find_all_by_id(user_ids)
69 69 respond_to do |format|
70 70 format.js do
71 71 render :update do |page|
72 72 users.each do |user|
73 page.select("#issue_watcher_user_ids_#{user.id}").each do |item|
74 page.remove item
75 end
73 page << %|$$("#issue_watcher_user_ids_#{user.id}").each(function(el){el.remove();});|
76 74 end
77 75 page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true)
78 76 end
79 77 end
80 78 end
81 79 end
82 80 end
83 81
84 82 def destroy
85 83 @watched.set_watcher(User.find(params[:user_id]), false) if request.post?
86 84 respond_to do |format|
87 85 format.html { redirect_to :back }
88 86 format.js do
89 87 render :update do |page|
90 88 page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
91 89 end
92 90 end
93 91 end
94 92 end
95 93
96 94 def autocomplete_for_user
97 95 @users = User.active.like(params[:q]).find(:all, :limit => 100)
98 96 if @watched
99 97 @users -= @watched.watcher_users
100 98 end
101 99 render :layout => false
102 100 end
103 101
104 102 private
105 103 def find_project
106 104 if params[:object_type] && params[:object_id]
107 105 klass = Object.const_get(params[:object_type].camelcase)
108 106 return false unless klass.respond_to?('watched_by')
109 107 @watched = klass.find(params[:object_id])
110 108 @project = @watched.project
111 109 elsif params[:project_id]
112 110 @project = Project.visible.find_by_param(params[:project_id])
113 111 end
114 112 rescue
115 113 render_404
116 114 end
117 115
118 116 def set_watcher(user, watching)
119 117 @watched.set_watcher(user, watching)
120 118 respond_to do |format|
121 119 format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
122 120 format.js do
123 121 render(:update) do |page|
124 122 c = watcher_css(@watched)
125 page.select(".#{c}").each do |item|
126 page.replace_html item, watcher_link(@watched, user)
127 end
123 page << %|$$(".#{c}").each(function(el){el.innerHTML="#{escape_javascript watcher_link(@watched, user)}"});|
128 124 end
129 125 end
130 126 end
131 127 end
132 128 end
General Comments 0
You need to be logged in to leave comments. Login now