annotate .svn/pristine/65/65900ece3bc07250aa0614c794f2f610e4078280.svn-base @ 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 e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 class MembersController < ApplicationController
Chris@1494 19 model_object Member
Chris@1494 20 before_filter :find_model_object, :except => [:index, :create, :autocomplete]
Chris@1494 21 before_filter :find_project_from_association, :except => [:index, :create, :autocomplete]
Chris@1494 22 before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
Chris@1494 23 before_filter :authorize
Chris@1494 24 accept_api_auth :index, :show, :create, :update, :destroy
Chris@1494 25
Chris@1494 26 def index
Chris@1494 27 @offset, @limit = api_offset_and_limit
Chris@1494 28 @member_count = @project.member_principals.count
Chris@1494 29 @member_pages = Paginator.new @member_count, @limit, params['page']
Chris@1494 30 @offset ||= @member_pages.offset
Chris@1494 31 @members = @project.member_principals.all(
Chris@1494 32 :order => "#{Member.table_name}.id",
Chris@1494 33 :limit => @limit,
Chris@1494 34 :offset => @offset
Chris@1494 35 )
Chris@1494 36
Chris@1494 37 respond_to do |format|
Chris@1494 38 format.html { head 406 }
Chris@1494 39 format.api
Chris@1494 40 end
Chris@1494 41 end
Chris@1494 42
Chris@1494 43 def show
Chris@1494 44 respond_to do |format|
Chris@1494 45 format.html { head 406 }
Chris@1494 46 format.api
Chris@1494 47 end
Chris@1494 48 end
Chris@1494 49
Chris@1494 50 def create
Chris@1494 51 members = []
Chris@1494 52 if params[:membership]
Chris@1494 53 if params[:membership][:user_ids]
Chris@1494 54 attrs = params[:membership].dup
Chris@1494 55 user_ids = attrs.delete(:user_ids)
Chris@1494 56 user_ids.each do |user_id|
Chris@1494 57 members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
Chris@1494 58 end
Chris@1494 59 else
Chris@1494 60 members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
Chris@1494 61 end
Chris@1494 62 @project.members << members
Chris@1494 63 end
Chris@1494 64
Chris@1494 65 respond_to do |format|
Chris@1494 66 format.html { redirect_to_settings_in_projects }
Chris@1494 67 format.js { @members = members }
Chris@1494 68 format.api {
Chris@1494 69 @member = members.first
Chris@1494 70 if @member.valid?
Chris@1494 71 render :action => 'show', :status => :created, :location => membership_url(@member)
Chris@1494 72 else
Chris@1494 73 render_validation_errors(@member)
Chris@1494 74 end
Chris@1494 75 }
Chris@1494 76 end
Chris@1494 77 end
Chris@1494 78
Chris@1494 79 def update
Chris@1494 80 if params[:membership]
Chris@1494 81 @member.role_ids = params[:membership][:role_ids]
Chris@1494 82 end
Chris@1494 83 saved = @member.save
Chris@1494 84 respond_to do |format|
Chris@1494 85 format.html { redirect_to_settings_in_projects }
Chris@1494 86 format.js
Chris@1494 87 format.api {
Chris@1494 88 if saved
Chris@1494 89 render_api_ok
Chris@1494 90 else
Chris@1494 91 render_validation_errors(@member)
Chris@1494 92 end
Chris@1494 93 }
Chris@1494 94 end
Chris@1494 95 end
Chris@1494 96
Chris@1494 97 def destroy
Chris@1494 98 if request.delete? && @member.deletable?
Chris@1494 99 @member.destroy
Chris@1494 100 end
Chris@1494 101 respond_to do |format|
Chris@1494 102 format.html { redirect_to_settings_in_projects }
Chris@1494 103 format.js
Chris@1494 104 format.api {
Chris@1494 105 if @member.destroyed?
Chris@1494 106 render_api_ok
Chris@1494 107 else
Chris@1494 108 head :unprocessable_entity
Chris@1494 109 end
Chris@1494 110 }
Chris@1494 111 end
Chris@1494 112 end
Chris@1494 113
Chris@1494 114 def autocomplete
Chris@1494 115 respond_to do |format|
Chris@1494 116 format.js
Chris@1494 117 end
Chris@1494 118 end
Chris@1494 119
Chris@1494 120 private
Chris@1494 121
Chris@1494 122 def redirect_to_settings_in_projects
Chris@1494 123 redirect_to settings_project_path(@project, :tab => 'members')
Chris@1494 124 end
Chris@1494 125 end