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