@@ -1,100 +1,100 | |||
|
1 |
# |
|
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
|
1 | # Redmine - project management software | |
|
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 MembersController < ApplicationController |
|
19 | 19 | model_object Member |
|
20 | 20 | before_filter :find_model_object, :except => [:new, :autocomplete_for_member] |
|
21 | 21 | before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member] |
|
22 | 22 | before_filter :find_project, :only => [:new, :autocomplete_for_member] |
|
23 | 23 | before_filter :authorize |
|
24 | 24 | |
|
25 | 25 | def new |
|
26 | 26 | members = [] |
|
27 | 27 | if params[:member] && request.post? |
|
28 | 28 | attrs = params[:member].dup |
|
29 | 29 | if (user_ids = attrs.delete(:user_ids)) |
|
30 | 30 | user_ids.each do |user_id| |
|
31 | 31 | members << Member.new(attrs.merge(:user_id => user_id)) |
|
32 | 32 | end |
|
33 | 33 | else |
|
34 | 34 | members << Member.new(attrs) |
|
35 | 35 | end |
|
36 | 36 | @project.members << members |
|
37 | 37 | end |
|
38 | 38 | respond_to do |format| |
|
39 | 39 | if members.present? && members.all? {|m| m.valid? } |
|
40 | 40 | |
|
41 | 41 | format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } |
|
42 | 42 | |
|
43 | 43 |
format.js { |
|
44 | 44 |
render(:update) {|page| |
|
45 | 45 | page.replace_html "tab-content-members", :partial => 'projects/settings/members' |
|
46 | 46 | page << 'hideOnLoad()' |
|
47 | 47 | members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") } |
|
48 | 48 | } |
|
49 | 49 | } |
|
50 | 50 | else |
|
51 | 51 | |
|
52 | 52 | format.js { |
|
53 | 53 | render(:update) {|page| |
|
54 | 54 | errors = members.collect {|m| |
|
55 | 55 | m.errors.full_messages |
|
56 | 56 | }.flatten.uniq |
|
57 | 57 | |
|
58 | 58 | page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', '))) |
|
59 | 59 | } |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def edit |
|
67 | 67 | if request.post? and @member.update_attributes(params[:member]) |
|
68 | 68 | respond_to do |format| |
|
69 | 69 | format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } |
|
70 | 70 |
format.js { |
|
71 | 71 |
render(:update) {|page| |
|
72 | 72 | page.replace_html "tab-content-members", :partial => 'projects/settings/members' |
|
73 | 73 | page << 'hideOnLoad()' |
|
74 | 74 | page.visual_effect(:highlight, "member-#{@member.id}") |
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def destroy |
|
82 | 82 | if request.post? && @member.deletable? |
|
83 | 83 | @member.destroy |
|
84 | 84 | end |
|
85 | 85 | respond_to do |format| |
|
86 | 86 | format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } |
|
87 | 87 | format.js { render(:update) {|page| |
|
88 | 88 | page.replace_html "tab-content-members", :partial => 'projects/settings/members' |
|
89 | 89 | page << 'hideOnLoad()' |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | end |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def autocomplete_for_member |
|
96 | 96 | @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals |
|
97 | 97 | render :layout => false |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now