lila/app/views/swiss/form.scala

211 lines
6.7 KiB
Scala
Raw Normal View History

2020-04-29 10:31:34 -06:00
package views.html.swiss
2020-10-05 06:39:25 -06:00
import controllers.routes
2020-04-29 10:31:34 -06:00
import play.api.data.Form
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.hub.LightTeam.TeamID
2020-10-05 06:39:25 -06:00
import lila.swiss.{ Swiss, SwissCondition, SwissForm }
import lila.tournament.TournamentForm
2020-04-29 10:31:34 -06:00
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"),
2020-09-21 10:01:43 -06:00
moreJs = jsModule("tourForm")
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,
form3.split(fields.description, fields.position),
2020-05-05 19:26:39 -06:00
form3.split(
fields.roundInterval,
fields.startsAt
),
2020-05-23 21:18:43 -06:00
form3.split(
2020-07-17 07:13:26 -06:00
fields.chatFor,
fields.password
2020-05-23 21:18:43 -06:00
),
2020-10-05 06:39:25 -06:00
condition(form, fields, swiss = none),
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"),
2020-09-21 10:01:43 -06:00
moreJs = jsModule("tourForm")
2020-05-04 00:31:50 -06:00
) {
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,
2020-10-22 14:06:42 -06:00
form3.split(fields.description, fields.position),
2020-05-05 19:26:39 -06:00
form3.split(
fields.roundInterval,
swiss.isCreated option fields.startsAt
),
2020-05-23 21:18:43 -06:00
form3.split(
2020-07-17 07:13:26 -06:00
fields.chatFor,
fields.password
2020-05-23 21:18:43 -06:00
),
2020-10-05 06:39:25 -06:00
condition(form, fields, swiss = swiss.some),
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-10-05 06:39:25 -06:00
private def condition(form: Form[_], fields: SwissFields, swiss: Option[Swiss])(implicit ctx: Context) =
frag(
form3.split(
form3.group(form("conditions.nbRatedGame.nb"), frag("Minimum rated games"), half = true)(
form3.select(_, SwissCondition.DataForm.nbRatedGameChoices)
),
(ctx.me.exists(_.hasTitle) || isGranted(_.ManageTournament)) ?? {
form3.checkbox(
form("conditions.titled"),
frag("Only titled players"),
help = frag("Require an official title to join the tournament").some,
half = true
)
}
),
form3.split(
form3.group(form("conditions.minRating.rating"), frag("Minimum rating"), half = true)(
form3.select(_, SwissCondition.DataForm.minRatingChoices)
),
form3.group(form("conditions.maxRating.rating"), frag("Maximum weekly rating"), half = true)(
form3.select(_, SwissCondition.DataForm.maxRatingChoices)
)
)
)
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),
small(cls := "form-help")(
trans.safeTournamentName(),
br,
trans.inappropriateNameWarning(),
br,
trans.emptyTournamentName()
)
)
}
2020-04-29 11:43:52 -06:00
def nbRounds =
2020-05-23 21:18:43 -06:00
form3.group(
form("nbRounds"),
"Number of rounds",
help = raw("An odd number of rounds allows optimal color balance.").some,
half = true
)(
2020-04-29 11:43:52 -06:00
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)(
2020-08-21 14:40:37 -06:00
form3.select(_, TournamentForm.clockIncrementChoices)
2020-04-29 10:31:34 -06:00
)
)
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"),
2020-08-25 06:50:39 -06:00
help = frag(
"Anything special you want to tell the participants? Try to keep it short. Markdown links are available: [name](https://url)"
).some,
half = true
2020-08-25 06:50:39 -06:00
)(form3.textarea(_)(rows := 4))
def position =
form3.group(
form("position"),
trans.startPosition(),
klass = "position",
half = true,
help = views.html.tournament.form.positionInputHelp.some
)(form3.input(_))
2020-04-29 10:31:34 -06:00
def startsAt =
form3.group(
form("startsAt"),
2020-05-05 19:26:39 -06:00
frag("Tournament start date"),
help = frag("In your own local timezone").some,
2020-05-05 19:26:39 -06:00
half = true
2020-04-29 10:31:34 -06:00
)(form3.flatpickr(_))
2020-05-23 21:18:43 -06:00
def chatFor =
form3.group(form("chatFor"), frag("Tournament chat"), half = true) { f =>
form3.select(
f,
Seq(
Swiss.ChatFor.NONE -> "No chat",
Swiss.ChatFor.LEADERS -> "Only team leaders",
Swiss.ChatFor.MEMBERS -> "Only team members",
Swiss.ChatFor.ALL -> "All Lichess players"
)
)
}
2020-07-17 07:13:26 -06:00
def password =
form3.group(
form("password"),
trans.password(),
help = trans.makePrivateTournament().some,
half = true
)(form3.input(_)(autocomplete := "off"))
2020-04-29 10:31:34 -06:00
}