Search in sources :

Example 26 with HtmlBundle

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);
}
Also used : HtmlBundle(views.HtmlBundle) ContainerTag(j2html.tags.ContainerTag)

Example 27 with 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);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Inject(com.google.inject.Inject) Styles(views.style.Styles) LinkElement(views.components.LinkElement) Content(play.twirl.api.Content) TagCreator.h1(j2html.TagCreator.h1) TagCreator.h2(j2html.TagCreator.h2) ImmutableList(com.google.common.collect.ImmutableList) Block(services.applicant.Block) HtmlBundle(views.HtmlBundle) BaseHtmlView(views.BaseHtmlView) TagCreator.p(j2html.TagCreator.p) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TagCreator.each(j2html.TagCreator.each) Instant(java.time.Instant) TagCreator.a(j2html.TagCreator.a) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) URLEncoder(java.net.URLEncoder) LocalDate(java.time.LocalDate) ReferenceClasses(views.style.ReferenceClasses) TagCreator.div(j2html.TagCreator.div) AnswerData(services.applicant.AnswerData) Tag(j2html.tags.Tag) BaseHtmlLayout(views.BaseHtmlLayout) AnswerData(services.applicant.AnswerData) HtmlBundle(views.HtmlBundle) Block(services.applicant.Block) Tag(j2html.tags.Tag)

Example 28 with 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);
}
Also used : HtmlBundle(views.HtmlBundle) ContainerTag(j2html.tags.ContainerTag) Tag(j2html.tags.Tag) Modal(views.components.Modal)

Example 29 with 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);
}
Also used : HtmlBundle(views.HtmlBundle) LinkElement(views.components.LinkElement) Http(play.mvc.Http) ContainerTag(j2html.tags.ContainerTag) Tag(j2html.tags.Tag) ContainerTag(j2html.tags.ContainerTag) Modal(views.components.Modal)

Example 30 with 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);
}
Also used : HtmlBundle(views.HtmlBundle)

Aggregations

HtmlBundle (views.HtmlBundle)37 ContainerTag (j2html.tags.ContainerTag)21 Tag (j2html.tags.Tag)13 LinkElement (views.components.LinkElement)10 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)6 TagCreator.div (j2html.TagCreator.div)6 TagCreator.each (j2html.TagCreator.each)6 TagCreator.p (j2html.TagCreator.p)6 ZoneId (java.time.ZoneId)6 Content (play.twirl.api.Content)6 BaseHtmlView (views.BaseHtmlView)6 ReferenceClasses (views.style.ReferenceClasses)6 Styles (views.style.Styles)6 Inject (com.google.inject.Inject)5 controllers.admin.routes (controllers.admin.routes)5 TagCreator.h1 (j2html.TagCreator.h1)5 Optional (java.util.Optional)5 Http (play.mvc.Http)5 ProgramDefinition (services.program.ProgramDefinition)4 AdminLayout (views.admin.AdminLayout)4