edit tournament WIP
parent
71d1f44eb1
commit
6926165052
|
@ -228,7 +228,7 @@ final class Tournament(
|
|||
def form = Auth { implicit ctx => me =>
|
||||
NoLameOrBot {
|
||||
teamC.teamsIBelongTo(me) map { teams =>
|
||||
Ok(html.tournament.form(forms(me), me, teams))
|
||||
Ok(html.tournament.form.create(forms(me), me, teams))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ final class Tournament(
|
|||
NoLameOrBot {
|
||||
env.team.api.owns(teamId, me.id) map {
|
||||
_ ?? {
|
||||
Ok(html.tournament.form(forms(me, teamId.some), me, Nil))
|
||||
Ok(html.tournament.form.create(forms(me, teamId.some), me, Nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ final class Tournament(
|
|||
implicit val req = ctx.body
|
||||
negotiate(
|
||||
html = forms(me).bindFromRequest.fold(
|
||||
err => BadRequest(html.tournament.form(err, me, teams)).fuccess,
|
||||
err => BadRequest(html.tournament.form.create(err, me, teams)).fuccess,
|
||||
setup =>
|
||||
rateLimitCreation(me, setup.isPrivate, ctx.req) {
|
||||
api.createTournament(setup, me, teams, getUserTeamIds) map { tour =>
|
||||
|
@ -396,6 +396,18 @@ final class Tournament(
|
|||
}
|
||||
}
|
||||
|
||||
def edit(id: String) = Auth { implicit ctx => me =>
|
||||
repo byId id flatMap {
|
||||
_ ?? {
|
||||
case tour if tour.createdBy == me.id && !tour.isFinished =>
|
||||
teamC.teamsIBelongTo(me) map { teams =>
|
||||
Ok(html.tournament.form.edit(tour, form)).fuccess
|
||||
}
|
||||
case tour => Redirect(routes.Tournament.show(tour.id)).fuccess
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val streamerCache = env.memo.cacheApi[Tour.ID, Set[UserModel.ID]](64, "tournament.streamers") {
|
||||
_.refreshAfterWrite(15.seconds)
|
||||
.maximumSize(64)
|
||||
|
|
|
@ -2,18 +2,19 @@ package views.html
|
|||
package tournament
|
||||
|
||||
import play.api.data.{ Field, Form }
|
||||
import play.api.i18n.Lang
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.tournament.{ Condition, DataForm }
|
||||
import lila.tournament.{ Condition, DataForm, Tournament }
|
||||
import lila.user.User
|
||||
|
||||
import controllers.routes
|
||||
|
||||
object form {
|
||||
|
||||
def create(form: Form[_], me: User, teams: List[lila.hub.LightTeam])(implicit ctx: Context) =
|
||||
def create(form: Form[_], me: User, myTeams: List[lila.hub.LightTeam])(implicit ctx: Context) =
|
||||
views.html.base.layout(
|
||||
title = trans.newTournament.txt(),
|
||||
moreCss = cssTag("tournament.form"),
|
||||
|
@ -30,23 +31,7 @@ object form {
|
|||
else trans.createANewTournament()
|
||||
),
|
||||
postForm(cls := "form3", action := routes.Tournament.create)(
|
||||
DataForm.canPickName(me) ?? {
|
||||
form3.group(form("name"), trans.name()) { f =>
|
||||
div(
|
||||
form3.input(f),
|
||||
" ",
|
||||
if (isTeamBattle) "Team Battle" else "Arena",
|
||||
br,
|
||||
small(cls := "form-help")(
|
||||
trans.safeTournamentName(),
|
||||
br,
|
||||
trans.inappropriateNameWarning(),
|
||||
br,
|
||||
trans.emptyTournamentName()
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
nameField(me, form, isTeamBattle),
|
||||
form3.split(
|
||||
form3.checkbox(
|
||||
form("rated"),
|
||||
|
@ -93,7 +78,7 @@ object form {
|
|||
trans.password(),
|
||||
help = trans.makePrivateTournament().some
|
||||
)(form3.input(_)),
|
||||
condition(form, auto = true, teams = teams),
|
||||
condition(form, auto = true, teams = myTeams),
|
||||
input(tpe := "hidden", name := form("berserkable").name, value := "false"), // hack allow disabling berserk
|
||||
form3.group(
|
||||
form("startDate"),
|
||||
|
@ -113,7 +98,9 @@ object form {
|
|||
)
|
||||
}
|
||||
|
||||
def edit(tour: Tournament, form: Form[_], me: User)(implicit ctx: Context) = {
|
||||
def edit(tour: Tournament, form: Form[_], me: User, myTeams: List[lila.hub.LightTeam])(
|
||||
implicit ctx: Context
|
||||
) =
|
||||
views.html.base.layout(
|
||||
title = tour.name(),
|
||||
moreCss = cssTag("tournament.form"),
|
||||
|
@ -122,11 +109,12 @@ object form {
|
|||
jsTag("tournamentForm.js")
|
||||
)
|
||||
) {
|
||||
val isTeamBattle = form("teamBattleByTeam").value.nonEmpty
|
||||
main(cls := "page-small")(
|
||||
div(cls := "tour__form box box-pad")(
|
||||
h1(tour.name()),
|
||||
postForm(cls := "form3", action := routes.Tournament.update(tour.id))(
|
||||
nameField(form),
|
||||
nameField(me, form, isTeamBattle),
|
||||
form3.split(
|
||||
form3.checkbox(
|
||||
form("rated"),
|
||||
|
@ -173,7 +161,7 @@ object form {
|
|||
trans.password(),
|
||||
help = trans.makePrivateTournament().some
|
||||
)(form3.input(_)),
|
||||
condition(form, auto = true, teams = teams),
|
||||
condition(form, auto = true, teams = myTeams),
|
||||
input(tpe := "hidden", name := form("berserkable").name, value := "false"), // hack allow disabling berserk
|
||||
form3.group(
|
||||
form("startDate"),
|
||||
|
@ -184,8 +172,8 @@ object form {
|
|||
),
|
||||
isTeamBattle option form3.hidden(form("teamBattleByTeam")),
|
||||
form3.actions(
|
||||
a(href := routes.Tournament.home())(trans.cancel()),
|
||||
form3.submit(trans.createANewTournament(), icon = "g".some)
|
||||
a(href := routes.Tournament.show(tour.id))(trans.cancel()),
|
||||
form3.submit(trans.save(), icon = "g".some)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
@ -193,24 +181,24 @@ object form {
|
|||
)
|
||||
}
|
||||
|
||||
private def nameField(me: User, form: Form[_]) =
|
||||
DataForm.canPickName(me) ?? {
|
||||
form3.group(form("name"), trans.name()) { f =>
|
||||
div(
|
||||
form3.input(f),
|
||||
" ",
|
||||
if (isTeamBattle) "Team Battle" else "Arena",
|
||||
private def nameField(me: User, form: Form[_], isTeamBattle: Boolean)(implicit ctx: Context) =
|
||||
DataForm.canPickName(me) ?? {
|
||||
form3.group(form("name"), trans.name()) { f =>
|
||||
div(
|
||||
form3.input(f),
|
||||
" ",
|
||||
if (isTeamBattle) "Team Battle" else "Arena",
|
||||
br,
|
||||
small(cls := "form-help")(
|
||||
trans.safeTournamentName(),
|
||||
br,
|
||||
small(cls := "form-help")(
|
||||
trans.safeTournamentName(),
|
||||
br,
|
||||
trans.inappropriateNameWarning(),
|
||||
br,
|
||||
trans.emptyTournamentName()
|
||||
)
|
||||
trans.inappropriateNameWarning(),
|
||||
br,
|
||||
trans.emptyTournamentName()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private def autoField(auto: Boolean, field: Field)(visible: Field => Frag) = frag(
|
||||
if (auto) form3.hidden(field) else visible(field)
|
||||
|
|
Loading…
Reference in New Issue