Created
April 4, 2011 19:55
-
-
Save OleTraveler/902283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WiredUser { | |
val userToWire = (Users.userForDisplay or userDetail.currentValue).get | |
private object User { | |
val entity = ValueCell(userToWire) | |
val edit = ValueCell(false) | |
val email = edit.lift(b => entity.lift(_.getEmail.asScala.headOption).get) | |
} | |
def edit = { | |
WiringUI.toNode(User.edit, JqWiringSupport.fade)((mode: Boolean, ns:NodeSeq) => { Wired.editable( | |
mode, | |
mode, | |
(b: Boolean) => ajaxButton(h("Done"), () => {User.edit.set(false); JsCmds.Noop}), | |
(b: Boolean) => ajaxButton(h("Edit"), () => {User.edit.set(true); JsCmds.Noop}) | |
)}) | |
} | |
def email = WiringUI.toNode(User.email, JqWiringSupport.fade)((email: Option[String], ns: NodeSeq) => { | |
Wired.editable( | |
email.getOrElse(""), | |
User.edit.get, | |
(n: String) => ajaxText(n, s => {refresh(setEmail(_, s)); JsCmds.Noop}), | |
(n: String) => h(n) | |
) | |
}) | |
} | |
object Wired { | |
def editable[T](o: T, mode: Boolean, t: (T)=> NodeSeq, f: (T) => NodeSeq) : NodeSeq = { | |
mode match { | |
case true => t(o) | |
case false => f(o) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment