Skip to content

Instantly share code, notes, and snippets.

@tjweir
Forked from timperrett/gist:388259
Created May 3, 2010 16:56
Show Gist options
  • Select an option

  • Save tjweir/388309 to your computer and use it in GitHub Desktop.

Select an option

Save tjweir/388309 to your computer and use it in GitHub Desktop.
def bid(xhtml: NodeSeq): NodeSeq = {
if(!Customer.loggedIn_?){
S.warning("You must be logged in to bid on auctions.")
NodeSeq.Empty
}
else {
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.")
}
SHtml.ajaxForm(bind("b",xhtml,
"amount" -%> SHtml.text(amountBox.openOr(""), s => amountBox = Full(s)) % ("id" -> "amount"),
"submit" -> SHtml.ajaxSubmit("Place Bid", () => { submit; Noop })
))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment