From 689136b20e041d6301c1742a2e61b4f9509f52b7 Mon Sep 17 00:00:00 2001 From: timperrett Date: Sun, 17 Apr 2011 22:57:52 +0100 Subject: [PATCH] Migrated a bunch of samples to use the CSS binding rather than manual binds --- .../main/scala/bootstrap/liftweb/Boot.scala | 4 +- .../sample/snippet/AutoCompleteSample.scala | 9 +- .../scala/sample/snippet/CookieSample.scala | 25 ++-- .../sample/snippet/RequestVarSample.scala | 12 +- .../main/webapp/state/cookie_handling.html | 7 +- .../src/main/webapp/state/request_var.html | 7 +- .../main/webapp/widgets/auto_complete.html | 6 +- lift-in-action.tmproj | 112 +----------------- 8 files changed, 32 insertions(+), 150 deletions(-) diff --git a/chapter-6/src/main/scala/bootstrap/liftweb/Boot.scala b/chapter-6/src/main/scala/bootstrap/liftweb/Boot.scala index 13b2c54..53d04a3 100644 --- a/chapter-6/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/chapter-6/src/main/scala/bootstrap/liftweb/Boot.scala @@ -57,8 +57,8 @@ class Boot { Menu("Implementing LiftView sub-type") / "MyView" / "sample" ), Menu("Requests, Sessions & Cookies") / "state" / "index" submenus( - Menu("Implementing a RequestVar[Box[String]]") / "wizard" / "request_var", - Menu("Getting and setting a cookie value") / "wizard" / "cookie_handling" + Menu("Implementing a RequestVar[Box[String]]") / "state" / "request_var", + Menu("Getting and setting a cookie value") / "state" / "cookie_handling" ), Menu("LiftScreen and Wizard") / "wizard" / "index" submenus( Menu("Basic LiftScreen implementation") / "wizard" / "lift_screen_one", diff --git a/chapter-6/src/main/scala/sample/snippet/AutoCompleteSample.scala b/chapter-6/src/main/scala/sample/snippet/AutoCompleteSample.scala index 469840e..ef78a26 100644 --- a/chapter-6/src/main/scala/sample/snippet/AutoCompleteSample.scala +++ b/chapter-6/src/main/scala/sample/snippet/AutoCompleteSample.scala @@ -7,10 +7,7 @@ import net.liftweb.widgets.autocomplete.AutoComplete class AutoCompleteSample { private val data = List("Timothy","Derek","Ross","Tyler","Indrajit","Harry","Greg","Debby") - def sample(xhtml: NodeSeq): NodeSeq = - bind("f", xhtml, - "find_name" -> AutoComplete("", - (current,limit) => data.filter(_.toLowerCase.startsWith(current.toLowerCase)), - x => println("Submitted: " + x)) - ) + def sample = "*" #> AutoComplete("", (current,limit) => + data.filter(_.toLowerCase.startsWith(current.toLowerCase)), + x => println("Submitted: " + x)) } \ No newline at end of file diff --git a/chapter-6/src/main/scala/sample/snippet/CookieSample.scala b/chapter-6/src/main/scala/sample/snippet/CookieSample.scala index 83fa9b4..1f4e2fa 100644 --- a/chapter-6/src/main/scala/sample/snippet/CookieSample.scala +++ b/chapter-6/src/main/scala/sample/snippet/CookieSample.scala @@ -6,31 +6,26 @@ import net.liftweb.util.Helpers._ import net.liftweb.http.{DispatchSnippet,S,SHtml} import net.liftweb.http.provider.HTTPCookie -// listing 6.15 +// listing 6.13 class CookieSample extends DispatchSnippet { override def dispatch = { - case "add" => add _ - case "delete" => delete _ + case "add" => add + case "delete" => delete case _ => display _ } private val cookieName = "liftinaction.sample" - private def action(does: String, using: () => Any, xhtml: NodeSeq) = - bind("c",xhtml, - "button" -> SHtml.submit(does, - () => {using(); S.redirectTo(S.uri)})) + private def action(does: String, using: () => Any) = + "*" #> SHtml.submit(does, () => {using(); S.redirectTo(S.uri)}) - def delete(xhtml: NodeSeq): NodeSeq = - action("Delete Cookie", () => S.deleteCookie(cookieName), xhtml) + def delete = action("Delete Cookie", + () => S.deleteCookie(cookieName)) - def add(xhtml: NodeSeq): NodeSeq = - action("Create Cookie", () => S.addCookie( - HTTPCookie(cookieName,"I love cookies")), xhtml) + def add = action("Create Cookie", () => S.addCookie( + HTTPCookie(cookieName,"I love cookies"))) - def display(xhtml: NodeSeq): NodeSeq = - S.findCookie(cookieName).map { cookie => + def display(xhtml: NodeSeq) = S.findCookie(cookieName).map { cookie => Text("Cookie found!: %s".format(cookie)) } openOr Text("No cookie set.") - } \ No newline at end of file diff --git a/chapter-6/src/main/scala/sample/snippet/RequestVarSample.scala b/chapter-6/src/main/scala/sample/snippet/RequestVarSample.scala index 0b31308..051a729 100644 --- a/chapter-6/src/main/scala/sample/snippet/RequestVarSample.scala +++ b/chapter-6/src/main/scala/sample/snippet/RequestVarSample.scala @@ -9,10 +9,12 @@ object sample extends RequestVar[Box[String]](Empty) object RequestVarSample extends DispatchSnippet { def dispatch = { - case _ => render _ + case _ => render + } + def render = { + "type=text" #> SHtml.text( + sample.is.openOr(""), + v => sample(Box.!!(v))) & + "type=submit" #> SHtml.onSubmitUnit(() => println(sample.is)) } - def render(xhtml: NodeSeq): NodeSeq = bind("f",xhtml, - "value" -> SHtml.text(sample.is.openOr(""), v => sample(Box.!!(v))), - "submit" -> SHtml.submit("Submit", () => println(sample.is)) - ) } \ No newline at end of file diff --git a/chapter-6/src/main/webapp/state/cookie_handling.html b/chapter-6/src/main/webapp/state/cookie_handling.html index 9c77b5d..fda4f7a 100644 --- a/chapter-6/src/main/webapp/state/cookie_handling.html +++ b/chapter-6/src/main/webapp/state/cookie_handling.html @@ -1,10 +1,9 @@

Cookies

- -

Attempted looking for cookie:

+

Attempted looking for cookie: Cookie Name

- +
- +

diff --git a/chapter-6/src/main/webapp/state/request_var.html b/chapter-6/src/main/webapp/state/request_var.html index 95c397d..3b66553 100644 --- a/chapter-6/src/main/webapp/state/request_var.html +++ b/chapter-6/src/main/webapp/state/request_var.html @@ -1,8 +1,9 @@

RequestVar sample

- -

-
+
+


+

+
diff --git a/chapter-6/src/main/webapp/widgets/auto_complete.html b/chapter-6/src/main/webapp/widgets/auto_complete.html index 8ff2e02..81c8a37 100644 --- a/chapter-6/src/main/webapp/widgets/auto_complete.html +++ b/chapter-6/src/main/webapp/widgets/auto_complete.html @@ -1,8 +1,6 @@

Auto Complete Widget

- - +

Type a name here:

- - +
diff --git a/lift-in-action.tmproj b/lift-in-action.tmproj index f643bb6..d4831d2 100644 --- a/lift-in-action.tmproj +++ b/lift-in-action.tmproj @@ -2,8 +2,6 @@ - currentDocument - chapter-6/src/main/webapp/snippets/lazy_loading.html documents @@ -35,118 +33,10 @@ firstVisibleLine 0 - chapter-6/src/main/scala/sample/snippet/LazyLoading.scala - - caret - - column - 0 - line - 14 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-6/src/main/webapp/snippets/intermediate_example.html - - caret - - column - 0 - line - 3 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-6/src/main/webapp/snippets/lazy_loading.html - - caret - - column - 16 - line - 11 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-8/src/main/scala/sample/lib/RestExampleAdvanced.scala - - caret - - column - 2 - line - 28 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-9/src/main/scala/bootstrap/liftweb/Boot.scala - - caret - - column - 4 - line - 11 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-9/src/main/scala/sample/comet/Clock.scala - - caret - - column - 0 - line - 22 - - firstVisibleColumn - 0 - firstVisibleLine - 0 - - chapter-9/src/main/scala/sample/comet/RockPaperScissors.scala - - caret - - column - 40 - line - 137 - - firstVisibleColumn - 0 - firstVisibleLine - 112 - - openDocuments - - chapter-8/src/main/scala/sample/lib/RestExampleAdvanced.scala - chapter-9/src/main/scala/bootstrap/liftweb/Boot.scala - chapter-9/src/main/scala/sample/comet/Clock.scala - chapter-9/src/main/scala/sample/comet/RockPaperScissors.scala - chapter-6/src/main/scala/sample/snippet/LazyLoading.scala - chapter-6/src/main/webapp/snippets/lazy_loading.html - chapter-6/src/main/webapp/snippets/intermediate_example.html - showFileHierarchyDrawer windowFrame - {{348, 181}, {876, 673}} + {{514, 71}, {876, 673}}