Created
January 25, 2011 18:41
-
-
Save eltimn/795373 to your computer and use it in GitHub Desktop.
Joda Period Field
This file contains 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
import org.joda.time.{DateTime, DateTimeConstants, Period => JodaPeriod} | |
import org.joda.time.format.ISOPeriodFormat | |
object waiverSetting extends StringField(this, 32) { | |
override def optional_? = true | |
override def displayName = "Waiver Period" | |
val periodFormatter = ISOPeriodFormat.standard | |
override def defaultValue = periodFormatter.print(new JodaPeriod) | |
def period: JodaPeriod = periodFormatter.parsePeriod(value) | |
def setFromForm(d: Int, h: Int, m: Int) = setBox(Full( | |
periodFormatter.print(new JodaPeriod(0, 0, 0, d, h, m, 0, 0)) | |
)) | |
def friendly = { | |
val fws = period.toString(meta.waiverFormatter) | |
if (fws.length == 0) | |
"None" | |
else | |
fws | |
} | |
private object waiverDays extends RequestVar[Int](period.getDays) | |
private object waiverHours extends RequestVar[Int](period.getHours) | |
private object waiverMinutes extends RequestVar[Int](period.getMinutes) | |
override def toForm = Full( | |
SHtml.selectObj[Int](List.range(0, 7).map(i => (i, i.toString)), Full(waiverDays.is), waiverDays(_)) ++ | |
<span style="margin-left: 4px;">Days / </span> ++ | |
SHtml.selectObj[Int](List.range(0, 24).map(i => (i, i.toString)), Full(waiverHours.is), waiverHours(_)) ++ | |
<span style="margin-left: 4px;">Hours / </span> ++ | |
SHtml.selectObj[Int](List.range(0, 60).map(i => (i, i.toString)), Full(waiverMinutes.is), waiverMinutes(_)) ++ | |
<span style="margin-left: 4px;">Minutes</span> ++ | |
SHtml.hidden(processForm _) | |
) | |
private def processForm() { | |
setBox(Full( | |
periodFormatter.print(new JodaPeriod(0, 0, 0, waiverDays.is, waiverHours.is, waiverMinutes.is, 0, 0)) | |
)) | |
} | |
override def helpAsHtml = Full(Text("Dropped players will not be available for pick up until after the specified period of time.")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment