Created
June 3, 2010 12:53
-
-
Save zombor/423843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>{{action}} Tournament</h2> | |
{{#errors}}{{errors}}{{/errors}} | |
<form method="post"> | |
<ul> | |
<li><label for="title">Title</label> <input name="title" id="title" value="{{title}}" /></li> | |
<li> | |
<label for="format_id">Format</label> | |
<select name="format_id" if="format_id"> | |
{{#formats}}<option value="{{value}}"{{#selected}} selected="selected"{{/selected}}>{{name}}</option> | |
{{/formats}} | |
</select> | |
</li> | |
<li> | |
<label for="max_players">Max players</label> | |
<select name="max_players" id="max_players"> | |
{{#max_players}}<option value="{{value}}"{{#selected}} selected="selected"{{/selected}}>{{name}}</option> | |
{{/max_players}} | |
</select> | |
</li> | |
<li> | |
<label for="round_length">Round length</label> | |
<select name="round_length" id="round_length"> | |
{{#round_length}}<option value="{{value}}"{{#selected}} selected="selected"{{/selected}}>{{name}}</option> | |
{{/round_length}} | |
</select> | |
</li> | |
<li> | |
<label for="num_rounds">Number of rounds</label> | |
<select name="num_rounds" id="num_rounds"> | |
{{#num_rounds}}<option value="{{value}}"{{#selected}} selected="selected"{{/selected}}>{{name}}</option> | |
{{/num_rounds}} | |
</select> | |
</li> | |
<li> | |
<label for="k_value">K-Value</label> | |
<select name="k_value" id="k_value"> | |
{{#k_value}}<option value="{{value}}"{{#selected}} selected="selected"{{/selected}}>{{name}}</option> | |
{{/k_value}} | |
</select> | |
</li> | |
<li> | |
<label for="cost">Cost</label> | |
<input name="cost" id="cost" value="{{cost}}" /> | |
</li> | |
<li> | |
<label for="prize">Prize</label> | |
<textarea name="prize" id="prize">{{prize}}</textarea> | |
</li> | |
<li> | |
<div class="label"></div> | |
<input type="submit" value="{{action}} Tournament"> | |
</li> | |
</ul> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Picombo | |
module Stache | |
class Tournament_Form < Mustache | |
self.template = File.open(Picombo::Core.find_file('views', 'tournament/form', true, 'mustache').shift).read | |
@tournament = nil | |
@action = 'Create' | |
def tournament=(tournament) | |
@tournament = tournament | |
end | |
def action=(action) | |
@action = action | |
end | |
def action | |
@action | |
end | |
def title | |
@tournament.title | |
end | |
def formats | |
formats = [] | |
Picombo::Models::Format.all.each do |format| | |
formats << { | |
:value => format.id, | |
:name => format.name, | |
:selected => format.id == @tournament.format.id | |
} | |
end | |
formats | |
end | |
def max_players | |
max_players = [] | |
(1..16).to_a.each do |num| | |
max_players << { | |
:value => num, | |
:name => num, | |
:selected => num == @tournament.max_players | |
} | |
end | |
max_players | |
end | |
def round_length | |
[ | |
{:value => 24, :name => '1 Day', :selected => 24 == @tournament.round_length}, | |
{:value => 48, :name => '2 Days', :selected => 48 == @tournament.round_length}, | |
{:value => 72, :name => '3 Days', :selected => 72 == @tournament.round_length}, | |
{:value => 96, :name => '4 Days', :selected => 96 == @tournament.round_length}, | |
{:value => 120, :name => '5 Days', :selected => 120 == @tournament.round_length}, | |
{:value => 144, :name => '6 Days', :selected => 144 == @tournament.round_length}, | |
{:value => 168, :name => '7 Days', :selected => 168 == @tournament.round_length}, | |
] | |
end | |
def num_rounds | |
[ | |
{:value => 0, :name => 'Auto', :selected => 0 == @tournament.num_rounds}, | |
{:value => 3, :name => '3', :selected => 3 == @tournament.num_rounds}, | |
{:value => 4, :name => '4', :selected => 4 == @tournament.num_rounds}, | |
{:value => 5, :name => '5', :selected => 5 == @tournament.num_rounds}, | |
] | |
end | |
def k_value | |
[ | |
{:value => 8, :name => '8', :selected => 8 == @tournament.k_value}, | |
{:value => 16, :name => '16', :selected => 16 == @tournament.k_value}, | |
{:value => 20, :name => '20', :selected => 20 == @tournament.k_value}, | |
{:value => 24, :name => '24', :selected => 24 == @tournament.k_value}, | |
{:value => 28, :name => '28', :selected => 28 == @tournament.k_value}, | |
{:value => 32, :name => '32', :selected => 32 == @tournament.k_value}, | |
{:value => 40, :name => '40', :selected => 40 == @tournament.k_value}, | |
{:value => 48, :name => '48', :selected => 40 == @tournament.k_value}, | |
] | |
end | |
def cost | |
@tournament.cost | |
end | |
def prize | |
@tournament.prize | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Picombo | |
module Controllers | |
class Tournament < Picombo::Controllers::Template | |
def initialize | |
super | |
end | |
def index | |
@@template[:body] = Picombo::Stache::Tournament_Index.render | |
end | |
def create | |
tournament = Picombo::Models::Tournament.new | |
body = Picombo::Stache::Tournament_Form.new | |
body.tournament = tournament | |
body.action = 'Create' | |
@@template[:body] = body.render | |
if Picombo::Input.instance.post.length > 0 | |
post = Picombo::Input.instance.post | |
tournament.title = post['title'] | |
tournament.format_id = post['format_id'] | |
tournament.max_players = post['max_players'] | |
tournament.round_length = post['round_length'] | |
tournament.num_rounds = post['num_rounds'] | |
tournament.k_value = post['k_value'] | |
tournament.cost = post['cost'] | |
tournament.prize = post['prize'] | |
tournament.user_id = 1 | |
tournament.save | |
@@template[:body] = Picombo::Stache::Tournament_Form_Success.render | |
end | |
end | |
def edit | |
id = Picombo::Input.instance.get('id') | |
tournament = Picombo::Models::Tournament.get(id) | |
body = Picombo::Stache::Tournament_Form.new | |
body.tournament = tournament | |
body.action = 'Update' | |
@@template[:body] = body.render | |
if Picombo::Input.instance.post.length > 0 | |
post = Picombo::Input.instance.post | |
tournament.title = post['title'] | |
tournament.format_id = post['format_id'] | |
tournament.max_players = post['max_players'] | |
tournament.round_length = post['round_length'] | |
tournament.num_rounds = post['num_rounds'] | |
tournament.k_value = post['k_value'] | |
tournament.cost = post['cost'] | |
tournament.prize = post['prize'] | |
tournament.user_id = 1 | |
tournament.save | |
@@template[:body] = Picombo::Stache::Tournament_Form_Success.render | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment