annotate app/controllers/groups_controller.rb @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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@1115 22 before_filter :find_group, :except => [:index, :new, :create]
Chris@1115 23 accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
Chris@909 24
Chris@0 25 helper :custom_fields
Chris@909 26
Chris@0 27 def index
Chris@1115 28 @groups = Group.sorted.all
Chris@0 29
Chris@0 30 respond_to do |format|
Chris@1115 31 format.html
Chris@1115 32 format.api
Chris@0 33 end
Chris@0 34 end
Chris@0 35
Chris@0 36 def show
Chris@0 37 respond_to do |format|
Chris@1115 38 format.html
Chris@1115 39 format.api
Chris@0 40 end
Chris@0 41 end
Chris@0 42
Chris@0 43 def new
Chris@0 44 @group = Group.new
Chris@0 45 end
Chris@0 46
Chris@0 47 def create
Chris@1115 48 @group = Group.new
Chris@1115 49 @group.safe_attributes = params[:group]
Chris@0 50
Chris@0 51 respond_to do |format|
Chris@0 52 if @group.save
Chris@909 53 format.html {
Chris@909 54 flash[:notice] = l(:notice_successful_create)
Chris@909 55 redirect_to(params[:continue] ? new_group_path : groups_path)
Chris@909 56 }
Chris@1115 57 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
Chris@0 58 else
Chris@0 59 format.html { render :action => "new" }
Chris@1115 60 format.api { render_validation_errors(@group) }
Chris@0 61 end
Chris@0 62 end
Chris@0 63 end
Chris@0 64
Chris@1115 65 def edit
Chris@1115 66 end
Chris@1115 67
Chris@0 68 def update
Chris@1115 69 @group.safe_attributes = params[:group]
Chris@0 70
Chris@0 71 respond_to do |format|
Chris@1115 72 if @group.save
Chris@0 73 flash[:notice] = l(:notice_successful_update)
Chris@0 74 format.html { redirect_to(groups_path) }
Chris@1115 75 format.api { render_api_ok }
Chris@0 76 else
Chris@0 77 format.html { render :action => "edit" }
Chris@1115 78 format.api { render_validation_errors(@group) }
Chris@0 79 end
Chris@0 80 end
Chris@0 81 end
Chris@0 82
Chris@0 83 def destroy
Chris@0 84 @group.destroy
Chris@0 85
Chris@0 86 respond_to do |format|
Chris@1464 87 format.html { redirect_to(groups_path) }
Chris@1115 88 format.api { render_api_ok }
Chris@0 89 end
Chris@0 90 end
Chris@909 91
Chris@0 92 def add_users
Chris@1517 93 @users = User.where(:id => (params[:user_id] || params[:user_ids])).all
Chris@1115 94 @group.users << @users if request.post?
Chris@0 95 respond_to do |format|
Chris@1464 96 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
Chris@1115 97 format.js
Chris@1115 98 format.api { render_api_ok }
Chris@0 99 end
Chris@0 100 end
Chris@909 101
Chris@0 102 def remove_user
Chris@909 103 @group.users.delete(User.find(params[:user_id])) if request.delete?
Chris@0 104 respond_to do |format|
Chris@1464 105 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
Chris@1115 106 format.js
Chris@1115 107 format.api { render_api_ok }
Chris@0 108 end
Chris@0 109 end
Chris@909 110
Chris@0 111 def autocomplete_for_user
Chris@1464 112 respond_to do |format|
Chris@1464 113 format.js
Chris@1464 114 end
Chris@0 115 end
Chris@909 116
Chris@0 117 def edit_membership
Chris@0 118 @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
Chris@0 119 @membership.save if request.post?
Chris@0 120 respond_to do |format|
Chris@1464 121 format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
Chris@1115 122 format.js
Chris@14 123 end
Chris@0 124 end
Chris@909 125
Chris@0 126 def destroy_membership
Chris@0 127 Member.find(params[:membership_id]).destroy if request.post?
Chris@0 128 respond_to do |format|
Chris@1464 129 format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
Chris@1115 130 format.js
Chris@0 131 end
Chris@0 132 end
Chris@1115 133
Chris@1115 134 private
Chris@1115 135
Chris@1115 136 def find_group
Chris@1115 137 @group = Group.find(params[:id])
Chris@1115 138 rescue ActiveRecord::RecordNotFound
Chris@1115 139 render_404
Chris@1115 140 end
Chris@0 141 end