annotate app/controllers/members_controller.rb @ 1169:492ff72268e3 bug_521

Close obsolete branch bug_521
author Chris Cannam
date Thu, 18 Oct 2012 10:42:48 +0100
parents ec1c49528f36
children bb32da3bea34
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 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 MembersController < ApplicationController
Chris@0 19 model_object Member
chris@493 20 menu_item :members
chris@493 21 before_filter :find_model_object, :except => [:index, :new, :autocomplete_for_member]
chris@493 22 before_filter :find_project_from_association, :except => [:new, :index, :autocomplete_for_member]
Chris@0 23 before_filter :find_project, :only => [:new, :autocomplete_for_member]
chris@493 24 before_filter :find_project_by_project_id, :only => [:index]
Chris@0 25 before_filter :authorize
Chris@0 26
chris@493 27 def index
chris@493 28 logger.debug('in index')
chris@493 29 respond_to do |format|
chris@493 30 format.html {
chris@493 31 render :layout => false if request.xhr?
chris@493 32 }
chris@493 33 end
chris@493 34 end
chris@493 35
Chris@0 36 def new
Chris@0 37 members = []
Chris@0 38 if params[:member] && request.post?
Chris@0 39 attrs = params[:member].dup
Chris@0 40 if (user_ids = attrs.delete(:user_ids))
Chris@0 41 user_ids.each do |user_id|
Chris@931 42 @new_member = Member.new(:role_ids => params[:member][:role_ids], :user_id => user_id)
luis@291 43 members << @new_member
luis@291 44
luis@291 45 # send notification to member
luisf@292 46 Mailer.deliver_added_to_project(@new_member, @project)
luis@291 47
Chris@0 48 end
Chris@0 49 else
Chris@931 50 @new_member = Member.new(:role_ids => params[:member][:role_ids], :user_id => params[:member][:user_id])
luis@291 51 members << @new_member
luis@291 52
luis@291 53 # send notification to member
luisf@292 54 Mailer.deliver_added_to_project(@new_member, @project)
luis@291 55
Chris@0 56 end
luis@291 57
Chris@0 58 @project.members << members
luis@291 59
Chris@0 60 end
Chris@0 61 respond_to do |format|
Chris@0 62 if members.present? && members.all? {|m| m.valid? }
Chris@0 63
chris@500 64 format.html { redirect_to :action => 'index', :project_id => @project }
Chris@0 65
Chris@909 66 format.js {
Chris@909 67 render(:update) {|page|
chris@500 68 page.replace_html "memberlist", :partial => 'editlist'
Chris@0 69 page << 'hideOnLoad()'
Chris@0 70 members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") }
Chris@0 71 }
Chris@0 72 }
Chris@0 73 else
Chris@0 74
Chris@0 75 format.js {
Chris@0 76 render(:update) {|page|
Chris@0 77 errors = members.collect {|m|
Chris@0 78 m.errors.full_messages
Chris@0 79 }.flatten.uniq
luis@276 80
luis@276 81 # page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', ')))
Chris@0 82 }
Chris@0 83 }
Chris@909 84
Chris@0 85 end
Chris@0 86 end
Chris@0 87 end
Chris@909 88
Chris@0 89 def edit
Chris@929 90 if params[:member]
Chris@929 91 @member.role_ids = params[:member][:role_ids]
Chris@929 92 end
Chris@929 93 if request.post? and @member.save
Chris@0 94 respond_to do |format|
chris@500 95 format.html { redirect_to :action => 'index', :project_id => @project }
Chris@909 96 format.js {
Chris@909 97 render(:update) {|page|
chris@500 98 page.replace_html "memberlist", :partial => 'editlist'
Chris@0 99 page << 'hideOnLoad()'
Chris@0 100 page.visual_effect(:highlight, "member-#{@member.id}")
Chris@0 101 }
Chris@0 102 }
Chris@0 103 end
Chris@0 104 end
Chris@0 105 end
Chris@0 106
Chris@0 107 def destroy
Chris@0 108 if request.post? && @member.deletable?
Chris@0 109 @member.destroy
Chris@0 110 end
Chris@0 111 respond_to do |format|
chris@500 112 format.html { redirect_to :action => 'index', :project_id => @project }
Chris@0 113 format.js { render(:update) {|page|
chris@500 114 page.replace_html "memberlist", :partial => 'editlist'
Chris@0 115 page << 'hideOnLoad()'
Chris@0 116 }
Chris@0 117 }
Chris@0 118 end
Chris@0 119 end
Chris@909 120
Chris@0 121 def autocomplete_for_member
Chris@929 122 @principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
chris@127 123 logger.debug "Query for #{params[:q]} returned #{@principals.size} results"
Chris@0 124 render :layout => false
Chris@0 125 end
Chris@0 126
Chris@0 127 end