Search in sources :

Example 11 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-directory by phax.

the class PagePublicContact method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bShowForm = true;
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
        final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
        final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
        final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
        final String sReCaptcha = StringHelper.trim(aWPEC.params().getAsString("g-recaptcha-response"));
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
        if (StringHelper.hasNoText(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
        else if (!EmailAddressHelper.isValid(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
        if (StringHelper.hasNoText(sText))
            aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
        if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptcha)) {
            if (!CaptchaSessionSingleton.getInstance().isChecked()) {
                // Check only if no other errors occurred
                if (ReCaptchaServerSideValidator.check("6LfZFS0UAAAAAONDJHyDnuUUvMB_oNmJxz9Utxza", sReCaptcha).isFailure())
                    aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
                else
                    CaptchaSessionSingleton.getInstance().setChecked();
            }
        }
        if (aFormErrors.isEmpty()) {
            final EmailData aEmailData = new EmailData(EEmailType.TEXT);
            aEmailData.setFrom(CPDPublisher.EMAIL_SENDER);
            aEmailData.to().add(new EmailAddress("pd@helger.com"));
            aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
            aEmailData.setSubject("[" + CPDPublisher.getApplication() + "] Contact Form - " + sName);
            final StringBuilder aSB = new StringBuilder();
            aSB.append("Contact form from " + CPDPublisher.getApplication() + " was filled out.\n\n");
            aSB.append("Name: ").append(sName).append("\n");
            aSB.append("Email: ").append(sEmail).append("\n");
            aSB.append("Topic: ").append(sTopic).append("\n");
            aSB.append("Text:\n").append(sText).append("\n");
            aEmailData.setBody(aSB.toString());
            ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
            aWPEC.postRedirectGetInternal(success("Thank you for your message. We will come back to you asap."));
        }
    }
    if (bShowForm) {
        aNodeList.addChild(info("Alternatively write an email to pd[at]helger.com - usually using the below form is more effective!"));
        aNodeList.addChild(warn("Please don't request any change of data via this contact form - contact your service provider instead. Thank you."));
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
        final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
        aSelect.addOption("SMP integration");
        aSelect.addOption("Website");
        aSelect.addOption("REST service");
        aSelect.addOption("SMP Statement of use");
        aSelect.addOption("General question");
        aSelect.addOptionPleaseSelect(aDisplayLocale);
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
        if (!CaptchaSessionSingleton.getInstance().isChecked()) {
            // Add visible Captcha
            aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create("6LfZFS0UAAAAAJaqpHJdFS_xxY7dqMQjXoBIQWOD", aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
        }
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
        aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EDefaultIcon.YES));
        aForm.addChild(new BootstrapButton().addChild("No thanks").setIcon(EDefaultIcon.CANCEL).setOnClick(aWPEC.getLinkToMenuItem(CMenuPublic.MENU_SEARCH_SIMPLE)));
    }
}
Also used : Locale(java.util.Locale) HCExtSelect(com.helger.photon.uicore.html.select.HCExtSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) EmailData(com.helger.smtp.data.EmailData) EmailAddress(com.helger.commons.email.EmailAddress) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 12 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-directory by phax.

the class PageSecureDeleteManually method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sParticipantID = aWPEC.params().getAsString(FIELD_PARTICIPANT_ID);
        final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
        if (StringHelper.hasNoText(sParticipantID))
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A participant ID must be provided.");
        else if (aParticipantID == null)
            aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The provided participant ID is syntactically invalid.");
        if (aFormErrors.isEmpty()) {
            int nDeleted = 0;
            try {
                nDeleted = PDMetaManager.getStorageMgr().deleteEntry(aParticipantID, null, false);
            } catch (final IOException ex) {
                // ignore
                nDeleted = -1;
            }
            if (nDeleted > 0)
                aWPEC.postRedirectGetInternal(success("The participant ID '" + aParticipantID.getURIEncoded() + "' was deleted (" + nDeleted + " rows)"));
            else
                aWPEC.postRedirectGetInternal(error("Error deleting participant ID '" + aParticipantID.getURIEncoded() + "'"));
        }
    }
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Participant ID").setCtrl(new HCEdit(new RequestField(FIELD_PARTICIPANT_ID, PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME + CIdentifier.URL_SCHEME_VALUE_SEPARATOR))).setHelpText(span().addChild("Enter the fully qualified Peppol participant ID (including the scheme) you want to delete.\nExample identifier layout: ").addChild(code(aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9999:test").getURIEncoded()))).setErrorList(aFormErrors.getListOfField(FIELD_PARTICIPANT_ID)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addSubmitButton("Delete from index", EDefaultIcon.DELETE);
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) IOException(java.io.IOException) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) RequestField(com.helger.photon.core.form.RequestField)

Example 13 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-directory by phax.

the class PDCommonUI method showBusinessInfoDetails.

