Class: RacerController

Inherits:
Shoes::Main
  • Object
show all
Includes:
RacerHelper
Defined in:
lib/controllers/racer_controller.rb

Instance Method Summary collapse

Methods included from RacerHelper

#cancel_button, #create_categorizations_for_checkboxes, #create_old_racer, #find_or_create_participation, #render_racer_form

Instance Method Details

#edit(id, tournament_id) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/controllers/racer_controller.rb', line 22

def edit(id, tournament_id)
  racer = Racer[id]
  tournament = Tournament[tournament_id]
  tournament_participation = find_or_create_participation(racer,tournament)
  return_to_url = session[:referrer].pop
  layout
  @center.clear {
    container
    stack{
      flow {
        stack(:width => 0.4) { render_racer_form(racer, tournament_participation) }
        stack(:width => 0.05)
        stack(:width => 0.4) {
          if best = tournament_participation.best_time
            #TODO i18n
            para "Best time in this event:","#{"%.2f" % best} seconds"
          end
          if best = racer.best_time
            #TODO i18n
            para "Best time ever:","#{"%.2f" % best} seconds"
          end
        }
      }
      
      flow {
        button $i18n.save do
          if((tournament.racers-[racer]).any? { |r| racer.name == r.name })
            alert("Racer is already in this event.")
          elsif racer.name.blank?
            alert "Sorry, name is required."
          elsif old_racer = Racer.filter(:name => racer.name).exclude(:id => racer.pk).first
            create_old_racer(old_racer, racer, tournament)
            visit(return_to_url||'/racers')
          else
            racer.save
            tournament_participation.save
            create_categorizations_for_checkboxes(racer)
            if Racer[racer.pk].name.blank? && racer.name.blank?
              racer.destroy
            end
            visit(return_to_url||'/racers')
          end
        end
        cancel_button(racer,return_to_url||'/racers')
      }
    }
  }
  timer(0.01) { @e.focus }
end

#edit_in_race(id, race_id) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/controllers/racer_controller.rb', line 87

def edit_in_race(id, race_id)
  racer = Racer[id]
  race = Race[race_id]
  tournament = race.tournament
  tournament_participation = find_or_create_participation(racer, tournament)
  layout
  @center.clear {
    container
    stack{
      flow {
        stack(:width => 0.4) { render_racer_form(racer, tournament_participation) }
        stack(:width => 0.05)
        stack(:width => 0.4) {
          if best = tournament_participation.best_time
            #TODO i18n
            para "Best time in this event:","#{"%.2f" % best} seconds"
          end
          if best = racer.best_time
            #TODO i18n
            para "Best time ever:","#{"%.2f" % best} seconds"
          end
        }
      }
      flow {
        button $i18n.save do
          if((tournament.racers-[racer]).any? { |r| racer.name == r.name })
            alert("Racer is already in this event.")
          elsif racer.name.blank?
            alert "Sorry, name is required."
          elsif old_racer = Racer.filter(:name => racer.name).exclude(:id => racer.pk).first
            create_old_racer(old_racer, racer, tournament)
            visit "/races/#{race_id}/edit"
          else
            racer.save
            tournament_participation.save
            create_categorizations_for_checkboxes(racer)
            if Racer[racer.pk].name.blank? && racer.name.blank?
              racer.destroy
            else
              rp = RaceParticipation.create(:racer => racer, :race => race)
            end
            visit "/races/#{race_id}/edit"
          end
        end
        cancel_button(racer,"/races/#{race_id}/edit")
      }
    }
  }
  timer(0.01) { @e.focus }
end

#listObject


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/controllers/racer_controller.rb', line 10

def list
  layout    
  @center.clear {
    stack do
      button("new racer") { visit "/racers/new" }
      Racer.all.each {|r|
        para(link(r.name,:click => "/racers/#{r.pk}"))
      }
    end
  }
end

#newObject


72
73
74
75
# File 'lib/controllers/racer_controller.rb', line 72

def new
  racer = Racer.create
  visit "/racers/#{racer.pk}"
end

#new_in_race(race_id) ⇒ Object


82
83
84
85
# File 'lib/controllers/racer_controller.rb', line 82

def new_in_race(race_id)
  racer = Racer.create
  visit "/racers/#{racer.pk}/race/#{race_id}"
end

#new_in_tournament(tournament_id) ⇒ Object


77
78
79
80
# File 'lib/controllers/racer_controller.rb', line 77

def new_in_tournament(tournament_id)
  racer = Racer.create
  visit "/racers/#{racer.pk}/#{tournament_id}"
end