diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 02:46:11 -0400 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 02:46:11 -0400 |
commit | 6c615c4eaa973d83778fc6d34157f823880765f1 (patch) | |
tree | 112cae9c020e34fdbd3620eea13b3c931e24e71c /app/views | |
parent | 353e0b387b8e76d407f9451c236efbb4bd3a19ef (diff) |
Work on the tournament creation page
Diffstat (limited to 'app/views')
-rw-r--r-- | app/views/tournaments/_form.html.erb | 161 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 23 | ||||
-rw-r--r-- | app/views/tournaments/_stages.html.erb | 36 | ||||
-rw-r--r-- | app/views/tournaments/new.html.erb | 19 |
4 files changed, 102 insertions, 137 deletions
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 7127d38..78ceca4 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -1,61 +1,102 @@ -<%= form_for(@tournament) do |f| %> - <% if @tournament.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2> - - <ul> - <% @tournament.errors.full_messages.each do |msg| %> - <li><%= msg %></li> - <% end %> - </ul> - </div> - <% end %> - - <div class="field"> - <%= f.label :game_id %><br> - <%= f.text_field :game_id %> - </div> - <div class="field"> - <%= f.label :status %><br> - <%= f.number_field :status %> - </div> - <div class="field"> - <%= f.label :name %><br> - <%= f.text_field :name %> - </div> - <div class="field"> - <%= f.label :min_players_per_team %><br> - <%= f.number_field :min_players_per_team %> - </div> - <div class="field"> - <%= f.label :max_players_per_team %><br> - <%= f.number_field :max_players_per_team %> - </div> - <div class="field"> - <%= f.label :min_teams_per_match %><br> - <%= f.number_field :min_teams_per_match %> - </div> - <div class="field"> - <%= f.label :max_teams_per_match %><br> - <%= f.number_field :max_teams_per_match %> - </div> - <div class="field"> - <%= f.label :set_rounds %><br> - <%= f.number_field :set_rounds %> - </div> - <div class="field"> - <%= f.label :randomized_teams %><br> - <%= f.check_box :randomized_teams %> - </div> - <div class="field"> - <%= f.label :sampling_method %><br> - <%= f.text_field :sampling_method %> - </div> - <div class="field"> - <%= f.label :scoring_method %><br> - <%= f.text_field :scoring_method %> - </div> - <div class="actions"> - <%= f.submit %> - </div> +<%= form_for(@tournament, + url: (@tournament.game.nil? ? new_tournament_path : tournaments_path), + method: (@tournament.game.nil? ? "get" : "post")) do |f| %> + <%= render "common/error_messages", :target => @tournament %> + + <fieldset><legend>Attributes</legend> + <p> + <%= f.label :game_id, "Select a game type" %> + <%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %> + </p> + + <% if @tournament.game.nil? %> + <%= submit_tag("Select", :class => "btn") %> + </fieldset> + <% else %> + + <p> + <%= f.label :name %> + <%= f.text_field :name %> + </p> + + <table><tbody> + <tr> + <td></td> + <th>Minimum</th> + <th>Maximum</th></tr> + <tr> + <th>Players per team</th> + <td><%= f.text_field(:min_players_per_team, type: :number, min: 1) %></td> + <td><%= f.text_field(:max_players_per_team, type: :number, min: 1) %></td> + </tr> + <tr> + <th>Teams per match</th> + <td><%= f.text_field(:min_teams_per_match, type: :number, min: 1) %></td> + <td><%= f.text_field(:max_teams_per_match, type: :number, min: 1) %></td> + </tr> + </tbody></table> + + <p> + <%= f.label :scoring_method %> + <%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize, method]}) %> + </p> + + <p> + <%= f.label :sampling_method %> + <%= f.select(:sampling_method, @tournament.sampling_methods.map{|method| [method.humanize, method]}) %> + </p> + + </fieldset> + + <fieldset><legend>Settings</legend> + <%= fields_for "tournament[settings]", @tournament.settings do |setting_fields| %> + <% (@tournament.settings.empty? ? @tournament.game.settings : @tournament.settings).each do |setting| %><p> + <% name = setting.name.parameterize.underscore %> + <%= setting_fields.label name %> + <br> + <% case setting.vartype %> + <% when 0 %> + <%= setting_fields.text_field( name ) %> + <% when 1 %> + <%= setting_fields.text_area( name ) %> + <% when 2 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= setting_fields.radio_button( name, option ) %><%= option %></label></li> + <% end %> + </ul> + <% when 3 %> + <ul> + <% setting.type_opt.split(',').each do |option|%> + <li><label><%= check_box_tag(name, value = option, checked = false, options = {}) %><%= option %></label></li> + <% end %> + </ul> + <% when 4 %> + <%= setting_fields.radio_button( name, "true" ) %> True + <%= setting_fields.radio_button( name, "false" ) %> False + <% when 5 %> + <%= setting_fields.select( name, setting.type_opt.split(',') ) %> + <% end %> + </p><% end %> + <% end %> + </fieldset> + + <fieldset><legend>Stages</legend> + <label for="num_stages">Number of tournament stages</label> + <input type="number" name="num_stages" min="1"> + <% for i in 1..(params[:num_stages].to_i) do %> + <%= fields_for "tournament[stages][#{i}]", @tournament.stages do |stage_fields| %> + <fieldset><legend>Stage <%= i %></legend> + <%= stage_fields.label :scheduling_method %> + <%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize, method]}) %> + <%= stage_fields.label :seeding_method %> + <%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize, method]}) %> + </fieldset> + <% end %> + <% end %> + </fieldset> + <%= f.submit %> + + <%# render 'stages' %> + <% end %> <% end %> diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb deleted file mode 100644 index e89550e..0000000 --- a/app/views/tournaments/_selected.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<%= form_for(@tournament) do |f| %> - <%= render "common/error_messages", :target => @tournament %> - <%= f.hidden_field(:game_id) %> - - <% @tournament.attributes.each do |name, value| %> - <% if (name == "randomized_teams") or(name == "max_teams_per_match") or (name == "max_players_per_team") or (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") or (name == "set_rounds") %> - <% next %> - <% end %> - <p> - <%= f.label name %><br> - <% unless @tournament.game.attributes[name].nil? %> - <% if name == "sampling_method" %> - <%= f.select( name, Tournament.sampling_methods) %> - <% else %> - <%= f.text_field(name, :value => @tournament.game.attributes[name] ) %> - <% end %> - <% else %> - <%= f.select( name, Tournament.scoring_methods) %> - <% end %> - </p> - <% end %> - <%= f.submit %> -<% end %> diff --git a/app/views/tournaments/_stages.html.erb b/app/views/tournaments/_stages.html.erb deleted file mode 100644 index 20c7b3f..0000000 --- a/app/views/tournaments/_stages.html.erb +++ /dev/null @@ -1,36 +0,0 @@ - <%= form_for(@tournament) do |f| %> - <%= render "common/error_messages", :target => @tournament %> - <%= f.hidden_field(:game_id) %> - <%= fields_for "tournament[settings]", @tournament.settings do |setting_fields| %> - - <% @tournament.game.settings.each do |setting| %> - <p> - <%= setting_fields.label setting.name %> - <br> - <% case setting.vartype %> - <% when 0 %> - <%= setting_fields.text_field( setting.name ) %> - <% when 1 %> - <%= setting_fields.text_area( setting.name ) %> - <% when 2 %> - <% setting.type_opt.split(',').each do |option|%> - <%= setting_fields.radio_button( setting.name, option ) %> <%= option %> <br> - <% end %> - <% when 3 %> - <% setting.type_opt.split(',').each do |option|%> - <%= check_box_tag(setting.name, value = option, checked = false, options = {}) %> <%= option %> <br> - <% end %> - <% when 4 %> - <%# setting_fields.label "true" %> - <%= setting_fields.radio_button( setting.name, "true" ) %> True - <%# setting_fields.label "false" %> - <%= setting_fields.radio_button( setting.name, "false" ) %> False - <% when 5 %> - <%= setting_fields.select( setting.name, setting.type_opt.split(',') ) %> - <% end %> - <% end %> - </p> - <% end %> - - <%= f.submit %> -<% end %> diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb index af74ea8..9c741e0 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,22 +1,5 @@ <h1>New Tournament</h1> -<%= form_tag(new_tournament_path, method: "get") do %> - <%= select_tag('tournament[game_id]', - options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id), - :prompt => "Select a Game Type") %> - <%= submit_tag("Select", :class => "btn") %> -<% end %> - -<div id='ajax-form'> - <% if not @tournament.game.nil? %> - <%= render 'selected' %> - <% end %> -</div> - -<div id='ajax-form'> - <% if not @tournament.game.nil? %> - <%= render 'stages' %> - <% end %> -</div> +<%= render 'form' %> <%= link_to 'Back', tournaments_path %> |