summaryrefslogtreecommitdiff
path: root/app/views/tournaments/_form.html.erb
blob: 353ec77113e5e0d9899e75d815426d1143e3c382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
137
138
139
140
<%
# Copyright (C) 2014 Andrew Murrell
# Copyright (C) 2014 Davis Webb
# Copyright (C) 2014 Guntas Grewal
# Copyright (C) 2014 Luke Shumaker
# Copyright (C) 2014 Nathaniel Foy
# Copyright (C) 2014 Tomer Kimia
#
# This file is part of Leaguer.
#
# Leaguer is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Leaguer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the Affero GNU General Public License
# along with Leaguer.  If not, see <http://www.gnu.org/licenses/>.
%>
<%= render "common/error_messages", :target => @tournament %>
<fieldset>
	<legend>Basic information</legend>
	<%= form_for(@tournament, url: new_tournament_path, method: "get") do |f| %>
		<div class="field">
			<%= f.label :game_id, "Select a Game Type" %>
			<%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %>
		</div>
		<div class="field">
			<label for="num_stages">Number of Tournament Stages</label>
			<input type="number" id="num_stages" name="num_stages" min="1" value="<%= params[:num_stages].to_i %>">
		</div>
		<% if @tournament.game %>
			<%= f.submit("Update (Will reset the rest of the form)", class: "btn-danger") %>
		<% else %>
			<%= f.submit("Submit") %>
		<% end %>
	<% end %>

</fieldset>
<% if @tournament.game %>
	<%= form_for(@tournament, url: tournaments_path, method: "post") do |f| %>
		<fieldset>
			<legend>Attributes</legend>

			<%= f.hidden_field(:game_id) %>
			<div class="field">
				<%= f.label :name %>
				<%= f.text_field :name %>
			</div>

			<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>

			<div class="field">
				<%= f.label :scoring_method, :scoring_method.to_s.titleize %>
				<%= f.select(:scoring_method, @tournament.scoring_methods.map{|method| [method.humanize.titleize, method]}) %>
			</div>
		</fieldset>

		<fieldset>
			<legend>Settings</legend>
			<%= f.fields_for :settings do |setting_fields| %>
				<% @tournament.tournament_settings.each do |setting| %>
					<div class="field">
						<%= setting_fields.label setting.name, setting.name.to_s.titleize %>
						<br>
						<% case setting.vartype %>
						<% when 0 %>
							<%= setting_fields.text_field( setting.name ) %>
						<% when 1 %>
							<%= setting_fields.text_area( setting.name ) %>
						<% when 2 %>
							<ul>
							<% setting.type_opt.split(',').each do |option|%>
								<li><label><%= setting_fields.radio_button( setting.name, option ) %><%= option.humanize.titleize %></label></li>
							<% end %>
							</ul>
						<% when 3 %>
							<ul>
							<% setting.type_opt.split(',').each do |option|%>
								<li><label><%= check_box_tag("tournament[settings][#{setting.name}][]", option, setting.value.split(',').include?(option)) %><%= option.humanize.titleize %></label></li>
							<% end %>
							</ul>
						<% when 4 %>
							<%= setting_fields.radio_button( setting.name, "true" ) %> <b>True</b>
							<%= setting_fields.radio_button( setting.name, "false" ) %> <b>False</b>
						<% when 5 %>
							<%= setting_fields.select( setting.name, setting.type_opt.split(',').collect {|opt| opt.humanize.titleize} ) %>
						<% end %>
					</div>
				<% end %>
			<% end %>
		</fieldset>

		<%= f.fields_for :stages do |stages_fields| %>
			<fieldset>
				<legend>Stages</legend>
				<% for i in 1..(params[:num_stages].to_i) do %>
					<%= stages_fields.fields_for i.to_s do |stage_fields| %>
					<fieldset>
						<legend>Stage <%= i %></legend>
						<div class="field">
							<%= stage_fields.label :scheduling_method, :scheduling_method.to_s.titleize %>
							<%= stage_fields.select(:scheduling_method, @tournament.scheduling_methods.map{|method| [method.humanize.titleize, method]}) %>
						</div>
						<div class="field">
							<%= stage_fields.label :seeding_method, :seeding_method.to_s.titleize %>
							<%= stage_fields.select(:seeding_method, @tournament.seeding_methods.map{|method| [method.humanize.titleize, method]}) %>
						</div>
					</fieldset>
					<% end %>
				<% end %>
			</fieldset>
		<% end %>

		<%= f.submit %>

	<% end %>
<% end %>