Search in sources :

Example 26 with ContainerTag

use of j2html.tags.ContainerTag in project civiform by seattle-uat.

the class ApplicantQuestionRenderer method renderInternal.

/**
 * Renders an applicant question's text, help text, errors, and the given form content.
 *
 * <p>In some cases, like text questions and number questions, the question errors are rendered in
 * the form content, so we offer the ability to specify whether or not this method should render
 * the question errors here.
 */
Tag renderInternal(Messages messages, Tag questionFormContent, boolean shouldDisplayQuestionErrors) {
    ContainerTag questionTextDiv = div().with(div().withClasses(ReferenceClasses.APPLICANT_QUESTION_TEXT, ApplicantStyles.QUESTION_TEXT).with(TextFormatter.createLinksAndEscapeText(question.getQuestionText()))).with(div().withClasses(ReferenceClasses.APPLICANT_QUESTION_HELP_TEXT, ApplicantStyles.QUESTION_HELP_TEXT).with(TextFormatter.createLinksAndEscapeText(question.getQuestionHelpText()))).withClasses(Styles.MB_4);
    if (shouldDisplayQuestionErrors) {
        // Question error text
        questionTextDiv.with(BaseHtmlView.fieldErrors(messages, question.getQuestionErrors()));
    }
    if (question.isRequiredButWasSkippedInCurrentProgram()) {
        String requiredQuestionMessage = messages.at(MessageKey.VALIDATION_REQUIRED.getKeyName());
        questionTextDiv.with(div().withClasses(Styles.P_1, Styles.TEXT_RED_600).withText("*" + requiredQuestionMessage));
    }
    return div().withId(question.getContextualizedPath().toString()).withClasses(Styles.MX_AUTO, Styles.MB_8, getReferenceClass(), getRequiredClass()).with(questionTextDiv).with(questionFormContent);
}
Also used : ContainerTag(j2html.tags.ContainerTag)

Example 27 with ContainerTag

use of j2html.tags.ContainerTag in project civiform by seattle-uat.

the class ApplicantUpsellCreateAccountView method render.

/**
 * Renders a sign-up page with a baked-in redirect.
 */
public Content render(Http.Request request, String redirectTo, Account account, String programTitle, String applicantName, Long applicationId, Messages messages, Optional<String> banner) {
    String title = messages.at(MessageKey.TITLE_APPLICATION_CONFIRMATION.getKeyName());
    HtmlBundle bundle = layout.getBundle().setTitle(title);
    ContainerTag createAccountBox = div().withClasses(Styles.BORDER, Styles.BORDER_GRAY_200, Styles.ROUNDED_2XL, Styles.SHADOW_MD, Styles.BG_WHITE, Styles.P_4, StyleUtils.responsiveSmall(Styles.P_6), Styles.MY_6).with(h2(messages.at(MessageKey.TITLE_CREATE_AN_ACCOUNT.getKeyName())).withClasses(Styles.MB_4)).with(div(messages.at(MessageKey.CONTENT_PLEASE_CREATE_ACCOUNT.getKeyName())).withClasses(Styles.MB_4)).with(div().withClasses(Styles.FLEX, Styles.FLEX_COL, Styles.GAP_4, StyleUtils.responsiveSmall(Styles.FLEX_ROW)).with(div().withClasses(Styles.FLEX_GROW)).with(new LinkElement().setHref(redirectTo).setText(messages.at(MessageKey.LINK_APPLY_TO_ANOTHER_PROGRAM.getKeyName())).asButton().withClasses(ApplicantStyles.BUTTON_NOT_RIGHT_NOW)).with(new LinkElement().setHref(org.pac4j.play.routes.LogoutController.logout().url()).setText(messages.at(MessageKey.LINK_ALL_DONE.getKeyName())).asButton().withClasses(ApplicantStyles.BUTTON_NOT_RIGHT_NOW)).with(new LinkElement().setHref(routes.LoginController.idcsLoginWithRedirect(Optional.of(redirectTo)).url()).setText(messages.at(MessageKey.LINK_CREATE_ACCOUNT_OR_SIGN_IN.getKeyName())).asButton().withClasses(ApplicantStyles.BUTTON_CREATE_ACCOUNT)));
    ContainerTag content = div().with(div(messages.at(MessageKey.CONTENT_CONFIRMED.getKeyName(), programTitle, applicationId)).withClasses(Styles.TEXT_LG));
    // Don't show "create an account" upsell box to TIs, or anyone with an email address already.
    if (Strings.isNullOrEmpty(account.getEmailAddress()) && account.getMemberOfGroup().isEmpty()) {
        content.with(createAccountBox);
    } else {
        content.with(new LinkElement().setHref(redirectTo).setText(messages.at(MessageKey.LINK_APPLY_TO_ANOTHER_PROGRAM.getKeyName())).asAnchorText());
    }
    if (banner.isPresent()) {
        bundle.addToastMessages(ToastMessage.error(banner.get()));
    }
    bundle.addMainStyles(ApplicantStyles.MAIN_PROGRAM_APPLICATION).addMainContent(h1(title).withClasses(ApplicantStyles.H1_PROGRAM_APPLICATION), content);
    return layout.renderWithNav(request, applicantName, messages, bundle);
}
Also used : HtmlBundle(views.HtmlBundle) LinkElement(views.components.LinkElement) ContainerTag(j2html.tags.ContainerTag)

