use of services.question.types.QuestionType in project civiform by seattle-uat.
the class QuestionEditView method buildQuestionForm.
private ContainerTag buildQuestionForm(QuestionForm questionForm, SelectWithLabel enumeratorOptions, boolean submittable, boolean forCreate) {
QuestionType questionType = questionForm.getQuestionType();
ContainerTag formTag = form().withMethod("POST");
// The question enumerator and name fields should not be changed after the question is created.
// If this form is not for creation, the fields are disabled, and hidden fields to pass
// enumerator
// and name data are added.
formTag.with(enumeratorOptions.setDisabled(!forCreate).getContainer());
formTag.with(repeatedQuestionInformation());
FieldWithLabel nameField = FieldWithLabel.input().setId("question-name-input").setFieldName(QUESTION_NAME_FIELD).setLabelText("Name").setDisabled(!submittable).setPlaceholderText("The name displayed in the question builder").setValue(questionForm.getQuestionName());
formTag.with(nameField.setDisabled(!forCreate).getContainer());
if (!forCreate) {
formTag.with(input().isHidden().withName(QUESTION_NAME_FIELD).withValue(questionForm.getQuestionName()), input().isHidden().withName(QUESTION_ENUMERATOR_FIELD).withValue(questionForm.getEnumeratorId().map(String::valueOf).orElse(NO_ENUMERATOR_ID_STRING)));
}
ContainerTag questionHelpTextField = FieldWithLabel.textArea().setId("question-help-text-textarea").setFieldName("questionHelpText").setLabelText("Question help text").setPlaceholderText("The question help text displayed to the applicant").setDisabled(!submittable).setValue(questionForm.getQuestionHelpText()).getContainer();
if (questionType.equals(QuestionType.STATIC)) {
// Hide help text for static questions.
questionHelpTextField.withClasses(Styles.HIDDEN);
}
formTag.with(FieldWithLabel.textArea().setId("question-description-textarea").setFieldName("questionDescription").setLabelText("Description").setPlaceholderText("The description displayed in the question builder").setDisabled(!submittable).setValue(questionForm.getQuestionDescription()).getContainer(), FieldWithLabel.textArea().setId("question-text-textarea").setFieldName("questionText").setLabelText("Question text").setPlaceholderText("The question text displayed to the applicant").setDisabled(!submittable).setValue(questionForm.getQuestionText()).getContainer(), questionHelpTextField).with(formQuestionTypeSelect(questionType));
formTag.with(QuestionConfig.buildQuestionConfig(questionForm, messages));
if (!ExporterService.NON_EXPORTED_QUESTION_TYPES.contains(questionType)) {
formTag.with(div().withId("demographic-field-content").with(buildDemographicFields(questionForm, submittable)));
}
return formTag;
}
use of services.question.types.QuestionType in project civiform by seattle-uat.
the class QuestionEditView method renderNewQuestionForm.
private Content renderNewQuestionForm(Request request, QuestionForm questionForm, ImmutableList<EnumeratorQuestionDefinition> enumeratorQuestionDefinitions, Optional<String> message) {
QuestionType questionType = questionForm.getQuestionType();
String title = String.format("New %s question", questionType.toString().toLowerCase());
ContainerTag formContent = buildQuestionContainer(title, questionForm).with(buildNewQuestionForm(questionForm, enumeratorQuestionDefinitions).with(makeCsrfTokenInputTag(request)));
if (message.isPresent()) {
formContent.with(ToastMessage.error(message.get()).setDismissible(false).getContainerTag());
}
return renderWithPreview(formContent, questionType, title);
}
use of services.question.types.QuestionType in project civiform by seattle-uat.
the class Question method setQuestionOptions.
/**
* Add {@link QuestionOption}s to the builder, taking into account legacy columns.
*
* <p>The majority of questions should have a `questionOptions` and not `legacyQuestionOptions`.
*/
private void setQuestionOptions(QuestionDefinitionBuilder builder) throws InvalidQuestionTypeException {
if (!QuestionType.of(questionType).isMultiOptionType()) {
return;
}
// `legacyQuestionOptions` is a legacy implementation that only supported a single locale.
if (questionOptions != null) {
builder.setQuestionOptions(questionOptions);
return;
}
// If the multi option question does have legacyQuestionOptions, we can assume there is only one
// locale and convert the strings to QuestionOption instances each with a single locale.
Locale firstKey = legacyQuestionOptions.keySet().stream().iterator().next();
ImmutableList<QuestionOption> options = Streams.mapWithIndex(legacyQuestionOptions.get(firstKey).stream(), (optionText, i) -> QuestionOption.create(Long.valueOf(i), Long.valueOf(i), LocalizedStrings.of(firstKey, optionText))).collect(toImmutableList());
builder.setQuestionOptions(options);
}
use of services.question.types.QuestionType in project civiform by seattle-uat.
the class AdminQuestionController method newOne.
/**
* Return a HTML page containing a form to create a new question in the draft version.
*/
@Secure(authorizers = Authorizers.Labels.CIVIFORM_ADMIN)
public Result newOne(Request request, String type) {
QuestionType questionType;
try {
questionType = QuestionType.of(type);
} catch (InvalidQuestionTypeException e) {
return badRequest(invalidQuestionTypeMessage(type));
}
ImmutableList<EnumeratorQuestionDefinition> enumeratorQuestionDefinitions = service.getReadOnlyQuestionService().toCompletableFuture().join().getUpToDateEnumeratorQuestions();
try {
return ok(editView.renderNewQuestionForm(request, questionType, enumeratorQuestionDefinitions));
} catch (UnsupportedQuestionTypeException e) {
return badRequest(e.getMessage());
}
}
use of services.question.types.QuestionType in project civiform by seattle-uat.
the class QuestionEditView method renderViewQuestionForm.
/**
* Render a read-only non-submittable question form.
*/
public Content renderViewQuestionForm(QuestionDefinition questionDefinition, Optional<QuestionDefinition> maybeEnumerationQuestionDefinition) throws InvalidQuestionTypeException {
QuestionForm questionForm = QuestionFormBuilder.create(questionDefinition);
QuestionType questionType = questionForm.getQuestionType();
String title = String.format("View %s question", questionType.toString().toLowerCase());
SelectWithLabel enumeratorOption = enumeratorOptionsFromMaybeEnumerationQuestionDefinition(maybeEnumerationQuestionDefinition);
ContainerTag formContent = buildQuestionContainer(title, QuestionFormBuilder.create(questionDefinition)).with(buildViewOnlyQuestionForm(questionForm, enumeratorOption));
return renderWithPreview(formContent, questionType, title);
}
Aggregations