annotate app/controllers/members_controller.rb @ 1181:27b6f53331d5 bug_320

Close obsolete branch bug_320
author Chris Cannam
date Wed, 09 Nov 2011 14:19:49 +0000
parents d7326bb4f6f0
children 5e80956cc792
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 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@0 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@0 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|
luis@291 42 @new_member = Member.new(attrs.merge(: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
luis@291 50 @new_member = Member.new(attrs)
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@0 66 format.js {
Chris@0 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@0 84
Chris@0 85 end
Chris@0 86 end
Chris@0 87 end
Chris@0 88
Chris@0 89 def edit
Chris@0 90 if request.post? and @member.update_attributes(params[:member])
Chris@0 91 respond_to do |format|
chris@500 92 format.html { redirect_to :action => 'index', :project_id => @project }
Chris@0 93 format.js {
Chris@0 94 render(:update) {|page|
chris@500 95 page.replace_html "memberlist", :partial => 'editlist'
Chris@0 96 page << 'hideOnLoad()'
Chris@0 97 page.visual_effect(:highlight, "member-#{@member.id}")
Chris@0 98 }
Chris@0 99 }
Chris@0 100 end
Chris@0 101 end
Chris@0 102 end
Chris@0 103
Chris@0 104 def destroy
Chris@0 105 if request.post? && @member.deletable?
Chris@0 106 @member.destroy
Chris@0 107 end
Chris@0 108 respond_to do |format|
chris@500 109 format.html { redirect_to :action => 'index', :project_id => @project }
Chris@0 110 format.js { render(:update) {|page|
chris@500 111 page.replace_html "memberlist", :partial => 'editlist'
Chris@0 112 page << 'hideOnLoad()'
Chris@0 113 }
Chris@0 114 }
Chris@0 115 end
Chris@0 116 end
Chris@0 117
Chris@0 118 def autocomplete_for_member
Chris@0 119 @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals
chris@127 120 logger.debug "Query for #{params[:q]} returned #{@principals.size} results"
Chris@0 121 render :layout => false
Chris@0 122 end
Chris@0 123
Chris@0 124 end