Browse Source

Setup task model and entry form

Create basic task model
  Restructure application template
  Create task entry form
master
jimi 11 years ago
parent
commit
5a95cdd1be
  1. 14
      app/controllers/Application.scala
  2. 11
      app/models/Task.scala
  3. 23
      app/views/index.scala.html

14
app/controllers/Application.scala

@ -3,13 +3,25 @@ package controllers
import play.api._ import play.api._
import play.api.mvc._ import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import models.Task
object Application extends Controller { object Application extends Controller {
val taskForm = Form(
"label" -> nonEmptyText
)
def index = Action { def index = Action {
Redirect(routes.Application.tasks) Redirect(routes.Application.tasks)
} }
def tasks = TODO
def tasks = Action {
Ok(views.html.index(Task.all(), taskForm))
}
def newTask = TODO def newTask = TODO

11
app/models/Task.scala

@ -0,0 +1,11 @@
package models
case class Task(id:Long, label:String)
object Task {
def all(): List[Task] = Nil
def create(label:String) {}
def delete(id:Long) {}
}

23
app/views/index.scala.html

@ -1,7 +1,24 @@
@(message: String)
@(tasks:List[Task], taskForm:Form[String])
@main("Welcome to Play") {
@import helper._
@play20.welcome(message)
@main("Todo List") {
<h1>@tasks.size task(s)</h1>
<ul>
@tasks.map { task =>
<li>
@task.label
@form(routes.Application.deleteTask(task.id)) {
<input type="submit" value="Delete">
}
</li>
}
</ul>
<h2>Add a new task</h2>
@form(routes.Application.newTask) {
@inputText(taskForm("label"))
<input type="submit" value="Create">
}
} }