2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
class GroupsController < ApplicationController
|
2009-12-17 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
before_filter :require_admin
|
2011-05-30 22:52:25 +04:00
|
|
|
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
# GET /groups
|
|
|
|
# GET /groups.xml
|
|
|
|
def index
|
|
|
|
@groups = Group.find(:all, :order => 'lastname')
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.xml { render :xml => @groups }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /groups/1
|
|
|
|
# GET /groups/1.xml
|
|
|
|
def show
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.xml { render :xml => @group }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /groups/new
|
|
|
|
# GET /groups/new.xml
|
|
|
|
def new
|
|
|
|
@group = Group.new
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.xml { render :xml => @group }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /groups/1/edit
|
|
|
|
def edit
|
2010-05-09 15:31:39 +04:00
|
|
|
@group = Group.find(params[:id], :include => :projects)
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /groups
|
|
|
|
# POST /groups.xml
|
|
|
|
def create
|
|
|
|
@group = Group.new(params[:group])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @group.save
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
format.html { redirect_to(groups_path) }
|
|
|
|
format.xml { render :xml => @group, :status => :created, :location => @group }
|
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /groups/1
|
|
|
|
# PUT /groups/1.xml
|
|
|
|
def update
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @group.update_attributes(params[:group])
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
format.html { redirect_to(groups_path) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /groups/1
|
|
|
|
# DELETE /groups/1.xml
|
|
|
|
def destroy
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
@group.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(groups_url) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def add_users
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
users = User.find_all_by_id(params[:user_ids])
|
|
|
|
@group.users << users if request.post?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
2011-05-30 22:52:25 +04:00
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
2009-09-12 12:36:46 +04:00
|
|
|
page.replace_html "tab-content-users", :partial => 'groups/users'
|
|
|
|
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def remove_user
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
@group.users.delete(User.find(params[:user_id])) if request.post?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
|
|
|
|
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def autocomplete_for_user
|
|
|
|
@group = Group.find(params[:id])
|
2011-04-01 20:47:30 +04:00
|
|
|
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
|
2009-09-12 12:36:46 +04:00
|
|
|
render :layout => false
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def edit_membership
|
|
|
|
@group = Group.find(params[:id])
|
2010-03-18 18:49:11 +03:00
|
|
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
|
2009-09-12 12:36:46 +04:00
|
|
|
@membership.save if request.post?
|
|
|
|
respond_to do |format|
|
2010-08-11 02:37:00 +04:00
|
|
|
if @membership.valid?
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
|
|
|
|
page.visual_effect(:highlight, "member-#{@membership.id}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format.js {
|
|
|
|
render(:update) {|page|
|
|
|
|
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def destroy_membership
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
Member.find(params[:membership_id]).destroy if request.post?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
|
|
|
|
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|