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);
}
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);
}
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());
}
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);
}
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());
}
}
Aggregations