(refs #102)Add validation and auto completion to the transfer user name field

This commit is contained in:
takezoe
2014-01-18 06:44:39 +09:00
parent fba81138ea
commit 89bfcdc44e
2 changed files with 24 additions and 13 deletions

View File

@@ -48,7 +48,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
case class TransferOwnerShipForm(newOwner: String)
val transferForm = mapping(
"newOwner" -> trim(label("New owner", text(required))) // TODO user and repository existence check
"newOwner" -> trim(label("New owner", text(required, transferUser)))
)(TransferOwnerShipForm.apply)
/**
@@ -256,4 +256,20 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
}
}
/**
* Provides Constraint to validate the repository transfer user.
*/
private def transferUser: Constraint = new Constraint(){
override def validate(name: String, value: String, messages: Messages): Option[String] =
getAccountByUserName(value) match {
case None => Some("User does not exist.")
case Some(x) => if(x.userName == params("owner")){
Some("This is current repository owner.")
} else {
params.get("repository").flatMap { repositoryName =>
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map{ _ => "User already has same repository." }
}
}
}
}
}

View File

@@ -1,24 +1,19 @@
@(repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
@import context._
@import view.helpers._
@html.main("Delete Repository", Some(repository)){
@html.main("Transfer Ownership", Some(repository)){
@html.header("settings", repository)
@menu("transfer", repository){
<form id="form" method="post" action="@url(repository)/settings/transfer">
<form id="form" method="post" action="@url(repository)/settings/transfer" validate="true" autocomplete="off">
<h3>Transfer Ownership</h3>
<fieldset>
<label for="newOwner" class="strong">New owner:</label>
<input type="text" name="newOwner" id="newOwner"/>
<span id="error-newOwner" class="error"></span>
</fieldset>
@helper.html.account("newOwner", 300)
<input type="submit" class="btn btn-danger" value="Transfer"/>
<div>
<span id="error-newOwner" class="error"></span>
</div>
</fieldset>
</form>
}
}
<script>
$(function(){
$('#form').submit(function(){
return confirm('Do you really want to transfer this repo?');
});
});
</script>