Skip to content

Commit

Permalink
Remove some remaining lift:gc and relaxed MetaRecord#toForm
Browse files Browse the repository at this point in the history
  • Loading branch information
danciu committed Mar 19, 2009
1 parent d983b21 commit 958e43b
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 29 deletions.
Expand Up @@ -76,7 +76,7 @@ class MappedDateTime[T<:Mapper[T]](val fieldOwner: T) extends MappedField[Date,
override def _toForm: Box[NodeSeq] =
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(<input type='text' id={fieldId}
name={funcName} lift:gc={funcName}
name={funcName}
value={is match {case null => "" case s => toInternetDate(s)}}/>)
}

Expand Down
Expand Up @@ -411,7 +411,7 @@ trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends Typed
override def _toForm: Box[NodeSeq] =
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(<input type='text' id={fieldId}
name={funcName} lift:gc={funcName}
name={funcName}
value={is match {case null => "" case s => s.toString}}/>)
}

Expand Down
Expand Up @@ -121,7 +121,7 @@ extends MappedField[String, T] {
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(<span><input id={fieldId} type='password' name={funcName}
value={is.toString}/>&nbsp;{S.??("repeat")}&nbsp;<input
type='password' name={funcName} lift:gc={funcName}
type='password' name={funcName}
value={is.toString}/></span>)
}
}
Expand Down
Expand Up @@ -96,7 +96,7 @@ class MappedString[T<:Mapper[T]](val fieldOwner: T,val maxLen: Int) extends Mapp
override def _toForm: Box[NodeSeq] =
fmapFunc({s: List[String] => this.setFromAny(s)}){name =>
Full(<input type='text' id={fieldId} maxlength={maxLen.toString}
name={name} lift:gc={name}
name={name}
value={is match {case null => "" case s => s.toString}}/>)}

