use of views.HtmlBundle in project civiform by seattle-uat.
the class ApiKeyNewOneView method render.
public Content render(Request request, ImmutableSet<String> programNames, Optional<DynamicForm> dynamicForm) {
String title = "Create a new API key";
ContainerTag formTag = form().withMethod("POST").with(makeCsrfTokenInputTag(request), h2("Name"), p("A human-readable name for identifying this API key in the UI."), setStateIfPresent(FieldWithLabel.input().setFieldName(ApiKeyService.FORM_FIELD_NAME_KEY_NAME).setId(ApiKeyService.FORM_FIELD_NAME_KEY_NAME).setLabelText("API key name"), dynamicForm, ApiKeyService.FORM_FIELD_NAME_KEY_NAME).getContainer(), h2("Expiration date"), p(EXPIRATION_DESCRIPTION), setStateIfPresent(FieldWithLabel.date().setFieldName(ApiKeyService.FORM_FIELD_NAME_EXPIRATION).setId(ApiKeyService.FORM_FIELD_NAME_EXPIRATION).setLabelText("Expiration date"), dynamicForm, ApiKeyService.FORM_FIELD_NAME_EXPIRATION).getContainer(), h2("Allowed IP addresses"), p(SUBNET_DESCRIPTION), setStateIfPresent(FieldWithLabel.input().setFieldName(ApiKeyService.FORM_FIELD_NAME_SUBNET).setId(ApiKeyService.FORM_FIELD_NAME_SUBNET).setLabelText("API key subnet"), dynamicForm, ApiKeyService.FORM_FIELD_NAME_SUBNET).getContainer());
formTag.with(h2("Allowed programs"), p("Select the programs this key grants read access to."));
for (String name : programNames.stream().sorted().collect(ImmutableList.toImmutableList())) {
formTag.with(FieldWithLabel.checkbox().setFieldName(programReadGrantFieldName(name)).setLabelText(name).setId(slugifier.slugify(name)).setValue("true").getContainer());
}
ContainerTag contentDiv = div().withClasses(Styles.PX_20).with(h1(title).withClasses(Styles.MY_4), formTag.with(submitButton("Save").withId("apikey-submit-button")).withAction(routes.AdminApiKeysController.create().url()));
HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(contentDiv);
return layout.renderCentered(htmlBundle);
}
use of views.HtmlBundle in project civiform by seattle-uat.
the class ProgramApplicationView method render.
public Content render(long programId, String programName, long applicationId, String applicantNameWithApplicationId, ImmutableList<Block> blocks, ImmutableList<AnswerData> answers) {
String title = "Program Application View";
ListMultimap<Block, AnswerData> blockToAnswers = ArrayListMultimap.create();
for (AnswerData answer : answers) {
Block answerBlock = blocks.stream().filter(block -> block.getId().equals(answer.blockId())).findFirst().orElseThrow();
blockToAnswers.put(answerBlock, answer);
}
Tag contentDiv = div().withId("application-view").withClasses(Styles.PX_20).with(h2("Program: " + programName).withClasses(Styles.MY_4), h1(applicantNameWithApplicationId).withClasses(Styles.MY_4), renderDownloadButton(programId, applicationId), each(blocks, block -> renderApplicationBlock(programId, block, blockToAnswers.get(block))));
HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(contentDiv);
return layout.render(htmlBundle);
}
use of views.HtmlBundle in project civiform by seattle-uat.
the class ProgramBlockEditView method render.
public Content render(Request request, ProgramDefinition programDefinition, long blockId, BlockForm blockForm, BlockDefinition blockDefinition, ImmutableList<ProgramQuestionDefinition> blockQuestions, String message, ImmutableList<QuestionDefinition> questions) {
Tag csrfTag = makeCsrfTokenInputTag(request);
String title = String.format("Edit %s", blockDefinition.name());
String blockUpdateAction = controllers.admin.routes.AdminProgramBlocksController.update(programDefinition.id(), blockId).url();
Modal blockDescriptionEditModal = blockDescriptionModal(csrfTag, blockForm, blockUpdateAction);
HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainStyles(Styles.FLEX, Styles.FLEX_COL).addMainContent(addFormEndpoints(csrfTag, programDefinition.id(), blockId), layout.renderProgramInfo(programDefinition), div().withId("program-block-info").withClasses(Styles.FLEX, Styles.FLEX_GROW, Styles._MX_2).with(blockOrderPanel(request, programDefinition, blockId)).with(blockEditPanel(programDefinition, blockDefinition, blockForm, blockQuestions, questions, blockDefinition.isEnumerator(), csrfTag, blockDescriptionEditModal.getButton())).with(questionBankPanel(questions, programDefinition, blockDefinition, csrfTag))).addModals(blockDescriptionEditModal);
// Add toast messages
if (request.flash().get("error").isPresent()) {
htmlBundle.addToastMessages(ToastMessage.error(request.flash().get("error").get()).setDuration(-1));
}
if (message.length() > 0) {
htmlBundle.addToastMessages(ToastMessage.error(message).setDismissible(false));
}
return layout.renderCentered(htmlBundle);
}
use of views.HtmlBundle in project civiform by seattle-uat.
the class ProgramBlockPredicatesEditView method render.
public Content render(Http.Request request, ProgramDefinition programDefinition, BlockDefinition blockDefinition, ImmutableList<QuestionDefinition> potentialPredicateQuestions) {
String title = String.format("Visibility condition for %s", blockDefinition.name());
Tag csrfTag = makeCsrfTokenInputTag(request);
String predicateUpdateUrl = routes.AdminProgramBlockPredicatesController.update(programDefinition.id(), blockDefinition.id()).url();
ImmutableList<Modal> modals = predicateFormModals(blockDefinition.name(), potentialPredicateQuestions, predicateUpdateUrl, csrfTag);
String removePredicateUrl = routes.AdminProgramBlockPredicatesController.destroy(programDefinition.id(), blockDefinition.id()).url();
String removePredicateFormId = "visibility-predicate-form-remove";
Tag removePredicateForm = form(csrfTag).withId(removePredicateFormId).withMethod(POST).withAction(removePredicateUrl).with(submitButton("Remove visibility condition").attr(Attr.FORM, removePredicateFormId).attr(blockDefinition.visibilityPredicate().isEmpty() ? Attr.DISABLED : ""));
String editBlockUrl = routes.AdminProgramBlocksController.edit(programDefinition.id(), blockDefinition.id()).url();
ContainerTag content = div().withClasses(Styles.MX_6, Styles.MY_10, Styles.FLEX, Styles.FLEX_COL, Styles.GAP_6).with(div().withClasses(Styles.FLEX, Styles.FLEX_ROW).with(h1(title).withClasses(Styles.FONT_BOLD, Styles.TEXT_XL)).with(div().withClasses(Styles.FLEX_GROW)).with(new LinkElement().setHref(editBlockUrl).setText(String.format("Return to edit %s", blockDefinition.name())).asAnchorText())).with(div().with(h2(H2_CURRENT_VISIBILITY_CONDITION).withClasses(Styles.FONT_SEMIBOLD, Styles.TEXT_LG)).with(div(blockDefinition.visibilityPredicate().isPresent() ? blockDefinition.visibilityPredicate().get().toDisplayString(blockDefinition.name(), potentialPredicateQuestions) : TEXT_NO_VISIBILITY_CONDITIONS).withClasses(ReferenceClasses.PREDICATE_DISPLAY))).with(removePredicateForm).with(div().with(h2(H2_NEW_VISIBILITY_CONDITION).withClasses(Styles.FONT_SEMIBOLD, Styles.TEXT_LG)).with(div(TEXT_NEW_VISIBILITY_CONDITION).withClasses(Styles.MB_2)).with(modals.isEmpty() ? text(TEXT_NO_AVAILABLE_QUESTIONS) : renderPredicateModalTriggerButtons(modals)));
HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(layout.renderProgramInfo(programDefinition), content);
Http.Flash flash = request.flash();
if (flash.get("error").isPresent()) {
htmlBundle.addToastMessages(ToastMessage.error(flash.get("error").get()).setDuration(-1));
} else if (flash.get("success").isPresent()) {
htmlBundle.addToastMessages(ToastMessage.success(flash.get("success").get()).setDuration(-1));
}
for (Modal modal : modals) {
htmlBundle = htmlBundle.addModals(modal);
}
return layout.renderCentered(htmlBundle);
}
use of views.HtmlBundle in project civiform by seattle-uat.
the class ProgramIndexView method render.
/**
* For each program in the list, render the program information along with an "Apply" button that
* redirects the user to that program's application.
*
* @param messages the localized {@link Messages} for the current applicant
* @param applicantId the ID of the current applicant
* @param draftPrograms an {@link ImmutableList} of {@link ProgramDefinition}s which the applicant
* has draft applications of
* @param activePrograms an {@link ImmutableList} of {@link ProgramDefinition}s with the most
* recent published versions
* @return HTML content for rendering the list of available programs
*/
public Content render(Messages messages, Http.Request request, long applicantId, Optional<String> userName, ImmutableList<ProgramDefinition> draftPrograms, ImmutableList<ProgramDefinition> activePrograms, Optional<String> banner) {
HtmlBundle bundle = layout.getBundle();
bundle.setTitle(messages.at(MessageKey.CONTENT_GET_BENEFITS.getKeyName()));
if (banner.isPresent()) {
bundle.addToastMessages(ToastMessage.alert(banner.get()));
}
bundle.addMainContent(topContent(messages.at(MessageKey.CONTENT_GET_BENEFITS.getKeyName()), messages.at(MessageKey.CONTENT_CIVIFORM_DESCRIPTION_1.getKeyName()), messages.at(MessageKey.CONTENT_CIVIFORM_DESCRIPTION_2.getKeyName())), mainContent(messages, draftPrograms, activePrograms, applicantId, messages.lang().toLocale()));
return layout.renderWithNav(request, userName, messages, bundle);
}
Aggregations