Search in sources :

Example 11 with RequestField

use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.

the class PagePublicToolsParticipantInformation method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    final boolean bShowInput = true;
    String sParticipantIDScheme = DEFAULT_ID_SCHEME;
    String sParticipantIDValue = null;
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        // Validate fields
        sParticipantIDScheme = StringHelper.trim(aWPEC.params().getAsString(FIELD_ID_SCHEME));
        sParticipantIDValue = StringHelper.trim(aWPEC.params().getAsString(FIELD_ID_VALUE));
        final String sSMLID = StringHelper.trim(aWPEC.params().getAsString(FIELD_SML));
        final ISMLConfiguration aSMLConfiguration = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
        final boolean bSMLAutoDetect = ISMLConfigurationManager.ID_AUTO_DETECT.equals(sSMLID);
        final boolean bQueryBusinessCard = aWPEC.params().isCheckBoxChecked(PARAM_QUERY_BUSINESS_CARD, DEFAULT_QUERY_BUSINESS_CARD);
        final boolean bShowTime = aWPEC.params().isCheckBoxChecked(PARAM_SHOW_TIME, DEFAULT_SHOW_TIME);
        final boolean bXSDValidation = aWPEC.params().isCheckBoxChecked(PARAM_XSD_VALIDATION, DEFAULT_XSD_VALIDATION);
        final boolean bVerifySignatures = aWPEC.params().isCheckBoxChecked(PARAM_VERIFY_SIGNATURES, DEFAULT_VERIFY_SIGNATURES);
        final IIdentifierFactory aIF = aSMLConfiguration != null ? aSMLConfiguration.getSMPIdentifierType().getIdentifierFactory() : SimpleIdentifierFactory.INSTANCE;
        // Legacy URL params?
        if (aWPEC.params().containsKey("idscheme") && aWPEC.params().containsKey("idvalue")) {
            sParticipantIDScheme = DEFAULT_ID_SCHEME;
            sParticipantIDValue = StringHelper.trim(aWPEC.params().getAsString("idscheme")) + ":" + StringHelper.trim(aWPEC.params().getAsString("idvalue"));
        }
        if (StringHelper.hasNoText(sParticipantIDScheme))
            aFormErrors.addFieldError(FIELD_ID_SCHEME, "Please provide an identifier scheme");
        else if (!aIF.isParticipantIdentifierSchemeValid(sParticipantIDScheme))
            aFormErrors.addFieldError(FIELD_ID_SCHEME, "The participant identifier scheme '" + sParticipantIDScheme + "' is not valid!");
        if (StringHelper.hasNoText(sParticipantIDValue))
            aFormErrors.addFieldError(FIELD_ID_VALUE, "Please provide an identifier value");
        else if (!aIF.isParticipantIdentifierValueValid(sParticipantIDValue))
            aFormErrors.addFieldError(FIELD_ID_VALUE, "The participant identifier value '" + sParticipantIDValue + "' is not valid!");
        if (aSMLConfiguration == null && !bSMLAutoDetect)
            aFormErrors.addFieldError(FIELD_SML, "A valid SML must be selected!");
        if (aFormErrors.isEmpty()) {
            _queryParticipant(aWPEC, sParticipantIDScheme, sParticipantIDValue, aSMLConfiguration, bSMLAutoDetect, bQueryBusinessCard, bShowTime, bXSDValidation, bVerifySignatures);
        }
    }
    if (bShowInput) {
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC).setMethod(EHCFormMethod.GET).setLeft(3));
        aForm.addChild(info().addChildren(div("Show all processes, document types and endpoints of a participant."), div("You may want to try scheme ").addChild(code(DEFAULT_ID_SCHEME)).addChild(" and value ").addChild(code("9915:test")).addChild(" on ").addChild(code("SMK")).addChild(" as an example.")));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier scheme").setCtrl(new HCEdit(new RequestField(FIELD_ID_SCHEME, sParticipantIDScheme)).setPlaceholder("Identifier scheme")).setHelpText(div("The most common identifier scheme is ").addChild(code(DEFAULT_ID_SCHEME))).setErrorList(aFormErrors.getListOfField(FIELD_ID_SCHEME)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Identifier value").setCtrl(new HCEdit(new RequestField(FIELD_ID_VALUE, sParticipantIDValue)).setPlaceholder("Identifier value")).setHelpText(div("The identifier value must look like ").addChild(code("9915:test"))).setErrorList(aFormErrors.getListOfField(FIELD_ID_VALUE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML to use").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML, ISMLConfigurationManager.ID_AUTO_DETECT), true)).setErrorList(aFormErrors.getListOfField(FIELD_SML)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Query Business Card?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_QUERY_BUSINESS_CARD, DEFAULT_QUERY_BUSINESS_CARD))).setErrorList(aFormErrors.getListOfField(PARAM_QUERY_BUSINESS_CARD)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Show query duration?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_SHOW_TIME, DEFAULT_SHOW_TIME))).setErrorList(aFormErrors.getListOfField(PARAM_SHOW_TIME)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Enable XML Schema validation of responses?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_XSD_VALIDATION, DEFAULT_XSD_VALIDATION))).setErrorList(aFormErrors.getListOfField(PARAM_XSD_VALIDATION)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Verify signatures of SMP responses?").setCtrl(new HCCheckBox(new RequestFieldBoolean(PARAM_VERIFY_SIGNATURES, DEFAULT_VERIFY_SIGNATURES))).setErrorList(aFormErrors.getListOfField(PARAM_VERIFY_SIGNATURES)));
        final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
        aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
        aToolbar.addSubmitButton("Show details");
    }
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ISMLConfiguration(com.helger.peppol.domain.ISMLConfiguration) SMLConfigurationSelect(com.helger.peppol.ui.select.SMLConfigurationSelect) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) ISMLConfigurationManager(com.helger.peppol.app.mgr.ISMLConfigurationManager) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) RequestField(com.helger.photon.core.form.RequestField)

Example 12 with RequestField

use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.

the class PagePublicToolsSMPSML method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final FormErrorList aFormErrors = new FormErrorList();
    final boolean bShowInput = true;
    aNodeList.addChild(warn("Note: as of ").addChild(new HCA(new SimpleURL("https://github.com/phax/phoss-smp")).addChild("phoss SMP server 5.0.0 beta 1")).addChild(" this registration feature is contained directly in the SMP software! So you don't need to send your certificates over the Internet anymore!"));
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        if (aWPEC.hasSubAction(SUBACTION_SMP_REGISTER))
            _registerSMPtoSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_UPDATE))
            _updateSMPatSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_DELETE))
            _deleteSMPfromSML(aWPEC, aFormErrors);
        else if (aWPEC.hasSubAction(SUBACTION_SMP_UPDATE_CERT))
            _updateSMPCertAtSML(aWPEC, aFormErrors);
    }
    if (bShowInput) {
        final int nLeft = 3;
        final BootstrapTabBox aTabBox = new BootstrapTabBox();
        // Register SMP at SML
        {
            final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
            aForm.setEncTypeFileUpload().setLeft(nLeft);
            aForm.addChild(info("Register a new SMP to the SML. This must only be done once per SMP!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(HELPTEXT_PHYSICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(HELPTEXT_LOGICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_REGISTER);
            aToolbar.addSubmitButton("Register SMP at SML");
            aTabBox.addTab("register", "Register SMP to SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_REGISTER));
        }
        // Update SMP at SML
        {
            final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
            aForm.setEncTypeFileUpload().setLeft(nLeft);
            aForm.addChild(info("Update an existing SMP at the SML. This must only be done when either the IP address or the host name of the SMP changed!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(HELPTEXT_PHYSICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(HELPTEXT_LOGICAL_ADDRESS).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_UPDATE);
            aToolbar.addSubmitButton("Update SMP at SML");
            aTabBox.addTab("update", "Update SMP at SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_UPDATE));
        }
        // Delete SMP from SML
        {
            final BootstrapForm aForm = getUIHandler().createFormFileUploadSelf(aWPEC);
            aForm.setLeft(nLeft);
            aForm.addChild(info("Delete an existing SMP from the SML."));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP ID").setCtrl(new HCEdit(new RequestField(FIELD_SMP_ID)).setPlaceholder("Your SMP ID")).setHelpText(HELPTEXT_SMP_ID).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_DELETE);
            aToolbar.addSubmitButton("Delete SMP from SML");
            aTabBox.addTab("delete", "Delete SMP from SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_DELETE));
        }
        // Update SMP certificate in SML
        {
            final BootstrapForm aForm = getUIHandler().createFormFileUploadSelf(aWPEC);
            aForm.setLeft(nLeft);
            aForm.addChild(info().addChildren(div("Prepare the update of your Peppol SMP certificate in the future."), div("This works only if your SMP certificate is NOT expired yet." + " If your SMP certificate is already expired contact CEF-EDELIVERY-SUPPORT@ec.europa.eu with your SMP ID, the new certificate and the requested exchange date!"), div("Note: this is a custom extension that only works with the CEF SML instances!")));
            aForm.addChild(warn("It is your responsibility to update the Peppol certificate in your SMP at the specified time!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new SMLConfigurationSelect(new RequestField(FIELD_SML_ID), false)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Existing/old SMP key store").setCtrl(new BootstrapFileUpload(FIELD_KEYSTORE, aDisplayLocale)).setHelpText(HELPTEXT_KEYSTORE).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("Existing/old SMP key store password").setCtrl(new HCEditPassword(FIELD_KEYSTORE_PW).setPlaceholder("The password for the existing SMP keystore. May be empty.")).setHelpText(HELPTEXT_KEYSTORE_PW).setErrorList(aFormErrors.getListOfField(FIELD_KEYSTORE_PW)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("Certificate migration date").setCtrl(BootstrapDateTimePicker.create(FIELD_PM_MIGRATION_DATE, aDisplayLocale, EBootstrap4DateTimePickerMode.DATE).setMinDate(PDTFactory.getCurrentLocalDate().plusDays(1))).setHelpText("The SML will replace the certificate at this date." + " It must be in the future and within the validity period of the provided new public certificate." + " If not provided, the 'valid from' part of the certificate is used.").setErrorList(aFormErrors.getListOfField(FIELD_PM_MIGRATION_DATE)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New public certificate").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_PM_PUBLIC_CERT)).setRows(5)).setHelpText(span("Paste the public part of your new certificate here (using PEM encoding)." + " Do NOT paste your new private key here." + " Must start with ").addChild(code(CertificateHelper.BEGIN_CERTIFICATE)).addChild(" and end with ").addChild(code(CertificateHelper.END_CERTIFICATE))).setErrorList(aFormErrors.getListOfField(FIELD_PM_PUBLIC_CERT)));
            final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
            aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
            aToolbar.addHiddenField(CPageParam.PARAM_SUBACTION, SUBACTION_SMP_UPDATE_CERT);
            aToolbar.addSubmitButton("Prepare certificate update");
            aTabBox.addTab("updatecert", "Update SMP certificate at SML", aForm, aWPEC.hasSubAction(SUBACTION_SMP_UPDATE_CERT));
        }
        aNodeList.addChild(aTabBox);
    }
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) HCA(com.helger.html.hc.html.textlevel.HCA) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCEditPassword(com.helger.html.hc.html.forms.HCEditPassword) SMLConfigurationSelect(com.helger.peppol.ui.select.SMLConfigurationSelect) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) SimpleURL(com.helger.commons.url.SimpleURL) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 13 with RequestField

use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.

the class PageSecureCRMGroup method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ICRMGroup aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    aForm.addChild(getUIHandler().createActionHeader(eFormAction.isEdit() ? "Edit CRM group" : "Create new CRM group"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_NAME, aSelectedObject == null ? null : aSelectedObject.getDisplayName()))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Sender email address").setCtrl(new HCEdit(new RequestField(FIELD_SENDER_EMAIL_ADDRESS, aSelectedObject == null ? null : aSelectedObject.getSenderEmailAddress()))).setErrorList(aFormErrors.getListOfField(FIELD_SENDER_EMAIL_ADDRESS)));
}
Also used : HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 14 with RequestField

use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.

the class PagePublicNewsletterSubscribe method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    ICommonsList<String> aSelectedCRMGroupIDs = null;
    if (aWPEC.hasAction(CPageParam.ACTION_SAVE)) {
        final String sSalutationID = aWPEC.params().getAsString(FIELD_SALUTATION);
        final ESalutation eSalutation = ESalutation.getFromIDOrNull(sSalutationID);
        final String sName = aWPEC.params().getAsString(FIELD_NAME);
        final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
        aSelectedCRMGroupIDs = aWPEC.params().getAsStringList(FIELD_GROUP);
        final ICommonsSet<ICRMGroup> aSelectedCRMGroups = new CommonsHashSet<>();
        ICRMSubscriber aSameEmailAddressSubscriber = null;
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "You must provide your name!");
        if (StringHelper.hasNoText(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "You must provide your email address!");
        else if (!EmailAddressHelper.isValid(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
        else {
            // Check if the email address is already in use
            aSameEmailAddressSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
        }
        if (aSelectedCRMGroupIDs != null)
            for (final String sCRMGroupID : aSelectedCRMGroupIDs) {
                final ICRMGroup aGroup = aCRMGroupMgr.getCRMGroupOfID(sCRMGroupID);
                if (aGroup == null)
                    aFormErrors.addFieldError(FIELD_GROUP, "The selected mailing list is not existing!");
                else
                    aSelectedCRMGroups.add(aGroup);
            }
        if (aSelectedCRMGroups.isEmpty())
            aFormErrors.addFieldError(FIELD_GROUP, "At least one mailing list must be selected!");
        else {
            if (aSameEmailAddressSubscriber != null) {
                // Merge with existing subscriber
                aSelectedCRMGroups.addAll(aSameEmailAddressSubscriber.getAllAssignedGroups());
            }
        }
        if (aFormErrors.isEmpty()) {
            // Save
            if (aSameEmailAddressSubscriber == null) {
                // Create a new one
                aCRMSubscriberMgr.createCRMSubscriber(eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            } else {
                // Update an existing one
                aCRMSubscriberMgr.updateCRMSubscriber(aSameEmailAddressSubscriber.getID(), eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            }
            aNodeList.addChild(success("Successfully subscribed '" + sEmailAddress + "' to mailing lists"));
        } else {
            aNodeList.addChild(getUIHandler().createIncorrectInputBox(aWPEC));
        }
    }
    final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
    aForm.setLeft(3);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Your salutation").setCtrl(new HCSalutationSelect(new RequestField(FIELD_SALUTATION), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SALUTATION)));
    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_ADDRESS))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    {
        final ICommonsList<? extends ICRMGroup> aAllCRMGroups = aCRMGroupMgr.getAll();
        if (aAllCRMGroups.size() == 1) {
            // No need for selection - use hidden field
            aForm.addChild(new HCHiddenField(FIELD_GROUP, aAllCRMGroups.getFirst().getID()));
        } else if (aAllCRMGroups.isNotEmpty()) {
            // Show selection
            final HCNodeList aGroups = new HCNodeList();
            for (final ICRMGroup aCRMGroup : aAllCRMGroups.getSorted(IHasDisplayName.getComparatorCollating(aDisplayLocale))) {
                final String sCRMGroupID = aCRMGroup.getID();
                final RequestFieldBooleanMultiValue aRFB = new RequestFieldBooleanMultiValue(FIELD_GROUP, sCRMGroupID, false);
                aGroups.addChild(new HCDiv().addChild(new HCCheckBox(aRFB)).addChild(" " + aCRMGroup.getDisplayName()));
            }
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Mailing lists to subscribe to").setCtrl(aGroups).setErrorList(aFormErrors.getListOfField(FIELD_GROUP)));
        }
    }
    // Toolbar
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_SAVE);
    aToolbar.addSubmitButton("Subscribe", EDefaultIcon.YES);
    aNodeList.addChild(aForm);
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) RequestFieldBooleanMultiValue(com.helger.photon.core.form.RequestFieldBooleanMultiValue) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) ESalutation(com.helger.masterdata.person.ESalutation) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICRMGroup(com.helger.peppol.crm.ICRMGroup) HCSalutationSelect(com.helger.photon.uicore.html.select.HCSalutationSelect) RequestField(com.helger.photon.core.form.RequestField)

Example 15 with RequestField

use of com.helger.photon.core.form.RequestField in project peppol-practical by phax.

the class PagePublicNewsletterUnsubscribe method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_SAVE)) {
        final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
        ICRMSubscriber aCRMSubscriber = null;
        if (StringHelper.hasNoText(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "You must provide your email address!");
        else if (!EmailAddressHelper.isValid(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
        else {
            aCRMSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
            if (aCRMSubscriber == null)
                aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is not registered to any mailing list!");
        }
        if (aFormErrors.isEmpty()) {
            // Update an existing one
            aCRMSubscriberMgr.updateCRMSubscriberGroupAssignments(aCRMSubscriber.getID(), null);
            aNodeList.addChild(success("Successfully unsubscribed '" + sEmailAddress + "' from all mailing lists"));
        } else {
            aNodeList.addChild(getUIHandler().createIncorrectInputBox(aWPEC));
        }
    }
    final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
    aForm.setLeft(3);
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL_ADDRESS))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    // Toolbar
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_SAVE);
    aToolbar.addSubmitButton("Unsubscribe", EDefaultIcon.YES);
    aNodeList.addChild(aForm);
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

RequestField (com.helger.photon.core.form.RequestField)40 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)37 HCEdit (com.helger.html.hc.html.forms.HCEdit)34 Locale (java.util.Locale)29 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)24 HCNodeList (com.helger.html.hc.impl.HCNodeList)23 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)20 FormErrorList (com.helger.photon.core.form.FormErrorList)18 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)12 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)12 PDTToString (com.helger.commons.datetime.PDTToString)11 RequestFieldBoolean (com.helger.photon.core.form.RequestFieldBoolean)10 HCTextArea (com.helger.html.hc.html.forms.HCTextArea)9 Nonnull (javax.annotation.Nonnull)9 HCA (com.helger.html.hc.html.textlevel.HCA)8 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)8 HCRow (com.helger.html.hc.html.tabular.HCRow)7 HCTextNode (com.helger.html.hc.impl.HCTextNode)7 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)7 ICommonsList (com.helger.commons.collection.impl.ICommonsList)6