From 5b12bb5aa0d3d4d4d11614e13e97283a05750eef Mon Sep 17 00:00:00 2001 From: David Pollak Date: Thu, 24 Feb 2011 06:00:53 -0800 Subject: [PATCH] Allow setting defalut value via params --- .../main/scala/net/liftweb/sitemap/Loc.scala | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala b/web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala index a52af7d027..5c89f5d7f8 100644 --- a/web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala +++ b/web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala @@ -63,8 +63,20 @@ trait Loc[T] { def calcHref(in: T): String = link.createPath(in) def defaultValue: Box[T] + + /** + * The value of the Loc based on params (either Loc.Value or Loc.CalcValue) + */ + def paramValue: Box[T] = calcValue.flatMap(f => f()) or staticValue + + private lazy val staticValue: Box[T] = params.collect{case Loc.Value(v: T) => v}.headOption + + private lazy val calcValue: Box[() => Box[T]] = params.collect{case Loc.CalcValue(f: Function0[Box[T]]) => f}.headOption - def currentValue: Box[T] = overrideValue or requestValue.is or defaultValue + /** + * The current value of the cell: overrideValue or requestValue.is or defaultValue oe paramValue + */ + def currentValue: Box[T] = overrideValue or requestValue.is or defaultValue or paramValue def childValues: List[T] = Nil @@ -526,6 +538,17 @@ object Loc { * the groups can be specified and recalled at the top level */ case class LocGroup(group: String*) extends AnyLocParam + + /** + * Calculate the value for the Loc. This is useful for parameterized + * menus. It allows you to calculate the value of the Loc. + */ + case class CalcValue[T](func: () => Box[T]) extends LocParam[T] + + /** + * The value of Loc + */ + case class Value[T](value: T) extends LocParam[T] /** * An extension point for adding arbitrary lazy values to a Loc.