Add editing user stuff.

This commit is contained in:
takezoe
2013-06-04 13:22:57 +09:00
parent dd7fef93fc
commit b13019c8be
2 changed files with 32 additions and 22 deletions

View File

@@ -8,7 +8,7 @@ class UsersController extends UsersControllerBase with AccountService
trait UsersControllerBase extends ControllerBase { self: AccountService => trait UsersControllerBase extends ControllerBase { self: AccountService =>
case class NewUserForm(userName: String, password: String, mailAddress: String, userType: Int, url: Option[String]) case class UserForm(userName: String, password: String, mailAddress: String, userType: Int, url: Option[String])
val newForm = mapping( val newForm = mapping(
"userName" -> trim(label("Username" , text(required, maxlength(100), unique))), "userName" -> trim(label("Username" , text(required, maxlength(100), unique))),
@@ -16,10 +16,16 @@ trait UsersControllerBase extends ControllerBase { self: AccountService =>
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))), "mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
"userType" -> trim(label("User Type" , number())), "userType" -> trim(label("User Type" , number())),
"url" -> trim(label("URL" , optional(text(maxlength(200))))) "url" -> trim(label("URL" , optional(text(maxlength(200)))))
)(NewUserForm.apply) )(UserForm.apply)
val editForm = mapping(
"userName" -> trim(label("Username" , text())),
"password" -> trim(label("Password" , text(required, maxlength(100)))),
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
"userType" -> trim(label("User Type" , number())),
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
)(UserForm.apply)
get("/admin/users"){ get("/admin/users"){
admin.html.userlist(getAllUsers()) admin.html.userlist(getAllUsers())
} }
@@ -43,13 +49,16 @@ trait UsersControllerBase extends ControllerBase { self: AccountService =>
redirect("/admin/users") redirect("/admin/users")
} }
// get("/admin/users/:name/_edit"){ get("/admin/users/:userName/_edit"){
// val userName = params("userName")
// } admin.html.useredit(getAccountByUserName(userName))
// }
// post("/admin/users/:name/_edit"){
// post("/admin/users/:name/_edit", editForm){ form =>
// } // TODO Update Account
redirect("/admin/users")
}
def unique: Constraint = new Constraint(){ def unique: Constraint = new Constraint(){
def validate(name: String, value: String): Option[String] = def validate(name: String, value: String): Option[String] =

View File

@@ -1,38 +1,39 @@
@(account: Option[model.Account])(implicit context: app.Context) @(account: Option[model.Account])(implicit context: app.Context)
@import context._ @import context._
@html.main("New User"){ @html.main(if(account.isEmpty) "New User" else "Update User"){
<form method="POST" action="@path/admin/users/_new" validate="true"> <form method="POST" action="@if(account.isEmpty){@path/admin/users/_new} else {@path/admin/users/@account.get.userName/_edit}" validate="true">
<fieldset> <fieldset>
<label for="userName"><strong>Usrename</strong></label> <label for="userName"><strong>Username</strong></label>
<input type="text" name="userName" id="userName" /> <input type="text" name="userName" id="userName" value="@account.map(_.userName)"@if(account.isDefined){ readonly}/>
<span id="error-userName" class="error"></span> <span id="error-userName" class="error"></span>
</fieldset> </fieldset>
<fieldset> <fieldset>
<label for="password"><strong>Password</strong></label> <label for="password"><strong>Password</strong></label>
<input type="password" name="password" id="password" /> <input type="password" name="password" id="password" value="@account.map(_.password)"/>
<span id="error-password" class="error"></span> <span id="error-password" class="error"></span>
</fieldset> </fieldset>
<fieldset> <fieldset>
<label for="mailAddress"><strong>Mail Address</strong></label> <label for="mailAddress"><strong>Mail Address</strong></label>
<input type="text" name="mailAddress" id="mailAddress" /> <input type="text" name="mailAddress" id="mailAddress" value="@account.map(_.mailAddress)"/>
<span id="error-mailAddress" class="error"></span> <span id="error-mailAddress" class="error"></span>
</fieldset> </fieldset>
<fieldset> <fieldset>
<label><strong>User Type</strong></label> <label><strong>User Type</strong></label>
<label for="userType_Normal"> <label for="userType_Normal">
<input type="radio" name="userType" id="userType_Normal" value="0" selected/> Normal <input type="radio" name="userType" id="userType_Normal" value="0"@if(account.isEmpty || account.get.userType==0){ checked}/> Normal
</label> </label>
<label for="userType_Admin"> <label for="userType_Admin">
<input type="radio" name="userType" id="userType_Admin" value="1"/> Administrator <input type="radio" name="userType" id="userType_Admin" value="1"@if(account.isDefined && account.get.userType==1){ checked}/> Administrator
</label> </label>
</fieldset> </fieldset>
<fieldset> <fieldset>
<label><strong>URL</strong></label> <label><strong>URL (Optional)</strong></label>
<input type="text" name="url" id="url" style="width: 400px;"/> <input type="text" name="url" id="url" style="width: 400px;" value="@account.map(_.url)"/>
<span id="error-url" class="error"></span> <span id="error-url" class="error"></span>
</fieldset> </fieldset>
<fieldset> <fieldset>
<input type="submit" value="Create User"/> <input type="submit" class="btn btn-primary" value="@if(account.isEmpty){Create User} else {Update User}"/>
<a href="@path/admin/users" class="btn">Cancel</a>
</fieldset> </fieldset>
</form> </form>
} }