Skip to content

Instantly share code, notes, and snippets.

@timperrett
Created May 3, 2010 16:14
Show Gist options
  • Save timperrett/388259 to your computer and use it in GitHub Desktop.
Save timperrett/388259 to your computer and use it in GitHub Desktop.
def bid(xhtml: NodeSeq): NodeSeq = {
var amountBox: Box[String] = Empty
def submit = {
for(ass <- amountBox ?~ "Amount not entered";
amo <- tryo(BigDecimal(ass).doubleValue) ?~! "Amount not a number";
auc <- auction;
vld <- tryo(amo).filter(_ >= auc.nextAmount) ?~ "Less that required amount!"
) yield {
new Bid().auction(auction).customer(Customer.currentUser).amount(amo).save
}
} match {
case Full(x) => S.notice("Great, your bid was accepted!")
case Failure(msg, _, _) => S.error(msg)
case _ => S.warning("Unable to place bid at this time.")
}
if(Customer.loggedIn_?){
SHtml.ajaxForm(bind("b",xhtml,
"amount" -%> SHtml.text(amountBox.openOr(""), s => amountBox = Full(s)) % ("id" -> "amount"),
"submit" -> SHtml.ajaxSubmit("Place Bid", () => { submit; Noop })
))
} else {
S.warning("You must be logged in to bid on auctions.")
NodeSeq.Empty
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment