@@ -1,174 +1,161 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class GroupsController < ApplicationController |
|
18 | class GroupsController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin |
|
21 | before_filter :require_admin | |
22 |
|
22 | |||
23 | helper :custom_fields |
|
23 | helper :custom_fields | |
24 |
|
24 | |||
25 | # GET /groups |
|
|||
26 | # GET /groups.xml |
|
|||
27 | def index |
|
25 | def index | |
28 | @groups = Group.find(:all, :order => 'lastname') |
|
26 | @groups = Group.find(:all, :order => 'lastname') | |
29 |
|
27 | |||
30 | respond_to do |format| |
|
28 | respond_to do |format| | |
31 |
format.html |
|
29 | format.html | |
32 | format.xml { render :xml => @groups } |
|
30 | format.xml { render :xml => @groups } | |
33 | end |
|
31 | end | |
34 | end |
|
32 | end | |
35 |
|
33 | |||
36 | # GET /groups/1 |
|
|||
37 | # GET /groups/1.xml |
|
|||
38 | def show |
|
34 | def show | |
39 | @group = Group.find(params[:id]) |
|
35 | @group = Group.find(params[:id]) | |
40 |
|
36 | |||
41 | respond_to do |format| |
|
37 | respond_to do |format| | |
42 |
format.html |
|
38 | format.html | |
43 | format.xml { render :xml => @group } |
|
39 | format.xml { render :xml => @group } | |
44 | end |
|
40 | end | |
45 | end |
|
41 | end | |
46 |
|
42 | |||
47 | # GET /groups/new |
|
|||
48 | # GET /groups/new.xml |
|
|||
49 | def new |
|
43 | def new | |
50 | @group = Group.new |
|
44 | @group = Group.new | |
51 |
|
45 | |||
52 | respond_to do |format| |
|
46 | respond_to do |format| | |
53 |
format.html |
|
47 | format.html | |
54 | format.xml { render :xml => @group } |
|
48 | format.xml { render :xml => @group } | |
55 | end |
|
49 | end | |
56 | end |
|
50 | end | |
57 |
|
51 | |||
58 | # GET /groups/1/edit |
|
|||
59 | def edit |
|
|||
60 | @group = Group.find(params[:id], :include => :projects) |
|
|||
61 | end |
|
|||
62 |
|
||||
63 | # POST /groups |
|
|||
64 | # POST /groups.xml |
|
|||
65 | def create |
|
52 | def create | |
66 | @group = Group.new |
|
53 | @group = Group.new | |
67 | @group.safe_attributes = params[:group] |
|
54 | @group.safe_attributes = params[:group] | |
68 |
|
55 | |||
69 | respond_to do |format| |
|
56 | respond_to do |format| | |
70 | if @group.save |
|
57 | if @group.save | |
71 | format.html { |
|
58 | format.html { | |
72 | flash[:notice] = l(:notice_successful_create) |
|
59 | flash[:notice] = l(:notice_successful_create) | |
73 | redirect_to(params[:continue] ? new_group_path : groups_path) |
|
60 | redirect_to(params[:continue] ? new_group_path : groups_path) | |
74 | } |
|
61 | } | |
75 | format.xml { render :xml => @group, :status => :created, :location => @group } |
|
62 | format.xml { render :xml => @group, :status => :created, :location => @group } | |
76 | else |
|
63 | else | |
77 | format.html { render :action => "new" } |
|
64 | format.html { render :action => "new" } | |
78 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } |
|
65 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } | |
79 | end |
|
66 | end | |
80 | end |
|
67 | end | |
81 | end |
|
68 | end | |
82 |
|
69 | |||
83 | # PUT /groups/1 |
|
70 | def edit | |
84 | # PUT /groups/1.xml |
|
71 | @group = Group.find(params[:id], :include => :projects) | |
|
72 | end | |||
|
73 | ||||
85 | def update |
|
74 | def update | |
86 | @group = Group.find(params[:id]) |
|
75 | @group = Group.find(params[:id]) | |
87 | @group.safe_attributes = params[:group] |
|
76 | @group.safe_attributes = params[:group] | |
88 |
|
77 | |||
89 | respond_to do |format| |
|
78 | respond_to do |format| | |
90 | if @group.save |
|
79 | if @group.save | |
91 | flash[:notice] = l(:notice_successful_update) |
|
80 | flash[:notice] = l(:notice_successful_update) | |
92 | format.html { redirect_to(groups_path) } |
|
81 | format.html { redirect_to(groups_path) } | |
93 | format.xml { head :ok } |
|
82 | format.xml { head :ok } | |
94 | else |
|
83 | else | |
95 | format.html { render :action => "edit" } |
|
84 | format.html { render :action => "edit" } | |
96 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } |
|
85 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } | |
97 | end |
|
86 | end | |
98 | end |
|
87 | end | |
99 | end |
|
88 | end | |
100 |
|
89 | |||
101 | # DELETE /groups/1 |
|
|||
102 | # DELETE /groups/1.xml |
|
|||
103 | def destroy |
|
90 | def destroy | |
104 | @group = Group.find(params[:id]) |
|
91 | @group = Group.find(params[:id]) | |
105 | @group.destroy |
|
92 | @group.destroy | |
106 |
|
93 | |||
107 | respond_to do |format| |
|
94 | respond_to do |format| | |
108 | format.html { redirect_to(groups_url) } |
|
95 | format.html { redirect_to(groups_url) } | |
109 | format.xml { head :ok } |
|
96 | format.xml { head :ok } | |
110 | end |
|
97 | end | |
111 | end |
|
98 | end | |
112 |
|
99 | |||
113 | def add_users |
|
100 | def add_users | |
114 | @group = Group.find(params[:id]) |
|
101 | @group = Group.find(params[:id]) | |
115 | users = User.find_all_by_id(params[:user_ids]) |
|
102 | users = User.find_all_by_id(params[:user_ids]) | |
116 | @group.users << users if request.post? |
|
103 | @group.users << users if request.post? | |
117 | respond_to do |format| |
|
104 | respond_to do |format| | |
118 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
105 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
119 | format.js { |
|
106 | format.js { | |
120 | render(:update) {|page| |
|
107 | render(:update) {|page| | |
121 | page.replace_html "tab-content-users", :partial => 'groups/users' |
|
108 | page.replace_html "tab-content-users", :partial => 'groups/users' | |
122 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } |
|
109 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } | |
123 | } |
|
110 | } | |
124 | } |
|
111 | } | |
125 | end |
|
112 | end | |
126 | end |
|
113 | end | |
127 |
|
114 | |||
128 | def remove_user |
|
115 | def remove_user | |
129 | @group = Group.find(params[:id]) |
|
116 | @group = Group.find(params[:id]) | |
130 | @group.users.delete(User.find(params[:user_id])) if request.delete? |
|
117 | @group.users.delete(User.find(params[:user_id])) if request.delete? | |
131 | respond_to do |format| |
|
118 | respond_to do |format| | |
132 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
119 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
133 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } |
|
120 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } | |
134 | end |
|
121 | end | |
135 | end |
|
122 | end | |
136 |
|
123 | |||
137 | def autocomplete_for_user |
|
124 | def autocomplete_for_user | |
138 | @group = Group.find(params[:id]) |
|
125 | @group = Group.find(params[:id]) | |
139 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) |
|
126 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) | |
140 | render :layout => false |
|
127 | render :layout => false | |
141 | end |
|
128 | end | |
142 |
|
129 | |||
143 | def edit_membership |
|
130 | def edit_membership | |
144 | @group = Group.find(params[:id]) |
|
131 | @group = Group.find(params[:id]) | |
145 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) |
|
132 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) | |
146 | @membership.save if request.post? |
|
133 | @membership.save if request.post? | |
147 | respond_to do |format| |
|
134 | respond_to do |format| | |
148 | if @membership.valid? |
|
135 | if @membership.valid? | |
149 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
136 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
150 | format.js { |
|
137 | format.js { | |
151 | render(:update) {|page| |
|
138 | render(:update) {|page| | |
152 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' |
|
139 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' | |
153 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
140 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
154 | } |
|
141 | } | |
155 | } |
|
142 | } | |
156 | else |
|
143 | else | |
157 | format.js { |
|
144 | format.js { | |
158 | render(:update) {|page| |
|
145 | render(:update) {|page| | |
159 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) |
|
146 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) | |
160 | } |
|
147 | } | |
161 | } |
|
148 | } | |
162 | end |
|
149 | end | |
163 | end |
|
150 | end | |
164 | end |
|
151 | end | |
165 |
|
152 | |||
166 | def destroy_membership |
|
153 | def destroy_membership | |
167 | @group = Group.find(params[:id]) |
|
154 | @group = Group.find(params[:id]) | |
168 | Member.find(params[:membership_id]).destroy if request.post? |
|
155 | Member.find(params[:membership_id]).destroy if request.post? | |
169 | respond_to do |format| |
|
156 | respond_to do |format| | |
170 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
157 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
171 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } |
|
158 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } | |
172 | end |
|
159 | end | |
173 | end |
|
160 | end | |
174 | end |
|
161 | end |
General Comments 0
You need to be logged in to leave comments.
Login now