Example 28 with ContainerTag

use of j2html.tags.ContainerTag in project civiform by seattle-uat.

the class AwsStorageDevViewStrategy method getFileUploadForm.

@Override
public ContainerTag getFileUploadForm(ViewUtils viewUtils, StorageUploadRequest storageUploadRequest, HtmlBundle bundle) throws RuntimeException {
    if (!(storageUploadRequest instanceof SignedS3UploadRequest)) {
        throw new RuntimeException("Trying to upload a file to localhost (AWS emulator) dev file storage using incorrect" + " upload request type.");
    }
    SignedS3UploadRequest request = (SignedS3UploadRequest) storageUploadRequest;
    ContainerTag formTag = form().attr(ENCTYPE, "multipart/form-data").with(input().withType("input").withName("key").withValue(request.key())).with(input().withType("hidden").withName("success_action_redirect").withValue(request.successActionRedirect())).with(input().withType("text").withName("X-Amz-Credential").withValue(request.credential()));
    if (!request.securityToken().isEmpty()) {
        formTag.with(input().withType("hidden").withName("X-Amz-Security-Token").withValue(request.securityToken()));
    }
    return formTag.with(input().withType("text").withName("X-Amz-Algorithm").withValue(request.algorithm())).with(input().withType("text").withName("X-Amz-Date").withValue(request.date())).with(input().withType("hidden").withName("Policy").withValue(request.policy())).with(input().withType("hidden").withName("X-Amz-Signature").withValue(request.signature())).with(input().withType("file").withName("file")).with(TagCreator.button(text("Upload to Amazon S3")).withType("submit")).withMethod("post").withAction(request.actionLink());
}
Also used : ContainerTag(j2html.tags.ContainerTag) SignedS3UploadRequest(services.cloud.aws.SignedS3UploadRequest)

Example 29 with ContainerTag

use of j2html.tags.ContainerTag in project civiform by seattle-uat.

the class EnumeratorQuestionRenderer method render.

@Override
public Tag render(ApplicantQuestionRendererParams params) {
    Messages messages = params.messages();
    EnumeratorQuestion enumeratorQuestion = question.createEnumeratorQuestion();
    String localizedEntityType = enumeratorQuestion.getEntityType();
    ImmutableList<String> entityNames = enumeratorQuestion.getEntityNames();
    ContainerTag enumeratorFields = div().withId(ENUMERATOR_FIELDS_ID);
    for (int index = 0; index < entityNames.size(); index++) {
        enumeratorFields.with(enumeratorField(messages, localizedEntityType, question.getContextualizedPath(), Optional.of(entityNames.get(index)), Optional.of(index)));
    }
    ContainerTag errorContent = div(enumeratorQuestion.getQuestionErrorMessage().getMessage(messages)).withClasses(ReferenceClasses.ENUMERATOR_ERROR, BaseStyles.FORM_ERROR_TEXT_BASE, enumeratorQuestion.hasConditionErrors() ? "" : Styles.HIDDEN);
    Tag enumeratorQuestionFormContent = div().with(errorContent).with(hiddenDeleteInputTemplate()).with(enumeratorFields).with(BaseHtmlView.button(ADD_ELEMENT_BUTTON_ID, String.format("+ %s", messages.at(MessageKey.ENUMERATOR_BUTTON_ADD_ENTITY.getKeyName(), localizedEntityType))).withClasses(ApplicantStyles.BUTTON_ENUMERATOR_ADD_ENTITY, StyleUtils.disabled(Styles.BG_GRAY_200, Styles.TEXT_GRAY_400)));
    return renderInternal(messages, enumeratorQuestionFormContent, false);
}
Also used : Messages(play.i18n.Messages) EnumeratorQuestion(services.applicant.question.EnumeratorQuestion) ContainerTag(j2html.tags.ContainerTag) ContainerTag(j2html.tags.ContainerTag) EmptyTag(j2html.tags.EmptyTag) Tag(j2html.tags.Tag)

Example 30 with ContainerTag

