Skip to content

Instantly share code, notes, and snippets.

@OleTraveler
Created April 4, 2011 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleTraveler/902283 to your computer and use it in GitHub Desktop.
Save OleTraveler/902283 to your computer and use it in GitHub Desktop.
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