To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / groups_controller.rb @ 912:5e80956cc792

History | View | Annotate | Download (5.13 KB)

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