Created
May 3, 2010 16:14
-
-
Save timperrett/388259 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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