@Nonnull
public static BootstrapViewForm showBusinessInfoDetails(@Nonnull final PDStoredBusinessEntity aStoredDoc, @Nonnull final Locale aDisplayLocale) {
    final BootstrapViewForm aViewForm = new BootstrapViewForm();
    if (aStoredDoc.hasCountryCode()) {
        final HCNodeList aCountryCtrl = new HCNodeList();
        final String sCountryCode = aStoredDoc.getCountryCode();
        aCountryCtrl.addChild(getFlagNode(sCountryCode));
        final Locale aCountry = CountryCache.getInstance().getCountry(sCountryCode);
        if (aCountry != null)
            aCountryCtrl.addChild(" " + aCountry.getDisplayCountry(aDisplayLocale) + " [" + sCountryCode + "]");
        else
            aCountryCtrl.addChild(" " + sCountryCode);
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Country").setCtrl(aCountryCtrl));
    }
    if (aStoredDoc.names().isNotEmpty()) {
        final ICommonsList<PDStoredMLName> aNames = getUIFilteredNames(aStoredDoc.names(), aDisplayLocale);
        IHCNode aNameCtrl;
        if (aNames.size() == 1)
            aNameCtrl = getMLNameNode(aNames.getFirst(), aDisplayLocale);
        else {
            final HCUL aNameUL = new HCUL();
            aNames.forEach(x -> aNameUL.addItem(getMLNameNode(x, aDisplayLocale)));
            aNameCtrl = aNameUL;
        }
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Entity Name").setCtrl(aNameCtrl));
    }
    if (aStoredDoc.hasGeoInfo())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Geographical information").setCtrl(HCExtHelper.nl2divList(aStoredDoc.getGeoInfo())));
    if (aStoredDoc.identifiers().isNotEmpty()) {
        final BootstrapTable aIDTable = new BootstrapTable(HCCol.star(), HCCol.star()).setStriped(true).setBordered(true).setCondensed(true);
        aIDTable.addHeaderRow().addCells("Scheme", "Value");
        for (final PDStoredIdentifier aStoredID : aStoredDoc.identifiers()) aIDTable.addBodyRow().addCells(aStoredID.getScheme(), aStoredID.getValue());
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional identifiers").setCtrl(aIDTable));
    }
    if (aStoredDoc.websiteURIs().isNotEmpty()) {
        final HCOL aOL = new HCOL();
        for (final String sWebsiteURI : aStoredDoc.websiteURIs()) aOL.addItem(HCA.createLinkedWebsite(sWebsiteURI, HC_Target.BLANK));
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Website URIs").setCtrl(aOL));
    }
    if (aStoredDoc.contacts().isNotEmpty()) {
        final BootstrapTable aContactTable = new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star()).setStriped(true).setBordered(true);
        aContactTable.addHeaderRow().addCells("Type", "Name", "Phone Number", "Email");
        for (final PDStoredContact aStoredContact : aStoredDoc.contacts()) aContactTable.addBodyRow().addCells(aStoredContact.getType(), aStoredContact.getName(), aStoredContact.getPhone(), aStoredContact.getEmail());
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Contacts").setCtrl(aContactTable));
    }
    if (aStoredDoc.hasAdditionalInformation())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional information").setCtrl(HCExtHelper.nl2divList(aStoredDoc.getAdditionalInformation())));
    if (aStoredDoc.hasRegistrationDate())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Registration date").setCtrl(PDTToString.getAsString(aStoredDoc.getRegistrationDate(), aDisplayLocale)));
    return aViewForm;
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) PDTToString(com.helger.commons.datetime.PDTToString) HCUL(com.helger.html.hc.html.grouping.HCUL) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) HCOL(com.helger.html.hc.html.grouping.HCOL) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) IHCNode(com.helger.html.hc.IHCNode) Nonnull(javax.annotation.Nonnull)

Example 14 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-smp by phax.

the class AbstractPageSecureEndpoint method isValidToDisplayPage.

@Override
@Nonnull
protected IValidityIndicator isValidToDisplayPage(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    if (aServiceGroupMgr.getSMPServiceGroupCount() <= 0) {
        aNodeList.addChild(warn("No service group is present! At least one service group must be present to create an endpoint for it."));
        aNodeList.addChild(new BootstrapButton().addChild("Create new service group").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SERVICE_GROUPS)).setIcon(EDefaultIcon.YES));
        return EValidity.INVALID;
    }
    final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr();
    if (aTransportProfileMgr.getSMPTransportProfileCount() <= 0) {
        aNodeList.addChild(warn("No transport profile is present! At least one transport profile must be present to create an endpoint for it."));
        aNodeList.addChild(new BootstrapButton().addChild("Create new transport profile").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_TRANSPORT_PROFILES)).setIcon(EDefaultIcon.YES));
        aNodeList.addChild(new BootstrapButton().addChild("Check default transport profiles").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_TRANSPORT_PROFILES)).setIcon(EDefaultIcon.YES));
        return EValidity.INVALID;
    }
    return super.isValidToDisplayPage(aWPEC);
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPTransportProfileManager(com.helger.phoss.smp.domain.transportprofile.ISMPTransportProfileManager) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Example 15 with HCNodeList

use of com.helger.html.hc.impl.HCNodeList in project phoss-smp by phax.

the class PageSecureBusinessCard method showBusinessCardEntity.

@Nonnull
public static IHCNode showBusinessCardEntity(@Nonnull final SMPBusinessCardEntity aEntity, final int nIndex, @Nonnull final Locale aDisplayLocale) {
    final BootstrapCard aPanel = new BootstrapCard();
    aPanel.createAndAddHeader().addChild("Business Entity " + nIndex);
    final BootstrapViewForm aForm2 = aPanel.createAndAddBody().addAndReturnChild(new BootstrapViewForm());
    aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Name").setCtrl(aEntity.names().getFirst().getName()));
    {
        final Locale aCountry = CountryCache.getInstance().getCountry(aEntity.getCountryCode());
        final HCNodeList aCtrl = new HCNodeList();
        final EFamFamFlagIcon eIcon = EFamFamFlagIcon.getFromIDOrNull(aCountry.getCountry());
        if (eIcon != null) {
            aCtrl.addChild(eIcon.getAsNode());
            aCtrl.addChild(" ");
        }
        aCtrl.addChild(aCountry.getDisplayCountry(aDisplayLocale) + " [" + aEntity.getCountryCode() + "]");
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Country code").setCtrl(aCtrl));
    }
    if (aEntity.hasGeographicalInformation()) {
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Geographical information").setCtrl(HCExtHelper.nl2divList(aEntity.getGeographicalInformation())));
    }
    if (aEntity.identifiers().isNotEmpty()) {
        final BootstrapTable aTable = new BootstrapTable(HCCol.star(), HCCol.star());
        aTable.addHeaderRow().addCells("Scheme", "Value");
        for (final SMPBusinessCardIdentifier aIdentifier : aEntity.identifiers()) aTable.addBodyRow().addCells(aIdentifier.getScheme(), aIdentifier.getValue());
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Identifiers").setCtrl(aTable));
    }
    if (aEntity.websiteURIs().isNotEmpty()) {
        final HCNodeList aNL = new HCNodeList();
        for (final String sWebsiteURI : aEntity.websiteURIs()) aNL.addChild(new HCDiv().addChild(HCA.createLinkedWebsite(sWebsiteURI)));
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Website URIs").setCtrl(aNL));
    }
    if (aEntity.contacts().isNotEmpty()) {
        final BootstrapTable aTable = new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star());
        aTable.addHeaderRow().addCells("Type", "Name", "Phone number", "Email address");
        for (final SMPBusinessCardContact aContact : aEntity.contacts()) {
            final HCRow aBodyRow = aTable.addBodyRow();
            aBodyRow.addCells(aContact.getType(), aContact.getName(), aContact.getPhoneNumber());
            aBodyRow.addCell(HCA_MailTo.createLinkedEmail(aContact.getEmail()));
        }
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Contacts").setCtrl(aTable));
    }
    if (aEntity.hasAdditionalInformation()) {
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Additional information").setCtrl(HCExtHelper.nl2divList(aEntity.getAdditionalInformation())));
    }
    if (aEntity.hasRegistrationDate()) {
        aForm2.addFormGroup(new BootstrapFormGroup().setLabel("Registration date").setCtrl(PDTToString.getAsString(aEntity.getRegistrationDate(), aDisplayLocale)));
    }
    return aPanel;
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) HCNodeList(com.helger.html.hc.impl.HCNodeList) EFamFamFlagIcon(com.helger.photon.uictrls.famfam.EFamFamFlagIcon) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) HCRow(com.helger.html.hc.html.tabular.HCRow) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

HCNodeList (com.helger.html.hc.impl.HCNodeList)82 Locale (java.util.Locale)50 Nonnull (javax.annotation.Nonnull)31 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)27 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)26 HCA (com.helger.html.hc.html.textlevel.HCA)25 HCRow (com.helger.html.hc.html.tabular.HCRow)21 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)20 ISimpleURL (com.helger.commons.url.ISimpleURL)19 DTCol (com.helger.photon.uictrls.datatables.column.DTCol)19 PDTToString (com.helger.commons.datetime.PDTToString)18 HCTable (com.helger.html.hc.html.tabular.HCTable)18 BootstrapViewForm (com.helger.photon.bootstrap4.form.BootstrapViewForm)18 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)17 BootstrapDTColAction (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction)17 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)16 BootstrapDataTables (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)15 DataTables (com.helger.photon.uictrls.datatables.DataTables)14 RequestField (com.helger.photon.core.form.RequestField)13 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)12