Permalink
Browse files

Version 1 of the site

  • Loading branch information...
1 parent 48b0dea commit 41a6bb7f4d4f0943401ba9fc871628fbb70a0132 @dpp dpp committed Jan 21, 2011
@@ -6,6 +6,8 @@ class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
// uncomment the following if you want to use the snapshot repo
val scalatoolsSnapshot = ScalaToolsSnapshots
+ // val localMaven = "local maven" at "file:///home/dpp/.m2/repository"
+
// If you're using JRebel for Lift development, uncomment
// this line
override def scanDirectories = Nil
@@ -27,7 +27,7 @@ class Boot {
Menu("parallel", "Parallel Rendering") / "parallel",
Menu("comet", "Comet & Ajax") / "comet",
Menu("wiring", "Wiring") / "wiring",
- Menu("tempales", "Designer Friendly Templates") / "templates",
+ Menu("templates", "Designer Friendly Templates") / "templates",
Menu("wizard", "Wizard") / "wizard",
Menu("security", "Security") / "security")
@@ -0,0 +1,113 @@
+package net.liftweb.seventhings
+package snippet
+
+import net.liftweb._
+import http._
+import SHtml._
+import util._
+import Helpers._
+import js._
+import js.JsCmds._
+import js.jquery._
+
+import scala.xml.{NodeSeq, Text}
+
+case class Line(guid: String, name: String, price: Double, taxable: Boolean)
+
+/**
+ * An invoice system with subtotals, tax, etc.
+ */
+class InvoiceWiring {
+ /**
+ * Define the relationships among the items
+ */
+ private object Info {
+ val invoices = ValueCell(List(newLine))
+ val taxRate = ValueCell(0.05d)
+ val subtotal = invoices.lift(_.foldLeft(0d)(_ + _.price))
+ val taxable = invoices.lift(_.filter(_.taxable).
+ foldLeft(0D)(_ + _.price))
+
+ val tax = taxRate.lift(taxable) {_ * _}
+
+ val total = subtotal.lift(tax) {_ + _}
+ }
+
+ /**
+ * wire an element to subtotal
+ */
+ def subtotal = WiringUI.toNode(Info.subtotal)(doubleDraw)
+
+ /**
+ * Wire an element to taxable
+ */
+ def taxable = WiringUI.toNode(Info.taxable)(doubleDraw)
+
+ def tax = WiringUI.toNode(Info.tax, JqWiringSupport.fade)(doubleDraw)
+
+ def total = WiringUI.toNode(Info.total, JqWiringSupport.fade)(doubleDraw)
+
+
+ /** *
+ * The tax rate input
+ */
+ def taxRate = ajaxText(Info.taxRate.get.toString,
+ doubleToJsCmd(Info.taxRate.set))
+
+ /**
+ * Draw all the input lines
+ */
+ def showLines = "* *" #> (Info.invoices.get.flatMap(renderLine): NodeSeq)
+
+ /**
+ * Add a line to the input
+ */
+ def addLine =
+ "* [onclick]" #> ajaxInvoke(() =>
+ JqJsCmds.AppendHtml("invoice_lines", renderLine(appendLine)))
+
+ /**
+ * render a line of input fields
+ */
+ private def renderLine(theLine: Line): NodeSeq = {
+ import theLine._
+
+ <div id={guid}>
+ {ajaxText(name, s => mutateLine(guid)(_.copy(name = s)))}
+
+ {ajaxText(price.toString,
+ (d: Double) => mutateLine(guid) {_.copy(price = d)})}
+
+ {ajaxCheckbox(theLine.taxable,
+ b => mutateLine(guid) {_.copy(taxable = b)})}
+ </div>
+ }
+
+ private def newLine = Line(nextFuncName, "", 0, false)
+
+ private def appendLine: Line = {
+ val ret = newLine
+ Info.invoices.set(ret :: Info.invoices.get)
+ ret
+ }
+
+ /**
+ * Mutate a line and update the Info field
+ */
+ private def mutateLine(guid: String)(f: Line => Line) {
+ val all = Info.invoices.get
+ val head = all.filter(_.guid == guid).map(f)
+ val rest = all.filter(_.guid != guid)
+ Info.invoices.set(head ::: rest)
+ }
+
+ // convert a Double to a NodeSeq
+ private def doubleDraw: (Double, NodeSeq) => NodeSeq =
+ (d, ns) => Text(java.text.NumberFormat.getCurrencyInstance.format(d))
+
+
+ // Some helpful implicit conversions
+ private implicit def unitToJsCmd(in: Unit): JsCmd = Noop
+ private implicit def doubleToJsCmd(in: Double => Any): String => JsCmd =
+ str => {asDouble(str).foreach(in)}
+}
@@ -0,0 +1,55 @@
+package net.liftweb.seventhings
+package snippet
+
+import net.liftweb._
+import http._
+import js.jquery.JqJsCmds._
+import wizard._
+import util.Helpers._
+
+/**
+ * An example of a wizard in Lift
+ */
+object MyWizard extends Wizard {
+ override protected def calcAjaxOnDone = Unblock
+
+ // define the first screen
+ val nameAndAge = new Screen {
+ // it has a name field
+ val name = field(S ? "First Name", "",
+ valMinLen(2, S ? "Name Too Short"),
+ valMaxLen(40, S ? "Name Too Long"))
+
+ // and an age field
+ val age = field(S ? "Age", 0, minVal(5, S ?? "Too young"),
+ maxVal(120, S ? "You should be dead"))
+
+ // choose the next screen based on the age
+ override def nextScreen = if (age.is < 18) parentName else favoritePet
+ }
+
+ // We ask the parent's name if the person is under 18
+ val parentName = new Screen {
+ val parentName = field(S ? "Mom or Dad's name", "",
+ valMinLen(2, S ? "Name Too Short"),
+ valMaxLen(40, S ? "Name Too Long"))
+ }
+
+ // we ask for the favorite pet
+ val favoritePet = new Screen {
+ val petName = field(S ? "Pet's name", "",
+ valMinLen(2, S ? "Name Too Short"),
+ valMaxLen(40, S ? "Name Too Long"))
+ }
+
+ // what to do on completion of the wizard
+ def finish() {
+ S.notice("Thank you for registering your pet: "+
+ favoritePet.petName+
+ " your age * 3: "+nameAndAge.age * 3)
+ }
+}
+
+object AjaxRunner {
+ def render = "* [onclick]" #> SHtml.ajaxInvoke(() => ModalDialog(<div><lift:MyWizard ajax="true"/></div>))
+}
@@ -17,12 +17,12 @@
<ol>
<li><big><span class="lift:Menu.item?name=lazy">Lazy Loading</span></big></li>
<li><big class="lift:Menu.item?name=parallel">Parallel page rendering</big></li>
- <li><big>Comet and Ajax</big></li>
- <li><big>Wiring -- declare interdepencies between page elements</big></li>
- <li><big>Designer friendly templates</big></li>
- <li><big>Wizard -- multipage input screens with full back-button
+ <li><big class="lift:Menu.item?name=comet">Comet and Ajax</big></li>
+ <li><big><span class="lift:Menu.item?name=wiring">Wiring</span> -- declare interdepencies between page elements</big></li>
+ <li><big class="lift:Menu.item?name=templates">Designer friendly templates</big></li>
+ <li><big><span class="lift:Menu.item?name=wizard">Wizard</span> -- multipage input screens with full back-button
support</big></li>
- <li><big>Security</big><br>
+ <li><big class="lift:Menu.item?name=security">Security</big><br>
</li>
</ol>
<big><big>Lift gives you the above Seven Things, plus your code is
Oops, something went wrong.

0 comments on commit 41a6bb7

Please sign in to comment.