class Admin::TeamsController

Edit teams. All succcessful edit expire cache.

Public Instance Methods

create() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 38
def create
  params[:team][:created_by] = current_person
  @team = Team.new(params[:team])

  if @team.save
    expire_cache
    flash[:notice] = "Created #{@team.name}"
    redirect_to(edit_admin_team_path(@team))
  else
    render :action => "edit"
  end
end
destroy() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 87
def destroy
  @team = Team.find(params[:id])
  if @team.destroy
    expire_cache
    redirect_to admin_teams_path
  else
    render :edit
  end
end
destroy_name() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 97
def destroy_name
  name_id = params[:name_id]
  Name.destroy(params[:name_id])
  render :update do |page|
    page.visual_effect(:puff, "name_#{name_id}", :duration => 2)
  end
end
edit() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 29
def edit
  @team = Team.find(params[:id], :include => [:aliases, :people])
end
index() click to toggle source

Params

  • team_name

# File app/controllers/admin/teams_controller.rb, line 8
def index
  @name = params['name'] || params[:term] || session['team_name'] || cookies[:team_name] || ''
  if @name.blank?
    @teams = []
  else
    session['team_name'] = @name
    cookies[:team_name] = { :value => @name, :expires => Time.zone.now + 36000 }
    name_like = "%#{@name}%"
    @teams = Team.find_all_by_name_like(@name, RacingAssociation.current.search_results_limit)
    if @teams.size == RacingAssociation.current.search_results_limit
      flash[:warn] = "First #{RacingAssociation.current.search_results_limit} teams"
    end
  end
  
  respond_to do |format|
    format.html
    format.js
    format.json { render :json => @teams.to_json }
  end
end
merge() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 80
def merge
  @team = Team.find(params[:id])
  @other_team = Team.find(params[:other_team_id])
  @team.merge(@other_team)
  expire_cache
end
new() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 33
def new
  @team = Team.new
  render :edit
end
toggle_member() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 105
def toggle_member
  team = Team.find(params[:id])
  team.toggle!(:member)
  render(:partial => "shared/member", :locals => { :record => team })
end
update() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 51
def update
  @team = Team.find(params[:id])

  if @team.update_attributes(params[:team])
    expire_cache
    redirect_to(edit_admin_team_path(@team))
  else
    render :edit
  end
end
update_attribute() click to toggle source
# File app/controllers/admin/teams_controller.rb, line 62
def update_attribute
  respond_to do |format|
    format.js {
      @team = Team.find(params[:id])
      @team.send "#{params[:name]}=", params[:value]

      @other_teams = @team.teams_with_same_name
      if @other_teams.empty?
        @team.save!
        expire_cache
        render :text => @team.send(params[:name]), :content_type => "text/html"
      else
        render "merge_confirm"
      end
    }
  end
end