Skip to content

Commit

Permalink
end to end spike now in place
Browse files Browse the repository at this point in the history
  • Loading branch information
kouphax committed May 9, 2012
1 parent a172eb3 commit e89e708
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
5 changes: 3 additions & 2 deletions app/controllers/Application.scala
Expand Up @@ -2,9 +2,10 @@ package controllers

import play.api._
import play.api.mvc._
import models._

object Application extends Controller {
def index = Action {
Ok(views.html.index())
def index = Action { implicit request =>
Ok(views.html.index(Registrations.all))
}
}
9 changes: 6 additions & 3 deletions app/controllers/Register.scala
Expand Up @@ -21,14 +21,17 @@ object Register extends Controller {
})
)

def index = Action {
Ok(views.html.register(registrationForm.fill(Registration("","","",""))))
def index = Action { implicit request =>
Ok(views.html.register(registrationForm))
}

def register = Action { implicit request =>
registrationForm.bindFromRequest.fold(
form => BadRequest(views.html.register(form)),
registration => Redirect(routes.Application.index())
registration => {
Registrations.create(registration)
Redirect(routes.Application.index()).flashing("message" -> "User Registered!")
}
)
}
}
17 changes: 16 additions & 1 deletion app/models/Registration.scala
@@ -1,4 +1,19 @@
package models

// STEP 1: Define the registration case class
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.ValidBSONType.BasicDBList
import com.novus.salat._
import com.novus.salat.global._
import com.mongodb.casbah.Imports._
import com.novus.salat.annotations._

case class Registration(username: String, password: String, confirm: String, realName: String)

object Registrations {
val registrations = MongoConnection()("sampleapp")("registrations")

def all = registrations.map(grater[Registration].asObject(_)).toList
def create(registration: Registration) {
registrations += grater[Registration].asDBObject(registration)
}
}
26 changes: 25 additions & 1 deletion app/views/index.scala.html
@@ -1,3 +1,27 @@
@(registrations: List[Registration])(implicit flash: Flash)
@main("Super Simple Sample") {
<a href="@routes.Register.index">Register</a>
@if(flash.data.contains("message")){
<div class='row'>
<div class="alert alert-success" style="margin-left:30px;margin-top:20px;">@flash.get("message")</div>
</div>
}
<div style="margin-top:20px;margin-bottom:20px;">
<a href="@routes.Register.index" class="btn btn-primary">Register</a>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Username</th>
<th>Real Name</th>
</tr>
</thead>
<tbody>
@registrations.map { registration =>
<tr>
<td>@registration.username</td>
<td>@registration.realName</td>
</tr>
}
</tbody>
</table>
}
18 changes: 10 additions & 8 deletions app/views/register.scala.html
@@ -1,4 +1,4 @@
@(registrationForm: Form[models.Registration])
@(registrationForm: Form[models.Registration])(implicit flash: Flash)

@import play.api.i18n._
@import views.html.helper._
Expand All @@ -7,7 +7,7 @@
<div class="control-group @if(field.hasErrors) {error}">
<label class="control-label" for="@field.id">@label</label>
<div class="controls">
<input type="@fieldType" value="@field.value" name="@field.id" />
<input type="@fieldType.name" value="@field.value" name="@field.id" />
@if(field.hasErrors){
<span class="help-inline">
@Messages(field.error.head.message)
Expand All @@ -19,19 +19,21 @@

@main("Super Simple Sample") {

@* GLOBAL ERROR/FLASH MESSAGE *@
@registrationForm.globalError.map { error =>
<div class="alert alert-error">@error.message</div>
}

@form(action = routes.Register.register, 'class -> "form-horizontal") {

<fieldset>
<legend>Registration</legend>
@* GLOBAL ERROR/FLASH MESSAGE *@
@registrationForm.globalError.map { error =>
<div class='row'>
<div class="alert alert-error" style="margin-left:30px;margin-top:20px;">@error.message</div>
</div>
}
@input(registrationForm("username"), "Username")
@input(registrationForm("password"), "Password", 'password)
@input(registrationForm("confirm"), "Confirm Password", 'password)
@input(registrationForm("realName"), "Real Name")
</fieldset>
<input type="submit" class="btn" value="register"/>
<input type="submit" class="btn" value="Register"/>
}
}
10 changes: 7 additions & 3 deletions project/Build.scala
Expand Up @@ -8,11 +8,15 @@ object ApplicationBuild extends Build {
val appVersion = "1.0-SNAPSHOT"

val appDependencies = Seq(
"com.github.twitter" % "bootstrap" % "2.0.2"
"com.github.twitter" % "bootstrap" % "2.0.2",
"com.mongodb.casbah" %% "casbah" % "2.1.5-1",
"com.novus" %% "salat-core" % "0.0.8-SNAPSHOT"
)

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
resolvers ++= Seq("webjars" at "http://webjars.github.com/m2")
resolvers ++= Seq(
"webjars" at "http://webjars.github.com/m2",
"repo.novus snaps" at "http://repo.novus.com/snapshots/"
)
)

}

0 comments on commit e89e708

Please sign in to comment.