class student creation UX

pull/5938/head
Thibault Duplessis 2020-01-18 10:18:48 -06:00
parent 627525b560
commit e5ad9999e1
5 changed files with 34 additions and 28 deletions

View File

@ -88,27 +88,30 @@ final class Clas(
}
def studentForm(id: String) = Secure(_.Teacher) { implicit ctx => me =>
WithClassAndStudents(me, id) { _ => (clas, students) =>
ctx.req.flash.get("created").map(_ split ' ').?? {
case Array(userId, password) =>
env.clas.api.student
.get(clas, userId)
.map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password)))
case _ => fuccess(none)
} flatMap { created =>
env.clas.forms.student.generate map { createForm =>
Ok(
html.clas.student.form(
clas,
students,
env.clas.forms.student.invite,
createForm,
created
if (getBool("gen")) env.clas.nameGenerator() map {
Ok(_)
} else
WithClassAndStudents(me, id) { _ => (clas, students) =>
ctx.req.flash.get("created").map(_ split ' ').?? {
case Array(userId, password) =>
env.clas.api.student
.get(clas, userId)
.map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password)))
case _ => fuccess(none)
} flatMap { created =>
env.clas.forms.student.generate map { createForm =>
Ok(
html.clas.student.form(
clas,
students,
env.clas.forms.student.invite,
createForm,
created
)
)
)
}
}
}
}
}
def studentCreate(id: String) = SecureBody(_.Teacher) { implicit ctx => me =>

View File

@ -140,9 +140,9 @@ object student {
)
)
private def realNameField(form: Form[_])(implicit ctx: Context) =
private def realNameField(form: Form[_], fieldName: String = "realName")(implicit ctx: Context) =
form3.group(
form("realName"),
form(fieldName),
frag("Real name"),
help = frag("Private. Will never be shown to anyone else. Helps you remember who that student is.").some
)(form3.input(_))
@ -216,13 +216,15 @@ Password: ${password.value}""")
),
postForm(cls := "form3", action := routes.Clas.studentCreate(c.id.value))(
form3.group(
create("username"),
create("create-username"),
frag("Lichess username"),
help = a(cls := "name-regen")("Generate a new name").some
help = a(cls := "name-regen", href := s"${routes.Clas.studentForm(c.id.value)}?gen=1")(
"Generate a new username"
).some
)(
form3.input(_)(created.isDefined option autofocus)
),
realNameField(create),
realNameField(create, "create-realName"),
form3.submit(trans.signUp(), icon = none)
)
)

View File

@ -31,8 +31,8 @@ final class ClasForm(
def create: Form[NewStudent] =
Form(
mapping(
"username" -> securityForms.signup.username,
"realName" -> nonEmptyText(maxLength = 100)
"create-username" -> securityForms.signup.username,
"create-realName" -> nonEmptyText(maxLength = 100)
)(NewStudent.apply)(NewStudent.unapply)
)

View File

@ -81,7 +81,6 @@ final class NameGenerator(userRepo: lila.user.UserRepo)(implicit ec: ExecutionCo
"Carabao",
"Cariboo",
"Cat",
"Cattle",
"Cheetah",
"Chicken",
"Chimpanzee",
@ -127,7 +126,6 @@ final class NameGenerator(userRepo: lila.user.UserRepo)(implicit ec: ExecutionCo
"Hornet",
"Horse",
"Hound",
"Human",
"Hyena",
"Impala",
"Insect",

View File

@ -4,5 +4,8 @@ $(function() {
$('table.sortable').each(function() {
tablesort(this, {});
});
$('.name-regen').click(() => location.reload());
$('.name-regen').click(function() {
$.get($(this).attr('href'), name => $('#form3-create-username').val(name));
return false;
});
});