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