Chris@0: # redMine - project management software Chris@0: # Copyright (C) 2006 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@0: class MembersController < ApplicationController Chris@0: model_object Member Chris@0: before_filter :find_model_object, :except => [:new, :autocomplete_for_member] Chris@0: before_filter :find_project_from_association, :except => [:new, :autocomplete_for_member] Chris@0: before_filter :find_project, :only => [:new, :autocomplete_for_member] Chris@0: before_filter :authorize Chris@0: Chris@0: def new Chris@0: members = [] Chris@0: if params[:member] && request.post? Chris@0: attrs = params[:member].dup Chris@0: if (user_ids = attrs.delete(:user_ids)) Chris@0: user_ids.each do |user_id| luis@291: @new_member = Member.new(attrs.merge(:user_id => user_id)) luis@291: members << @new_member luis@291: luis@291: # send notification to member luisf@292: Mailer.deliver_added_to_project(@new_member, @project) luis@291: Chris@0: end Chris@0: else luis@291: @new_member = Member.new(attrs) luis@291: members << @new_member luis@291: luis@291: # send notification to member luisf@292: Mailer.deliver_added_to_project(@new_member, @project) luis@291: Chris@0: end luis@291: Chris@0: @project.members << members luis@291: Chris@0: end Chris@0: respond_to do |format| Chris@0: if members.present? && members.all? {|m| m.valid? } Chris@0: Chris@0: format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } Chris@0: Chris@0: format.js { Chris@0: render(:update) {|page| Chris@0: page.replace_html "tab-content-members", :partial => 'projects/settings/members' Chris@0: page << 'hideOnLoad()' Chris@0: members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") } Chris@0: } Chris@0: } Chris@0: else Chris@0: Chris@0: format.js { Chris@0: render(:update) {|page| Chris@0: errors = members.collect {|m| Chris@0: m.errors.full_messages Chris@0: }.flatten.uniq luis@276: luis@276: # page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', '))) Chris@0: } Chris@0: } Chris@0: Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: def edit Chris@0: if request.post? and @member.update_attributes(params[:member]) Chris@0: respond_to do |format| Chris@0: format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } Chris@0: format.js { Chris@0: render(:update) {|page| Chris@0: page.replace_html "tab-content-members", :partial => 'projects/settings/members' Chris@0: page << 'hideOnLoad()' Chris@0: page.visual_effect(:highlight, "member-#{@member.id}") Chris@0: } Chris@0: } Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: def destroy Chris@0: if request.post? && @member.deletable? Chris@0: @member.destroy Chris@0: end Chris@0: respond_to do |format| Chris@0: format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project } Chris@0: format.js { render(:update) {|page| Chris@0: page.replace_html "tab-content-members", :partial => 'projects/settings/members' Chris@0: page << 'hideOnLoad()' Chris@0: } Chris@0: } Chris@0: end Chris@0: end Chris@0: Chris@0: def autocomplete_for_member Chris@0: @principals = Principal.active.like(params[:q]).find(:all, :limit => 100) - @project.principals chris@135: logger.debug "Query for #{params[:q]} returned #{@principals.size} results" Chris@0: render :layout => false Chris@0: end Chris@0: Chris@0: end