protected def i_obscure_!(in : String) : String = {
Expand Down
Expand Up @@ -27,7 +27,7 @@ class MappedTextarea[T<:Mapper[T]](owner : T, maxLen: Int) extends MappedString[
*/
override def _toForm: Box[NodeSeq] = {
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(<textarea name={funcName} lift:gc={funcName}
Full(<textarea name={funcName}
rows={textareaRows.toString}
cols={textareaCols.toString} id={fieldId}>{is.toString}</textarea>)}
}
Expand Down
4 changes: 2 additions & 2 deletions lift-mapper/src/main/scala/net/liftweb/mapper/Mapper.scala
Expand Up @@ -187,7 +187,7 @@ trait Mapper[A<:Mapper[A]] extends BaseMapper {
getSingleton.toForm(this) ++
S.fmapFunc((ignore: List[String]) => f(this)){
(name: String) =>
(<input type='hidden' name={name} lift:gc={name} value="n/a" />)} ++
(<input type='hidden' name={name} value="n/a" />)} ++
(button.map(b => getSingleton.formatFormElement( <xml:group>&nbsp;</xml:group> , <input type="submit" value={b}/> )) openOr _root_.scala.xml.Text(""))

def toForm(button: Box[String], redoSnippet: NodeSeq => NodeSeq, onSuccess: A => Unit): NodeSeq = {
Expand All @@ -201,7 +201,7 @@ trait Mapper[A<:Mapper[A]] extends BaseMapper {
}

getSingleton.toForm(this) ++
S.fmapFunc((ignore: List[String]) => doSubmit())(name => <input type='hidden' name={name} lift:gc={name} value="n/a" />) ++
S.fmapFunc((ignore: List[String]) => doSubmit())(name => <input type='hidden' name={name} value="n/a" />) ++
(button.map(b => getSingleton.formatFormElement( <xml:group>&nbsp;</xml:group> , <input type="submit" value={b}/> )) openOr _root_.scala.xml.Text(""))
}

Expand Down
18 changes: 12 additions & 6 deletions lift-record/src/main/scala/net/liftweb/record/MetaRecord.scala
Expand Up @@ -19,7 +19,6 @@ import scala.collection.mutable.{ListBuffer}
import scala.xml._
import net.liftweb.http.js.{JsExp, JE}
import net.liftweb.http.{FieldError, SHtml}
// import net.liftweb.mapper.{Safe, KeyObfuscator}
import java.lang.reflect.Method
import field._

Expand Down Expand Up @@ -220,13 +219,20 @@ trait MetaRecord[BaseRecord <: Record[BaseRecord]] {
*/
def toForm(inst: BaseRecord): NodeSeq = {
formTemplate match {
case Full(template) => _toForm(inst, template)
case Empty => fieldList.flatMap(holder => fieldByName(holder.name, inst).
case Full(template) => toForm(inst, template)
case _ => fieldList.flatMap(holder => fieldByName(holder.name, inst).
map(_.toForm).openOr(NodeSeq.Empty) ++ Text("\n"))
}
}

private def _toForm(inst: BaseRecord, template: NodeSeq): NodeSeq = {
/**
* Returns the XHTML representation of inst Record. You must provide the Node template
* to represent this record in the proprietary layout.
*
* @param inst - the record to be rendered
* @return the XHTML content as a NodeSeq
*/
def toForm(inst: BaseRecord, template: NodeSeq): NodeSeq = {
template match {
case e @ <lift:field_label>{_*}</lift:field_label> => e.attribute("name") match{
case Some(name) => fieldByName(name.toString, inst).map(_.label).openOr(NodeSeq.Empty)
Expand All @@ -247,11 +253,11 @@ trait MetaRecord[BaseRecord <: Record[BaseRecord]] {
}

case Elem(namespace, label, attrs, scp, ns @ _*) =>
Elem(namespace, label, attrs, scp, _toForm(inst, ns.flatMap(n => _toForm(inst, n))):_* )
Elem(namespace, label, attrs, scp, toForm(inst, ns.flatMap(n => toForm(inst, n))):_* )

case s : Seq[_] => s.flatMap(e => e match {
case Elem(namespace, label, attrs, scp, ns @ _*) =>
Elem(namespace, label, attrs, scp, _toForm(inst, ns.flatMap(n => _toForm(inst, n))):_* )
Elem(namespace, label, attrs, scp, toForm(inst, ns.flatMap(n => toForm(inst, n))):_* )
case x => x
})

Expand Down
Expand Up @@ -52,11 +52,7 @@ class BooleanField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends Field
}
}

private def elem = /*<input type="checkbox"
name={S.mapFunc(SFuncHolder(this.setFromAny(_)))}
value={value.toString}
tabindex={tabIndex toString}/>;
*/ SHtml.checkbox(value, this.set _, "tabIndex" -> tabIndex.toString)
private def elem = SHtml.checkbox(value, this.set _, "tabIndex" -> tabIndex.toString)

def toForm = {
//var el = elem
Expand Down
Expand Up @@ -53,7 +53,7 @@ class DateTimeField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends Fiel
private def elem =
S.fmapFunc(SFuncHolder(this.setFromAny(_))){funcName =>
<input type="text"
name={funcName} lift:gc={funcName}
name={funcName}
value={value match {case null => "" case s: Calendar => toInternetDate(s.getTime)}}
tabindex={tabIndex toString}/>
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ trait NumericField[MyType, OwnerType <: Record[OwnerType]] extends Field[MyType,
this.setFromAny(s) match {
case Empty => valueCouldNotBeSet = true
case _ =>
}}}{funcName => <input type="text" name={funcName} lift:gc={funcName} value={value.toString}
}}}{funcName => <input type="text" name={funcName} value={value.toString}
tabindex={tabIndex toString}/>}

/**
Expand Down
Expand Up @@ -50,7 +50,7 @@ class PasswordField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends Fiel

private def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))){
funcName => <input type="pasword"
name={funcName} lift:gc={funcName}
name={funcName}
value={value match {case null => "" case s => s.toString}}
tabindex={tabIndex toString}/>}

Expand Down
Expand Up @@ -57,7 +57,6 @@ class StringField[OwnerType <: Record[OwnerType]](rec: OwnerType, maxLength: Int
funcName =>
<input type="text" maxlength={maxLength.toString}
name={funcName}
lift:gc={funcName}
value={value match {case null => "" case s => s.toString}}
tabindex={tabIndex toString}/>
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ import Helpers._
class TextareaField[OwnerType <: Record[OwnerType]](rec: OwnerType, maxLength: Int) extends StringField(rec, maxLength) {

private def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))){
funcName => <textarea name={funcName} lift:gc={funcName}
funcName => <textarea name={funcName}
rows={textareaRows.toString}
cols={textareaCols.toString}
tabindex={tabIndex toString}>{value match {case null => "" case s => s.toString}}</textarea>
Expand Down
Expand Up @@ -86,10 +86,9 @@ class TreeView {
<link rel="stylesheet" href={"/" + LiftRules.resourceServerPath + "/tree/jquery.treeview.css"} type="text/css"/>
<script type="text/javascript" src={"/" + LiftRules.resourceServerPath + "/tree/jquery.treeview.js"}/>
<script type="text/javascript" src={"/" + LiftRules.resourceServerPath + "/tree/jquery.treeview.async.js"}/>
<span lift:gc={gc}/>
{
Script(OnLoad(js.cmd))
}
{
Script(OnLoad(js.cmd))
}
</head>

}
Expand Down
Expand Up @@ -75,8 +75,7 @@ class Ajax {
<pre>{text}</pre>,
4 seconds, 200))

<a href="javascript://" onclick={je.toJsCmd}
lift:gc={name}>Enter text above and click me</a>
<a href="javascript://" onclick={je.toJsCmd}>Enter text above and click me</a>
}
<br/>
<br/>
Expand Down

0 comments on commit 958e43b

Please sign in to comment.