Skip to content

Instantly share code, notes, and snippets.

@mgladdish
mgladdish / Job.java
Created October 10, 2014 06:59
Concurrent Distinct Job Executor
package uk.co.odum.sky;
public class Job {
private String jobName;
public Job(String jobName) {
this.jobName = jobName;
}
@mgladdish
mgladdish / NestingMultipleChoiceV1.scala
Created June 12, 2018 12:38
First draft of a nesting multiple choice trait
trait NestingMultipleChoice[C <: Messages[C]] extends WidgetGroup {
def nestedWidgets: Map[String, Widget]
def nestingMultipleChoiceWidget: MultipleChoice[C]
override lazy val widgets: Seq[Widget] = nestingMultpleChoiceWidget +: nestedWidgets.values.toSeq
}
trait NestingMultipleChoice[C <: Messages[C]] extends WidgetGroup {
def nestedWidgets: Map[String, Widget]
def nestingMultipleChoiceWidget: MultipleChoice[C]
override lazy val widgets: Seq[Widget] = nestingMultpleChoiceWidget +: nestedWidgets.values.toSeq
def templateChoices(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[List[Map[String, Any]]] = {
nestingMultipleChoiceWidget.choicesForTemplate.map(...
trait NestingMultipleChoice[C <: Messages[C]] extends WidgetGroup {
def nestedWidgets: Map[String, Widget]
def nestingMultipleChoiceWidget: MultipleChoice[C]
override lazy val widgets: Seq[Widget] = nestingMultpleChoiceWidget +: nestedWidgets.values.toSeq
def templateChoices(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[List[Map[String, Any]]] = {
nestingMultipleChoiceWidget.choicesForTemplate.map(...
case class NestingCheckboxes[C <: Messages[C]](... nestedWidgets: Map[String, Widget]) extends NestingMultipleChoice[C] {
override val nestingMultipleChoiceWidget = new Checkbox(...)
}
case class NestingCheckboxes[C <: Messages[C]](... nestedWidgets: Map[String, Widget]) extends NestingMultipleChoice[C] {
override val nestingMultipleChoiceWidget = new Checkbox(...) {
override def render(form: Form, errors: ValidationErrors, requestInfo: RequestInfo)(...): Future[String] = {
...
// pass result of templateChoices(form, errors, requestInfo) to my template and return the rendered result
}
}
}
{{#choices}}
<div class="multiple-choice">
<input id="{{id}}_{{value}}" name="{{name}}" type="checkbox" value="{{value}}" {{#selected}} checked="checked" {{/selected}} />
<label for="{{id}}_{{value}}">{{{text}}}</label>
</div>
{{{nestedWidget}}} <!-- addition to output the html of the already-rendered nested widget -->
{{/choices}}
def nestedInput[M <: Messages[M]](name: String, ...)(...) =
Input(name, ..., layoutTemplateName = "nestedWidgetBoilerplate.mustache", ...)
@mgladdish
mgladdish / contactMethods.properties
Last active June 12, 2018 17:17
Properties file for check box options
EMAIL=Email
PHONE=Phone
TEXT=Text message
section(
messages = "sectionText", // the name of properties bundle containing section-level text
nestingCheckboxes(
"myCheckboxes", // the unique name of our widget
"questionWording", // the name of the properties bundle containing text for the widget
required, // constraints applied to the widget
"contactMethods", // the name of the properties bundle containing the key and labels for each checkbox choice
Map( // our nested widgets