Skip to content

Instantly share code, notes, and snippets.

@urcadox
Created October 19, 2011 14:16
Show Gist options
  • Save urcadox/1298410 to your computer and use it in GitHub Desktop.
Save urcadox/1298410 to your computer and use it in GitHub Desktop.
package code {
package snippet {
import net.liftweb.common._
import net.liftweb.util._
import net.liftweb.http._
import net.liftweb.http.SHtml._
import model._
import model.UserType._
import java.util.Date
object Preferences extends LiftScreen {
object user extends ScreenVar[code.model.User](User.currentUser.open_!)
override def screenTop = Full(<h2>{S.?("preferences")}</h2>)
val currentPassword = new Field {
type ValueType = String
override def name = S.?("current-password")
override def default = ""
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.password(is, set _)
}
val firstName = new Field {
type ValueType = String
override def name = user.is.firstName.displayName
override def default = user.is.firstName.is
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.text(is, user.is.firstName.set _)
}
val lastName = new Field {
type ValueType = String
override def name = user.is.lastName.displayName
override def default = user.is.lastName.is
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.text(is, user.is.lastName.set _)
}
val email = new Field {
type ValueType = String
override def name = user.is.email.displayName
override def default = user.is.email.is
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.text(is, user.is.email.set _)
}
val newPassword1 = new Field {
type ValueType = String
override def name = S.?("new-password")
override def default = ""
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.text(is, set _)
}
val newPassword2 = new Field {
type ValueType = String
override def name = S.?("new-password-confirmation")
override def default = ""
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.text(is, set _)
}
val timezone = new Field {
type ValueType = List[Any]
override def name = user.is.timezone.displayName
override def default = user.is.timezone.is
lazy val manifest = buildIt[ValueType]
override def toForm = SHtml.select(
user.is.timezone.buildDisplayList,
Box(user.is.timezone.is),
user.is.timezone.set _
)
}
val optIn = new Field {
type ValueType = Option[Boolean]
override def name = user.is.optIn.displayName
override def default = user.is.optIn.is
lazy val manifest = buildIt[ValueType]
override def toForm = user.is.optIn.toForm
}
override def validations = (
() => user.is.optIn.notEmpty(S.?("mandatory-choice"))(user.is.optIn.is)
) :: Nil
override def finishButton = <button>
{S.?("save")}
</button>
def finish() {
user.is.save
S.notice(S.?("preferences-saved"))
S.redirectTo("/preferences")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment