Skip to content

Commit 34b405d

Browse files
committed
update to play 2.2 and added support for DELETE
1 parent 01bee3a commit 34b405d

File tree

8 files changed

+58
-44
lines changed

8 files changed

+58
-44
lines changed

app/controllers/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Application extends Controller {
99

1010
public static Result index() {
11-
return ok(index.render("Your new application is ready."));
11+
return redirect(routes.Products.list());
1212
}
1313

1414
}

app/views/index.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@(message: String)
22

3-
@main("Welcome to Play 2.1") {
3+
@main("Welcome to Play 2.2") {
44

55
@play20.welcome(message, style = "Java")
66

app/views/products/list.scala.html

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
11
@(products: Set[Product])
2-
3-
@import helper._
42
@main("Products catalogue") {
53

6-
<h1>All products</h1>
4+
<h2>All products</h2>
5+
6+
<script>
7+
function del(urlToDelete) {
8+
$.ajax({
9+
url: urlToDelete,
10+
type: 'DELETE',
11+
success: function(results) {
12+
// Refresh the page
13+
location.reload();
14+
}
15+
});
16+
}
17+
</script>
718

8-
<dl>
9-
@for(product <- products) {
10-
<dt>
19+
<table class="table table-striped">
20+
<thead>
21+
<tr>
22+
<th>EAN</th>
23+
<th>Name</th>
24+
<th>Description</th>
25+
<th></th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
@for(product <- products) {
1130

12-
<a href="@routes.Products.details(product.ean)">
13-
<i class="icon icon-pencil"></i>
14-
@product.ean - @product.name
15-
</a>
16-
</dt>
17-
<dd>@product.description
18-
@form(action = routes.Products.delete(product.ean)){
19-
<button type="submit" class="btn btn-danger btn-mini">
20-
<i class="icon icon-white icon-trash"></i> Delete</button>
31+
<tr>
32+
<td><a href="@routes.Products.details(product.ean)">
33+
@product.ean
34+
</a></td>
35+
<td><a href="@routes.Products.details(product.ean)">@product.name</a></td>
36+
<td><a href="@routes.Products.details(product.ean)">@product.name</a></td>
37+
<td>
38+
<a href="@routes.Products.details(product.ean)"><i class="icon icon-pencil"></i></a>
39+
<a onclick="javascript:del('@routes.Products.details(product.ean)')"><i class="icon icon-trash"></i></a>
40+
</td>
41+
</tr>
2142
}
22-
</dd>
23-
}
24-
</dl>
43+
44+
</tbody>
45+
</table>
2546

47+
48+
2649
<a href="@routes.Products.newProduct()" class="btn">
2750
<i class="icon-plus"></i> New product</a>
2851
}

build.sbt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name := "warehouse"
2+
3+
version := "1.0-SNAPSHOT"
4+
5+
libraryDependencies ++= Seq(
6+
javaJdbc,
7+
javaEbean,
8+
cache,
9+
"com.google.guava" % "guava" % "14.0"
10+
)
11+
12+
play.Project.playJavaSettings

conf/routes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ GET /products/ controllers.Products.list()
99
GET /products/new controllers.Products.newProduct()
1010
GET /products/:ean controllers.Products.details(ean: String)
1111
POST /products/ controllers.Products.save()
12-
POST /products/:ean/delete controllers.Products.delete(ean: String)
12+
DELETE /products/:ean controllers.Products.delete(ean: String)
1313

1414
# Map static resources from the /public folder to the /assets URL path
1515
GET /assets/*file controllers.Assets.at(path="/public", file)

project/Build.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.12.2
1+
sbt.version=0.13.0

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ logLevel := Level.Warn
55
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
66

77
// Use the Play sbt plugin for Play projects
8-
addSbtPlugin("play" % "sbt-plugin" % "2.1.1")
8+
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

0 commit comments

Comments
 (0)