Skip to content

Commit

Permalink
Closes #1034. Closes #1032. Screen and Wizard honor FormParam entries…
Browse files Browse the repository at this point in the history
… and it's easier to add FormParams to MappedField
  • Loading branch information
dpp committed Aug 25, 2011
1 parent f254f08 commit d98b451
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Expand Up @@ -195,6 +195,11 @@ trait BaseMappedField extends SelectableField with Bindable with MixableMappedFi


def asJs: List[(String, JsExp)] = List((name, asJsExp)) def asJs: List[(String, JsExp)] = List((name, asJsExp))


/**
* What form elements are we going to add to this field?
*/
def formElemAttrs: scala.Seq[SHtml.ElemAttr] = Nil

def renderJs_? = true def renderJs_? = true


/** /**
Expand Down Expand Up @@ -451,7 +456,7 @@ trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends Typed
case other => other case other => other
} }


_toForm.map(_.flatMap(mf) ) _toForm.map(_.flatMap(mf) ).map(SHtml.ElemAttr.applyToAllElems(_, formElemAttrs))
} }


/** /**
Expand Down
Expand Up @@ -23,6 +23,7 @@ import net.liftweb.json.JsonAST.{JNothing, JNull, JString, JValue}
import net.liftweb.util._ import net.liftweb.util._
import scala.reflect.Manifest import scala.reflect.Manifest
import scala.xml._ import scala.xml._
import http.SHtml


/** Base trait of record fields, with functionality common to any type of field owned by any type of record */ /** Base trait of record fields, with functionality common to any type of field owned by any type of record */
trait BaseField extends FieldIdentifier with util.BaseField { trait BaseField extends FieldIdentifier with util.BaseField {
Expand Down Expand Up @@ -92,6 +93,11 @@ trait BaseField extends FieldIdentifier with util.BaseField {
/** Encode the field value into a JValue */ /** Encode the field value into a JValue */
def asJValue: JValue def asJValue: JValue


/**
* What form elements are we going to add to this field?
*/
def formElemAttrs: Seq[SHtml.ElemAttr] = Nil

/** /**
* Set the name of this field * Set the name of this field
*/ */
Expand Down
33 changes: 32 additions & 1 deletion web/webkit/src/main/scala/net/liftweb/http/LiftScreen.scala
Expand Up @@ -188,6 +188,11 @@ trait AbstractScreen extends Factory {


override def helpAsHtml: Box[NodeSeq] = Empty override def helpAsHtml: Box[NodeSeq] = Empty


/**
* What form elements are we going to add to this field?
*/
def formElemAttrs: Seq[SHtml.ElemAttr] = Nil

/** /**
* Is the field editable * Is the field editable
*/ */
Expand All @@ -198,7 +203,8 @@ trait AbstractScreen extends Factory {
AbstractScreen.this.vendForm(manifest) or otherFuncVendors(manifest) or AbstractScreen.this.vendForm(manifest) or otherFuncVendors(manifest) or
LiftRules.vendForm(manifest) LiftRules.vendForm(manifest)


func.map(f => f(is, set _)).filter(x => editable_?) func.map(f => f(is, set _)).filter(x => editable_?).
map(ns => SHtml.ElemAttr.applyToAllElems(ns, formElemAttrs))
} }


protected def otherFuncVendors(what: Manifest[ValueType]): Box[(ValueType, ValueType => Any) => NodeSeq] = Empty protected def otherFuncVendors(what: Manifest[ValueType]): Box[(ValueType, ValueType => Any) => NodeSeq] = Empty
Expand Down Expand Up @@ -277,6 +283,11 @@ trait AbstractScreen extends Factory {


override def default = FieldBuilder.this.default override def default = FieldBuilder.this.default


/**
* What form elements are we going to add to this field?
*/
override lazy val formElemAttrs: Seq[SHtml.ElemAttr] = grabParams(stuff)

override implicit def manifest: Manifest[ValueType] = FieldBuilder.this.manifest override implicit def manifest: Manifest[ValueType] = FieldBuilder.this.manifest


override def helpAsHtml = help override def helpAsHtml = help
Expand Down Expand Up @@ -387,6 +398,11 @@ trait AbstractScreen extends Factory {
*/ */
override def show_? = underlying.show_? override def show_? = underlying.show_?


/**
* What form elements are we going to add to this field?
*/
override lazy val formElemAttrs: Seq[SHtml.ElemAttr] = grabParams(stuff)

/** /**
* Given the current context, should this field be displayed * Given the current context, should this field be displayed
*/ */
Expand Down Expand Up @@ -464,6 +480,11 @@ trait AbstractScreen extends Factory {
*/ */
override def show_? = underlying.map(_.show_?) openOr false override def show_? = underlying.map(_.show_?) openOr false


/**
* What form elements are we going to add to this field?
*/
override lazy val formElemAttrs: Seq[SHtml.ElemAttr] = grabParams(stuff)

/** /**
* Given the current context, should this field be displayed * Given the current context, should this field be displayed
*/ */
Expand Down Expand Up @@ -629,6 +650,11 @@ trait AbstractScreen extends Factory {


override def default: T = defaultValue override def default: T = defaultValue


/**
* What form elements are we going to add to this field?
*/
override lazy val formElemAttrs: Seq[SHtml.ElemAttr] = grabParams(stuff)

override val setFilter = stuff.flatMap { override val setFilter = stuff.flatMap {
case AFilter(f) => List(f) case AFilter(f) => List(f)
case _ => Nil case _ => Nil
Expand All @@ -653,6 +679,11 @@ trait AbstractScreen extends Factory {


override def default: T = defaultValue override def default: T = defaultValue


/**
* What form elements are we going to add to this field?
*/
override lazy val formElemAttrs: Seq[SHtml.ElemAttr] = grabParams(stuff)

override val setFilter = stuff.flatMap { override val setFilter = stuff.flatMap {
case AFilter(f) => List(f) case AFilter(f) => List(f)
case _ => Nil case _ => Nil
Expand Down
10 changes: 10 additions & 0 deletions web/webkit/src/main/scala/net/liftweb/http/SHtml.scala
Expand Up @@ -96,6 +96,16 @@ trait SHtml {


implicit def strSeqToElemAttr(in: Seq[(String, String)]): implicit def strSeqToElemAttr(in: Seq[(String, String)]):
Seq[ElemAttr] = in.map(a => a: ElemAttr) Seq[ElemAttr] = in.map(a => a: ElemAttr)

def applyToAllElems(in: Seq[Node], elemAttrs: Seq[ElemAttr]): Seq[Node] = in map {
case Group(ns) => Group(applyToAllElems(ns, elemAttrs))
case e: Elem => val updated = elemAttrs.foldLeft(e)((e, f) => f(e))

new Elem(updated.prefix, updated.label,
updated.attributes, updated.scope,
applyToAllElems(updated.child, elemAttrs) :_*)
case n => n
}
} }


private class ApplicableElem(in: Elem) { private class ApplicableElem(in: Elem) {
Expand Down

0 comments on commit d98b451

Please sign in to comment.