class student creation UX

This commit is contained in:
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 => def studentForm(id: String) = Secure(_.Teacher) { implicit ctx => me =>
WithClassAndStudents(me, id) { _ => (clas, students) => if (getBool("gen")) env.clas.nameGenerator() map {
ctx.req.flash.get("created").map(_ split ' ').?? { Ok(_)
case Array(userId, password) => } else
env.clas.api.student WithClassAndStudents(me, id) { _ => (clas, students) =>
.get(clas, userId) ctx.req.flash.get("created").map(_ split ' ').?? {
.map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password))) case Array(userId, password) =>
case _ => fuccess(none) env.clas.api.student
} flatMap { created => .get(clas, userId)
env.clas.forms.student.generate map { createForm => .map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password)))
Ok( case _ => fuccess(none)
html.clas.student.form( } flatMap { created =>
clas, env.clas.forms.student.generate map { createForm =>
students, Ok(
env.clas.forms.student.invite, html.clas.student.form(
createForm, clas,
created students,
env.clas.forms.student.invite,
createForm,
created
)
) )
) }
} }
} }
}
} }
def studentCreate(id: String) = SecureBody(_.Teacher) { implicit ctx => me => 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( form3.group(
form("realName"), form(fieldName),
frag("Real name"), frag("Real name"),
help = frag("Private. Will never be shown to anyone else. Helps you remember who that student is.").some help = frag("Private. Will never be shown to anyone else. Helps you remember who that student is.").some
)(form3.input(_)) )(form3.input(_))
@ -216,13 +216,15 @@ Password: ${password.value}""")
), ),
postForm(cls := "form3", action := routes.Clas.studentCreate(c.id.value))( postForm(cls := "form3", action := routes.Clas.studentCreate(c.id.value))(
form3.group( form3.group(
create("username"), create("create-username"),
frag("Lichess 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) form3.input(_)(created.isDefined option autofocus)
), ),
realNameField(create), realNameField(create, "create-realName"),
form3.submit(trans.signUp(), icon = none) form3.submit(trans.signUp(), icon = none)
) )
) )

View file

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

View file

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

View file

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