use of j2html.tags.ContainerTag in project core by z1lc.

the class WikipediaConnector method writeHtmlFile.

private void writeHtmlFile(List<WikiPerson> sortedPeople) {
    ContainerTag html = html().with(head().with(style().with(new DomContent() {

        @Override
        public void renderModel(Appendable writer, Object model) throws IOException {
            writer.append(new HTMLOutputBuilder().getStyleSheet());
        }
    })).with(meta().attr("charset", "UTF-8")).with(title("Top " + sortedPeople.size() + " Most-visited English Wikipedia Articles"))).with(body().with(table().attr("align", "center").with(tr().with(th("WikiArticle"), th("Hits▼"))).with(sortedPeople.stream().map(WikiPerson::toArticle).map(wikiArticle -> tr().with(td(a(wikiArticle.getPrettyTitle()).withHref(wikiArticle.getURL())).withClass("wiki_article_title"), td(NumberFormat.getNumberInstance(Locale.US).format(wikiArticle.getHits())).withClass("wiki_article_hits"))).collect(Collectors.toList()))).with(sortedPeople.stream().map(WikiPerson::toArticle).map(article -> p(article.getURL())).collect(Collectors.toList())));
    File loansTarget = new File(CrossPlatformUtils.getRootPathIncludingTrailingSlash().orElseThrow() + "out/wikipedia.html");
    log.info("Writing to %s", loansTarget.getAbsolutePath());
    try (PrintWriter writer = Unchecked.get(() -> new PrintWriter(loansTarget, StandardCharsets.UTF_8))) {
        writer.print(html.render());
    }
}
Also used : JsonObject(com.google.gson.JsonObject) java.util(java.util) Inject(com.google.inject.Inject) CookieSpecs(org.apache.http.client.config.CookieSpecs) RequestConfig(org.apache.http.client.config.RequestConfig) JsonParser(com.google.gson.JsonParser) Unchecked(com.robertsanek.util.Unchecked) NumberFormat(java.text.NumberFormat) EntityUtils(org.apache.http.util.EntityUtils) JsonElement(com.google.gson.JsonElement) Log(com.robertsanek.util.Log) CrossPlatformUtils(com.robertsanek.util.platform.CrossPlatformUtils) HTMLOutputBuilder(com.robertsanek.passivekiva.HTMLOutputBuilder) Matcher(java.util.regex.Matcher) Request(org.apache.http.client.fluent.Request) TagCreator(j2html.TagCreator) PrintWriter(java.io.PrintWriter) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ImmutableSet(com.google.common.collect.ImmutableSet) WikiPerson(com.robertsanek.data.etl.remote.wikipedia.WikiPerson) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Logs(com.robertsanek.util.Logs) ContainerTag(j2html.tags.ContainerTag) DataQualityBase(com.robertsanek.data.quality.anki.DataQualityBase) AtomicLong(java.util.concurrent.atomic.AtomicLong) DomContent(j2html.tags.DomContent) HttpGet(org.apache.http.client.methods.HttpGet) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Pattern(java.util.regex.Pattern) FilenameUtils(org.apache.commons.io.FilenameUtils) HttpClients(org.apache.http.impl.client.HttpClients) HTMLOutputBuilder(com.robertsanek.passivekiva.HTMLOutputBuilder) DomContent(j2html.tags.DomContent) JsonObject(com.google.gson.JsonObject) ContainerTag(j2html.tags.ContainerTag) File(java.io.File) WikiPerson(com.robertsanek.data.etl.remote.wikipedia.WikiPerson) PrintWriter(java.io.PrintWriter)

Aggregations

ContainerTag (j2html.tags.ContainerTag)150 Tag (j2html.tags.Tag)30 TagCreator.div (j2html.TagCreator.div)20 HtmlBundle (views.HtmlBundle)20 Inject (javax.inject.Inject)17 List (java.util.List)13 TagCreator (j2html.TagCreator)12 DomContent (j2html.tags.DomContent)12 Mav (io.datarouter.web.handler.mav.Mav)11 LinkElement (views.components.LinkElement)11 J2HtmlTable (io.datarouter.web.html.j2html.J2HtmlTable)10 DatarouterWebRequireJsV2 (io.datarouter.web.requirejs.DatarouterWebRequireJsV2)10 TagCreator.a (j2html.TagCreator.a)10 BaseHandler (io.datarouter.web.handler.BaseHandler)9 Bootstrap4PageFactory (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory)8 TagCreator.td (j2html.TagCreator.td)8 ArrayList (java.util.ArrayList)8 Optional (java.util.Optional)8 TagCreator.each (j2html.TagCreator.each)7 ZoneId (java.time.ZoneId)7