Permalink
Browse files

deletes

  • Loading branch information...
1 parent fb74a8f commit 83e5f9278fc0b1ee5fb820e18e40e958080b60a3 @chrislewis committed Oct 3, 2011
Showing with 23 additions and 8 deletions.
  1. +14 −3 src/main/resources/index.html
  2. +9 −5 src/main/scala/net/godcode/hazelbox/wwpeek/GridPeekPlan.scala
@@ -2,11 +2,11 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Insert title here</title>
+<title>Unfiltered + Hazelcast</title>
</head>
<body>
<form id="person" action="/person" method="post">
- <input type="text" name="firstName"/>
+ <input type="text" id="firstName" name="firstName"/>
<input type="submit"/>
</form>
<div id="people"></div>
@@ -18,9 +18,20 @@
};
loadPeople();
+ $("#people li a").live("click", function(e) {
+ e.preventDefault();
+ $.ajax(this.href, {
+ type: "DELETE",
+ success: loadPeople
+ });
+ });
+
$("#person").submit(function(e) {
e.preventDefault();
- $.post("/person", $("#person").serialize(), loadPeople);
+ $.post("/person", $("#person").serialize(), function() {
+ loadPeople();
+ $("#firstName").val("");
+ });
});
})(jQuery);
</script>
@@ -13,20 +13,24 @@ class GridPeekPlan(hazel: HazelcastInstance) extends Plan {
def scalaMap[A, B](jm: java.util.Map[A, B]) =
scala.collection.JavaConversions.asScalaMap(jm)
- val people = scalaMap(hazel.getMap[ObjectId, Person]("default"))
+ val people = scalaMap(hazel.getMap[String, Person]("default"))
val me = Person(firstName = "Chris")
- people += (me._id -> me)
+ people += (me._id.toString -> me)
def intent = {
case GET(Path("/person")) => Html(
- <ul id="people">{ (List.empty[xml.NodeSeq] /: people) { case (ns, (k, v)) => <li>{v}</li> :: ns } }</ul>
+ <ul>{ (List.empty[xml.NodeSeq] /: people) {
+ case (ns, (k, v)) => <li>{v} - <a href={"/person/" + v._id.toString}>delete</a></li> :: ns } }</ul>
)
case POST(Path("/person") & Params(p)) =>
p("firstName").headOption.map { n =>
val person = Person(firstName = n)
- people += person._id -> person
- Ok
+ people += person._id.toString -> person
+ NoContent
}.getOrElse(BadRequest)
+ case DELETE(Path(Seg("person" :: id :: Nil))) =>
+ people.remove(id)
+ NoContent
}
}

0 comments on commit 83e5f92

Please sign in to comment.