lila/app/views/swiss/form.scala

145 lines
4.4 KiB
Scala
Raw Normal View History

2020-04-29 10:31:34 -06:00
package views.html.swiss
import play.api.data.Form
import controllers.routes
import lila.api.Context
import lila.app.templating.Environment._
import lila.tournament.{ DataForm => TourForm }
2020-05-04 00:31:50 -06:00
import lila.swiss.{ Swiss, SwissForm }
2020-04-29 10:31:34 -06:00
import lila.app.ui.ScalatagsTemplate._
import lila.hub.LightTeam.TeamID
object form {
def create(form: Form[_], teamId: TeamID)(implicit ctx: Context) =
views.html.base.layout(
title = "New Swiss tournament",
2020-04-29 11:43:52 -06:00
moreCss = cssTag("swiss.form"),
moreJs = frag(
flatpickrTag,
jsTag("tournamentForm.js")
)
2020-04-29 10:31:34 -06:00
) {
val fields = new SwissFields(form)
main(cls := "page-small")(
2020-04-29 11:43:52 -06:00
div(cls := "swiss__form tour__form box box-pad")(
2020-04-29 10:31:34 -06:00
h1("New Swiss tournament"),
postForm(cls := "form3", action := routes.Swiss.create(teamId))(
2020-04-29 11:43:52 -06:00
form3.split(fields.name, fields.nbRounds),
2020-04-29 10:31:34 -06:00
form3.split(fields.rated, fields.variant),
fields.clock,
fields.description,
2020-05-05 19:26:39 -06:00
form3.split(
fields.roundInterval,
fields.startsAt
),
2020-05-04 00:31:50 -06:00
form3.globalError(form),
2020-04-29 10:31:34 -06:00
form3.actions(
a(href := routes.Team.show(teamId))(trans.cancel()),
form3.submit(trans.createANewTournament(), icon = "g".some)
)
)
)
)
}
2020-05-04 00:31:50 -06:00
def edit(swiss: Swiss, form: Form[_])(implicit ctx: Context) =
views.html.base.layout(
title = swiss.name,
moreCss = cssTag("swiss.form"),
moreJs = frag(
flatpickrTag,
jsTag("tournamentForm.js")
)
) {
val fields = new SwissFields(form)
main(cls := "page-small")(
div(cls := "swiss__form box box-pad")(
h1("Edit ", swiss.name),
postForm(cls := "form3", action := routes.Swiss.update(swiss.id.value))(
form3.split(fields.name, fields.nbRounds),
form3.split(fields.rated, fields.variant),
fields.clock,
fields.description,
2020-05-05 19:26:39 -06:00
form3.split(
fields.roundInterval,
swiss.isCreated option fields.startsAt
),
2020-05-04 00:31:50 -06:00
form3.globalError(form),
form3.actions(
a(href := routes.Swiss.show(swiss.id.value))(trans.cancel()),
form3.submit(trans.save(), icon = "g".some)
)
),
postForm(cls := "terminate", action := routes.Swiss.terminate(swiss.id.value))(
submitButton(dataIcon := "j", cls := "text button button-red confirm")(
"Cancel the tournament"
)
)
)
)
}
2020-04-29 10:31:34 -06:00
}
final private class SwissFields(form: Form[_])(implicit ctx: Context) {
def name =
form3.group(form("name"), trans.name()) { f =>
div(
form3.input(f),
br,
small(cls := "form-help")(
trans.safeTournamentName(),
br,
trans.inappropriateNameWarning(),
br,
trans.emptyTournamentName()
)
)
}
2020-04-29 11:43:52 -06:00
def nbRounds =
form3.group(form("nbRounds"), "Number of rounds", half = true)(
form3.input(_, typ = "number")
)
2020-04-29 10:31:34 -06:00
2020-05-05 22:11:15 -06:00
def rated =
2020-05-11 14:20:46 -06:00
frag(
form3.checkbox(
form("rated"),
trans.rated(),
help = raw("Games are rated<br>and impact players ratings").some
),
st.input(tpe := "hidden", st.name := form("rated").name, value := "false") // hack allow disabling rated
2020-05-05 22:11:15 -06:00
)
2020-04-29 10:31:34 -06:00
def variant =
form3.group(form("variant"), trans.variant(), half = true)(
2020-04-29 11:43:52 -06:00
form3.select(_, translatedVariantChoicesWithVariants(_.key).map(x => x._1 -> x._2))
2020-04-29 10:31:34 -06:00
)
def clock =
form3.split(
form3.group(form("clock.limit"), trans.clockInitialTime(), half = true)(
2020-04-29 11:43:52 -06:00
form3.select(_, SwissForm.clockLimitChoices)
2020-04-29 10:31:34 -06:00
),
form3.group(form("clock.increment"), trans.clockIncrement(), half = true)(
form3.select(_, TourForm.clockIncrementChoices)
)
)
2020-05-05 19:26:39 -06:00
def roundInterval =
form3.group(form("roundInterval"), frag("Interval between rounds"), half = true)(
form3.select(_, SwissForm.roundIntervalChoices)
)
2020-04-29 10:31:34 -06:00
def description =
form3.group(
form("description"),
frag("Tournament description"),
help = frag("Anything special you want to tell the participants? Try to keep it short.").some
)(form3.textarea(_)(rows := 2))
def startsAt =
form3.group(
form("startsAt"),
2020-05-05 19:26:39 -06:00
frag("Tournament start date"),
half = true
2020-04-29 10:31:34 -06:00
)(form3.flatpickr(_))
}