summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-09 18:37:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-09 18:37:16 +0000
commit1b1c510ff99cfca216082926e5ce9e2e981b2506 (patch)
treeae25be505ae388435276a44a7755186c70ebe5e7 /app
parentc22f60271f7c6726a28b2a319041c11b2a782b5e (diff)
downloadredmine-1b1c510ff99cfca216082926e5ce9e2e981b2506.tar.gz
redmine-1b1c510ff99cfca216082926e5ce9e2e981b2506.zip
Ability to add non-member users as watchers (#5159).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8592 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/watchers_controller.rb26
-rw-r--r--app/views/layouts/base.html.erb1
-rw-r--r--app/views/watchers/_new.html.erb30
-rw-r--r--app/views/watchers/_watchers.html.erb20
-rw-r--r--app/views/watchers/autocomplete_for_user.html.erb1
5 files changed, 59 insertions, 19 deletions
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index 8c951ad9d..1a1935d0d 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -37,13 +37,28 @@ class WatchersController < ApplicationController
end
def new
- @watcher = Watcher.new(params[:watcher])
- @watcher.watchable = @watched
- @watcher.save if request.post?
+ respond_to do |format|
+ format.js do
+ render :update do |page|
+ page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
+ page << "showModal('ajax-modal', '400px');"
+ end
+ end
+ end
+ end
+
+ def create
+ if params[:watcher].is_a?(Hash) && request.post?
+ user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
+ user_ids.each do |user_id|
+ Watcher.create(:watchable => @watched, :user_id => user_id)
+ end
+ end
respond_to do |format|
format.html { redirect_to :back }
format.js do
render :update do |page|
+ page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
end
end
@@ -64,6 +79,11 @@ class WatchersController < ApplicationController
end
end
+ def autocomplete_for_user
+ @users = User.active.like(params[:q]).find(:all, :limit => 100) - @watched.watcher_users
+ render :layout => false
+ end
+
private
def find_project
klass = Object.const_get(params[:object_type].camelcase)
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 6673b4944..ccf5dbaee 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -73,6 +73,7 @@
</div>
<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
+<div id="ajax-modal" style="display:none;"></div>
<div id="footer">
<div class="bgl"><div class="bgr">
diff --git a/app/views/watchers/_new.html.erb b/app/views/watchers/_new.html.erb
new file mode 100644
index 000000000..56a122a51
--- /dev/null
+++ b/app/views/watchers/_new.html.erb
@@ -0,0 +1,30 @@
+<h3 class="title"><%= l(:permission_add_issue_watchers) %></h3>
+
+<% form_remote_tag :url => {:controller => 'watchers',
+ :action => 'create',
+ :object_type => watched.class.name.underscore,
+ :object_id => watched},
+ :method => :post,
+ :html => {:id => 'new-watcher-form'} do %>
+
+ <p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
+ <%= observe_field(:user_search,
+ :frequency => 0.5,
+ :update => :users_for_watcher,
+ :method => :get,
+ :url => {
+ :controller => 'watchers',
+ :action => 'autocomplete_for_user',
+ :object_type => watched.class.name.underscore,
+ :object_id => watched},
+ :with => 'q') %>
+
+ <div id="users_for_watcher">
+ <%= principals_check_box_tags 'watcher[user_ids][]', watched.addable_watcher_users %>
+ </div>
+
+ <p class="buttons">
+ <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %>
+ <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
+ </p>
+<% end %>
diff --git a/app/views/watchers/_watchers.html.erb b/app/views/watchers/_watchers.html.erb
index 67e1f4fca..1f40707be 100644
--- a/app/views/watchers/_watchers.html.erb
+++ b/app/views/watchers/_watchers.html.erb
@@ -1,26 +1,14 @@
+<% if User.current.allowed_to?(:add_issue_watchers, @project) %>
<div class="contextual">
<%= link_to_remote l(:button_add),
:url => {:controller => 'watchers',
:action => 'new',
:object_type => watched.class.name.underscore,
- :object_id => watched} if User.current.allowed_to?(:add_issue_watchers, @project) %>
+ :object_id => watched},
+ :method => 'get' %>
</div>
+<% end %>
<h3><%= l(:label_issue_watchers) %> (<%= watched.watcher_users.size %>)</h3>
-<% unless @watcher.nil? %>
- <% remote_form_for(:watcher, @watcher,
- :url => {:controller => 'watchers',
- :action => 'new',
- :object_type => watched.class.name.underscore,
- :object_id => watched},
- :method => :post,
- :html => {:id => 'new-watcher-form'}) do |f| %>
- <p><%= f.select :user_id, (watched.addable_watcher_users.collect {|m| [m.name, m.id]}), :prompt => "--- #{l(:actionview_instancetag_blank_option)} ---" %>
-
- <%= submit_tag l(:button_add) %>
- <%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
- <% end %>
-<% end %>
-
<%= watchers_list(watched) %>
diff --git a/app/views/watchers/autocomplete_for_user.html.erb b/app/views/watchers/autocomplete_for_user.html.erb
new file mode 100644
index 000000000..a24d28eb4
--- /dev/null
+++ b/app/views/watchers/autocomplete_for_user.html.erb
@@ -0,0 +1 @@
+<%= principals_check_box_tags 'watcher[user_ids][]', @users %>