Class Admin::TeamsController
In: app/controllers/admin/teams_controller.rb
Parent: Admin::AdminController

Edit teams. All succcessful edit expire cache.

Methods

Public Instance methods

Cancel inline editing

[Source]

     # File app/controllers/admin/teams_controller.rb, line 115
115:   def cancel_in_place_edit
116:     team_id = params[:id]
117:     render :update do |page|
118:       page.replace("team_#{team_id}_row", :partial => "team", :locals => { :team => Team.find(team_id) })
119:       page.call :restripeTable, :teams_table
120:     end
121:   end

[Source]

    # File app/controllers/admin/teams_controller.rb, line 40
40:   def create
41:     params[:team][:created_by] = current_person
42:     @team = Team.new(params[:team])
43: 
44:     if @team.save
45:       expire_cache
46:       flash[:notice] = "Created #{@team.name}"
47:       redirect_to(edit_admin_team_path(@team))
48:     else
49:       render :action => "edit"
50:     end
51:   end

[Source]

     # File app/controllers/admin/teams_controller.rb, line 123
123:   def destroy
124:     @team = Team.find(params[:id])
125:     if @team.destroy
126:       expire_cache
127:       redirect_to admin_teams_path
128:     else
129:       render :edit
130:     end
131:   end

Exact dupe of people controller

[Source]

     # File app/controllers/admin/teams_controller.rb, line 134
134:   def destroy_alias
135:     alias_id = params[:alias_id]
136:     Alias.destroy(alias_id)
137:     render :update do |page|
138:       page.visual_effect(:puff, "alias_#{alias_id}", :duration => 2)
139:     end
140:   end

[Source]

     # File app/controllers/admin/teams_controller.rb, line 142
142:   def destroy_name
143:     name_id = params[:name_id]
144:     Name.destroy(params[:name_id])
145:     render :update do |page|
146:       page.visual_effect(:puff, "name_#{name_id}", :duration => 2)
147:     end
148:   end

[Source]

    # File app/controllers/admin/teams_controller.rb, line 31
31:   def edit
32:     @team = Team.find(params[:id], :include => [:aliases, :people])
33:   end

Params

  • team_name

[Source]

    # File app/controllers/admin/teams_controller.rb, line 10
10:   def index
11:     @name = params['name'] || params[:term] || session['team_name'] || cookies[:team_name] || ''
12:     if @name.blank?
13:       @teams = []
14:     else
15:       session['team_name'] = @name
16:       cookies[:team_name] = { :value => @name, :expires => Time.zone.now + 36000 }
17:       name_like = "%#{@name}%"
18:       @teams = Team.find_all_by_name_like(@name, RacingAssociation.current.search_results_limit)
19:       if @teams.size == RacingAssociation.current.search_results_limit
20:         flash[:warn] = "First #{RacingAssociation.current.search_results_limit} teams"
21:       end
22:     end
23:     
24:     respond_to do |format|
25:       format.html
26:       format.js
27:       format.json { render :json => @teams.to_json }
28:     end
29:   end

Inline

[Source]

     # File app/controllers/admin/teams_controller.rb, line 105
105:   def merge
106:     team_to_merge_id = params[:id].gsub('team_', '')
107:     @team_to_merge = Team.find(team_to_merge_id)
108:     @merged_team_name = @team_to_merge.name
109:     @existing_team = Team.find(params[:target_id])
110:     @existing_team.merge(@team_to_merge)
111:     expire_cache
112:   end

Inline

[Source]

     # File app/controllers/admin/teams_controller.rb, line 95
 95:   def merge?(original_name, existing_teams, team)
 96:     @team = team
 97:     @existing_teams = existing_teams
 98:     @original_name = original_name
 99:     render :update do |page| 
100:       page.replace_html("team_#{@team.id}_row", :partial => 'merge_confirm', :locals => { :team => @team })
101:     end
102:   end

[Source]

    # File app/controllers/admin/teams_controller.rb, line 35
35:   def new
36:     @team = Team.new
37:     render :edit
38:   end

Inline update. Merge with existing Team if names match

[Source]

    # File app/controllers/admin/teams_controller.rb, line 71
71:   def set_team_name
72:     @team = Team.find(params[:id])
73:     new_name = params[:value]
74:     @team.name = new_name
75: 
76:     teams_with_same_name = @team.teams_with_same_name
77:     unless teams_with_same_name.empty?
78:       return merge?(@team.name_was, teams_with_same_name, @team)
79:     end
80:     
81:     # Want validation
82:     @team.name = params[:value]
83:     if @team.save
84:       expire_cache
85:       render :text => @team.name
86:     else
87:       render :update do |page|
88:         page.alert(@team.errors.full_messages)
89:         render :text => @team.name_was
90:       end
91:     end
92:   end

[Source]

    # File app/controllers/admin/teams_controller.rb, line 64
64:   def toggle_member
65:     team = Team.find(params[:id])
66:     team.toggle!(:member)
67:     render(:partial => "shared/member", :locals => { :record => team })
68:   end

[Source]

    # File app/controllers/admin/teams_controller.rb, line 53
53:   def update
54:     @team = Team.find(params[:id])
55: 
56:     if @team.update_attributes(params[:team])
57:       expire_cache
58:       redirect_to(edit_admin_team_path(@team))
59:     else
60:       render :edit
61:     end
62:   end

[Validate]