Search in sources :

Example 21 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-directory by phax.

the class AppCommonUI method createViewLoginForm.

@Nonnull
public static BootstrapForm createViewLoginForm(@Nonnull final LayoutExecutionContext aLEC, @Nullable final String sPreselectedUserName) {
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    // Use new IDs for both fields, in case the login stuff is displayed more
    // than once!
    final String sIDUserName = GlobalIDFactory.getNewStringID();
    final String sIDPassword = GlobalIDFactory.getNewStringID();
    final String sIDErrorField = GlobalIDFactory.getNewStringID();
    final BootstrapForm aForm = new BootstrapForm(aLEC).setAction(aLEC.getSelfHref()).setFormType(EBootstrapFormType.DEFAULT);
    aForm.setLeft(3);
    // User name field
    aForm.addFormGroup(new BootstrapFormGroup().setLabel(EPhotonCoreText.EMAIL_ADDRESS.getDisplayText(aDisplayLocale)).setCtrl(new HCEdit(new RequestField(CLogin.REQUEST_ATTR_USERID, sPreselectedUserName)).setID(sIDUserName)));
    // Password field
    aForm.addFormGroup(new BootstrapFormGroup().setLabel(EPhotonCoreText.LOGIN_FIELD_PASSWORD.getDisplayText(aDisplayLocale)).setCtrl(new HCEditPassword(CLogin.REQUEST_ATTR_PASSWORD).setID(sIDPassword)));
    // Placeholder for error message
    aForm.addChild(new HCDiv().setID(sIDErrorField).addStyle(CCSSProperties.MARGIN.newValue("4px 0")));
    // Login button
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aLEC));
    final JSPackage aOnClick = new JSPackage();
    {
        final JSAnonymousFunction aJSSuccess = new JSAnonymousFunction();
        final JSVar aJSData = aJSSuccess.param("data");
        aJSSuccess.body()._if(aJSData.ref(AjaxExecutorPublicLogin.JSON_LOGGEDIN), JSHtml.windowLocationReload(), JQuery.idRef(sIDErrorField).empty().append(aJSData.ref(AjaxExecutorPublicLogin.JSON_HTML)));
        aOnClick.add(new JQueryAjaxBuilder().url(CAjax.LOGIN.getInvocationURI(aRequestScope)).method(EHttpMethod.POST).data(new JSAssocArray().add(CLogin.REQUEST_ATTR_USERID, JQuery.idRef(sIDUserName).val()).add(CLogin.REQUEST_ATTR_PASSWORD, JQuery.idRef(sIDPassword).val())).success(aJSSuccess).build());
    }
    aOnClick._return(false);
    aToolbar.addSubmitButton(EPhotonCoreText.LOGIN_BUTTON_SUBMIT.getDisplayText(aDisplayLocale), aOnClick);
    return aForm;
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) JSVar(com.helger.html.jscode.JSVar) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCEditPassword(com.helger.html.hc.html.forms.HCEditPassword) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) JSPackage(com.helger.html.jscode.JSPackage) JSAssocArray(com.helger.html.jscode.JSAssocArray) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField) Nonnull(javax.annotation.Nonnull)

Example 22 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class PageSecureBusinessCard method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPBusinessCard aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final boolean bEdit = eFormAction.isEdit();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit Business Card" : "Create new Business Card"));
    if (bEdit) {
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(aSelectedObject.getID()).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
    } else {
        // Show only service groups that don't have a BC already
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Service Group").setCtrl(new HCServiceGroupSelect(new RequestField(FIELD_SERVICE_GROUP_ID, aSelectedObject != null ? aSelectedObject.getID() : null), aDisplayLocale, x -> aBusinessCardMgr.getSMPBusinessCardOfServiceGroup(x) == null)).setErrorList(aFormErrors.getListOfField(FIELD_SERVICE_GROUP_ID)));
    }
    final HCDiv aEntityContainer = aForm.addAndReturnChild(new HCDiv().setID("entitycontainer"));
    final IRequestParamMap aEntities = aWPEC.getRequestParamMap().getMap(PREFIX_ENTITY);
    if (bFormSubmitted) {
        // Re-show of form
        if (aEntities != null)
            for (final String sEntityRowID : aEntities.keySet()) aEntityContainer.addChild(_createEntityInputForm(aWPEC, null, sEntityRowID, aFormErrors, bFormSubmitted));
    } else {
        if (aSelectedObject != null) {
            // add all existing stored entities
            for (final SMPBusinessCardEntity aEntity : aSelectedObject.getAllEntities()) aEntityContainer.addChild(_createEntityInputForm(aWPEC, aEntity, (String) null, aFormErrors, bFormSubmitted));
        }
    }
    {
        final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
        final JSVar aJSAppendData = aJSAppend.param("data");
        aJSAppend.body().add(JQuery.idRef(aEntityContainer).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
        final JSPackage aOnAdd = new JSPackage();
        aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_ENTITY.getInvocationURL(aRequestScope)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
        aForm.addChild(new BootstrapButton().addChild("Add Entity").setIcon(EDefaultIcon.PLUS).setOnClick(aOnAdd));
    }
}
Also used : Locale(java.util.Locale) GlobalIDFactory(com.helger.commons.id.factory.GlobalIDFactory) ILayoutExecutionContext(com.helger.photon.core.execcontext.ILayoutExecutionContext) PDClientProvider(com.helger.phoss.smp.app.PDClientProvider) EWithDeprecated(com.helger.photon.uicore.html.select.HCCountrySelect.EWithDeprecated) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) FormErrorList(com.helger.photon.core.form.FormErrorList) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) Nonempty(com.helger.commons.annotation.Nonempty) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) HCA(com.helger.html.hc.html.textlevel.HCA) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) CPageParam(com.helger.photon.uicore.css.CPageParam) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) IHCCell(com.helger.html.hc.html.tabular.IHCCell) HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCTextNode(com.helger.html.hc.impl.HCTextNode) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCExtHelper(com.helger.html.hc.ext.HCExtHelper) RegExHelper(com.helger.commons.regex.RegExHelper) IValidityIndicator(com.helger.commons.state.IValidityIndicator) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) RequestParamMap(com.helger.servlet.request.RequestParamMap) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) JSJQueryHelper(com.helger.photon.uicore.js.JSJQueryHelper) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) DataTables(com.helger.photon.uictrls.datatables.DataTables) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) LinkHelper(com.helger.photon.app.url.LinkHelper) JSAssocArray(com.helger.html.jscode.JSAssocArray) BootstrapDateTimePicker(com.helger.photon.bootstrap4.uictrls.datetimepicker.BootstrapDateTimePicker) PDTFromString(com.helger.commons.datetime.PDTFromString) HCEdit(com.helger.html.hc.html.forms.HCEdit) IHCNode(com.helger.html.hc.IHCNode) JQuery(com.helger.html.jquery.JQuery) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) Nullable(javax.annotation.Nullable) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) StringHelper(com.helger.commons.string.StringHelper) WorkInProgress(com.helger.commons.annotation.WorkInProgress) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) BootstrapFormHelper(com.helger.photon.bootstrap4.form.BootstrapFormHelper) CAjax(com.helger.phoss.smp.ui.ajax.CAjax) HCA_MailTo(com.helger.html.hc.ext.HCA_MailTo) HCCol(com.helger.html.hc.html.tabular.HCCol) RequestField(com.helger.photon.core.form.RequestField) AbstractBootstrapWebPageActionHandler(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandler) ESortOrder(com.helger.commons.compare.ESortOrder) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) JSVar(com.helger.html.jscode.JSVar) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) BootstrapSuccessBox(com.helger.photon.bootstrap4.alert.BootstrapSuccessBox) AbstractBootstrapWebPageActionHandlerDelete(com.helger.photon.bootstrap4.pages.handler.AbstractBootstrapWebPageActionHandlerDelete) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) Locale(java.util.Locale) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) EmailAddressValidator(com.helger.smtp.util.EmailAddressValidator) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) BootstrapErrorBox(com.helger.photon.bootstrap4.alert.BootstrapErrorBox) HCCountrySelect(com.helger.photon.uicore.html.select.HCCountrySelect) EWebPageFormAction(com.helger.photon.uicore.page.EWebPageFormAction) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) IAjaxFunctionDeclaration(com.helger.photon.ajax.decl.IAjaxFunctionDeclaration) PDClient(com.helger.pd.client.PDClient) CountryCache(com.helger.commons.locale.country.CountryCache) EFamFamIcon(com.helger.photon.uictrls.famfam.EFamFamIcon) LocalDate(java.time.LocalDate) SMPWebAppConfiguration(com.helger.phoss.smp.app.SMPWebAppConfiguration) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ESuccess(com.helger.commons.state.ESuccess) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) HCRow(com.helger.html.hc.html.tabular.HCRow) EValidity(com.helger.commons.state.EValidity) PhotonUnifiedResponse(com.helger.photon.app.PhotonUnifiedResponse) AbstractSMPWebPageForm(com.helger.phoss.smp.ui.AbstractSMPWebPageForm) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) CompareHelper(com.helger.commons.compare.CompareHelper) URLValidator(com.helger.commons.url.URLValidator) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) ISimpleURL(com.helger.commons.url.ISimpleURL) HCNodeList(com.helger.html.hc.impl.HCNodeList) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) CBootstrapCSS(com.helger.photon.bootstrap4.CBootstrapCSS) HCTable(com.helger.html.hc.html.tabular.HCTable) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) SMPBusinessCardName(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardName) EBootstrapButtonSize(com.helger.photon.bootstrap4.button.EBootstrapButtonSize) EShowList(com.helger.photon.uicore.page.EShowList) EFamFamFlagIcon(com.helger.photon.uictrls.famfam.EFamFamFlagIcon) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) JSPackage(com.helger.html.jscode.JSPackage) HCDiv(com.helger.html.hc.html.grouping.HCDiv) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) JSVar(com.helger.html.jscode.JSVar) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCServiceGroupSelect(com.helger.phoss.smp.ui.secure.hc.HCServiceGroupSelect) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) JSPackage(com.helger.html.jscode.JSPackage) JSAssocArray(com.helger.html.jscode.JSAssocArray) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) IRequestParamMap(com.helger.servlet.request.IRequestParamMap) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 23 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class PageSecureSMLConfiguration method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLInfo aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final boolean bEdit = eFormAction.isEdit();
    aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit SML configuration '" + aSelectedObject.getDisplayName() + "'" : "Create new SML configuration"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_DISPLAY_NAME, aSelectedObject != null ? aSelectedObject.getDisplayName() : null))).setHelpText("The name of the SML configuration. This is for informational purposes only and has no effect on the functionality.").setErrorList(aFormErrors.getListOfField(FIELD_DISPLAY_NAME)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("DNS Zone").setCtrl(new HCEdit(new RequestField(FIELD_DNS_ZONE, aSelectedObject != null ? aSelectedObject.getDNSZone() : null))).setHelpText(new HCTextNode("The name of the DNS Zone that this SML is working upon (e.g. "), code("acc.edelivery.tech.ec.europa.eu"), new HCTextNode("). The value will automatically converted to all-lowercase!")).setErrorList(aFormErrors.getListOfField(FIELD_DNS_ZONE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Management Service URL").setCtrl(new HCEdit(new RequestField(FIELD_MANAGEMENT_ADDRESS_URL, aSelectedObject != null ? aSelectedObject.getManagementServiceURL() : null))).setHelpText("The service URL where the SML management application is running on including the host name. It may not contain the '" + CSMLDefault.MANAGEMENT_SERVICE_METADATA + "' or '" + CSMLDefault.MANAGEMENT_SERVICE_PARTICIPANTIDENTIFIER + "' path elements!").setErrorList(aFormErrors.getListOfField(FIELD_MANAGEMENT_ADDRESS_URL)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Client Certificate required?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_CLIENT_CERTIFICATE_REQUIRED, aSelectedObject != null ? aSelectedObject.isClientCertificateRequired() : DEFAULT_CLIENT_CERTIFICATE_REQUIRED))).setHelpText("Check this if this SML requires a client certificate for access. Both Peppol production SML and SMK require a client certificate. Only a locally running SML software may not require a client certificate.").setErrorList(aFormErrors.getListOfField(FIELD_CLIENT_CERTIFICATE_REQUIRED)));
}
Also used : RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) HCEdit(com.helger.html.hc.html.forms.HCEdit) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) HCTextNode(com.helger.html.hc.impl.HCTextNode) RequestField(com.helger.photon.core.form.RequestField)

Example 24 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class PageSecureSMLRegistration method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    if (!_canShowPage(aWPEC))
        return;
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final FormErrorList aFormErrors = new FormErrorList();
    final boolean bShowInput = true;
    final ISMLInfo aDefaultSML = SMPMetaManager.getSettings().getSMLInfo();
    final String sSMPID = SMPServerConfiguration.getSMLSMPID();
    if (aDefaultSML != null) {
        // Check if this SMP is already registered
        final String sPublisherDNSName = sSMPID + "." + aDefaultSML.getPublisherDNSZone();
        try {
            final InetAddress aIA = InetAddress.getByName(sPublisherDNSName);
            aNodeList.addChild(success(div("An SMP is already registered at the configured SML using the DNS name '" + sPublisherDNSName + "'. The determined IP address is " + aIA.getHostAddress())).addChild(div("Note: this can be a different machine than this one, if another SMP uses the same ID as this one (" + sSMPID + ")")));
        } catch (final UnknownHostException ex) {
        // continue
        }
    }
    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);
    }
    if (bShowInput) {
        // Get default from configuration
        final String sPhysicalAddress = SMPServerConfiguration.getSMLSMPIP();
        final String sLogicalAddress = SMPServerConfiguration.getSMLSMPHostname();
        String sDefaultPhysicalAddress = "";
        String sDefaultLogicalAddress = "";
        try {
            final InetAddress aLocalHost = InetAddress.getLocalHost();
            sDefaultPhysicalAddress = aLocalHost.getHostAddress();
            sDefaultLogicalAddress = "http://" + aLocalHost.getCanonicalHostName();
        } catch (final UnknownHostException ex) {
            LOGGER.error("Error determining localhost address", ex);
        }
        final BootstrapTabBox aTabBox = new BootstrapTabBox();
        final Predicate<ISMLInfo> aSMLFilter = ISMLInfo::isClientCertificateRequired;
        // Register SMP at SML
        {
            final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC).setLeft(3);
            aForm.addChild(info("Register this SMP to the SML. This must only be done once per SMP!"));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new HCSMLSelect(new RequestField(FIELD_SML_ID, aDefaultSML != null ? aDefaultSML.getID() : null), aDisplayLocale, aSMLFilter)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP ID").setCtrl(em(sSMPID)).setHelpText(HELPTEXT_SMP_ID));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS, sPhysicalAddress)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(TextHelper.getFormattedText(HELPTEXT_PHYSICAL_ADDRESS, sDefaultPhysicalAddress)).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS, sLogicalAddress)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(TextHelper.getFormattedText(HELPTEXT_LOGICAL_ADDRESS, sDefaultLogicalAddress)).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            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).setLeft(3);
            aForm.addChild(info("Update this 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 HCSMLSelect(new RequestField(FIELD_SML_ID, aDefaultSML == null ? null : aDefaultSML.getID()), aDisplayLocale, aSMLFilter)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP ID").setCtrl(em(sSMPID)).setHelpText(HELPTEXT_SMP_ID));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Physical address").setCtrl(new HCEdit(new RequestField(FIELD_PHYSICAL_ADDRESS, sPhysicalAddress)).setPlaceholder("The IPv4 address of your SMP. E.g. 1.2.3.4")).setHelpText(TextHelper.getFormattedText(HELPTEXT_PHYSICAL_ADDRESS, sDefaultPhysicalAddress)).setErrorList(aFormErrors.getListOfField(FIELD_PHYSICAL_ADDRESS)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Logical address").setCtrl(new HCEdit(new RequestField(FIELD_LOGICAL_ADDRESS, sLogicalAddress)).setPlaceholder("The domain name of your SMP server. E.g. http://smp.example.org")).setHelpText(TextHelper.getFormattedText(HELPTEXT_LOGICAL_ADDRESS, sDefaultLogicalAddress)).setErrorList(aFormErrors.getListOfField(FIELD_LOGICAL_ADDRESS)));
            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().createFormSelf(aWPEC).setLeft(3);
            aForm.addChild(info("Delete this SMP from the SML."));
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SML").setCtrl(new HCSMLSelect(new RequestField(FIELD_SML_ID, aDefaultSML == null ? null : aDefaultSML.getID()), aDisplayLocale, aSMLFilter)).setErrorList(aFormErrors.getListOfField(FIELD_SML_ID)));
            aForm.addFormGroup(new BootstrapFormGroup().setLabel("SMP ID").setCtrl(em(sSMPID)).setHelpText(HELPTEXT_SMP_ID));
            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));
        }
        aNodeList.addChild(aTabBox);
    }
}
Also used : Locale(java.util.Locale) HCSMLSelect(com.helger.phoss.smp.ui.secure.hc.HCSMLSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) UnknownHostException(java.net.UnknownHostException) ISMLInfo(com.helger.peppol.sml.ISMLInfo) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) InetAddress(java.net.InetAddress) RequestField(com.helger.photon.core.form.RequestField)

Example 25 with BootstrapForm

use of com.helger.photon.bootstrap4.form.BootstrapForm in project phoss-smp by phax.

the class PageSecureEndpointChangeCertificate method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    boolean bShowList = true;
    final ICommonsMap<String, ICommonsList<ISMPEndpoint>> aEndpointsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsMap<String, ICommonsSet<ISMPServiceGroup>> aServiceGroupsGroupedPerURL = new CommonsHashMap<>();
    final ICommonsList<ISMPServiceInformation> aAllSIs = aServiceInfoMgr.getAllSMPServiceInformation();
    int nTotalEndpointCount = 0;
    for (final ISMPServiceInformation aSI : aAllSIs) {
        final ISMPServiceGroup aSG = aSI.getServiceGroup();
        for (final ISMPProcess aProcess : aSI.getAllProcesses()) for (final ISMPEndpoint aEndpoint : aProcess.getAllEndpoints()) {
            final String sUnifiedCertificate = _getUnifiedCert(aEndpoint.getCertificate());
            aEndpointsGroupedPerURL.computeIfAbsent(sUnifiedCertificate, k -> new CommonsArrayList<>()).add(aEndpoint);
            aServiceGroupsGroupedPerURL.computeIfAbsent(sUnifiedCertificate, k -> new CommonsHashSet<>()).add(aSG);
            ++nTotalEndpointCount;
        }
    }
    {
        final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aNodeList.addChild(aToolbar);
        final int nCount = BulkChangeCertificate.getRunningJobCount();
        if (nCount > 0) {
            aNodeList.addChild(warn((nCount == 1 ? "1 bulk change is" : nCount + " bulk changes are") + " currently running in the background"));
        }
    }
    if (aWPEC.hasAction(CPageParam.ACTION_EDIT)) {
        bShowList = false;
        final FormErrorList aFormErrors = new FormErrorList();
        final String sOldUnifiedCert = _getUnifiedCert(aWPEC.params().getAsString(FIELD_OLD_CERTIFICATE));
        if (aWPEC.hasSubAction(CPageParam.ACTION_SAVE)) {
            final String sNewCert = aWPEC.params().getAsString(FIELD_NEW_CERTIFICATE);
            final String sNewUnifiedCert = _getUnifiedCert(sNewCert);
            if (StringHelper.hasNoText(sOldUnifiedCert))
                aFormErrors.addFieldInfo(FIELD_OLD_CERTIFICATE, "An old certificate must be provided");
            else {
                final String sErrorDetails = _getCertificateParsingError(sOldUnifiedCert);
                if (sErrorDetails != null)
                    aFormErrors.addFieldInfo(FIELD_OLD_CERTIFICATE, "The old certificate is invalid: " + sErrorDetails);
            }
            if (StringHelper.hasNoText(sNewUnifiedCert))
                aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "A new certificate must be provided");
            else {
                final String sErrorDetails = _getCertificateParsingError(sNewUnifiedCert);
                if (sErrorDetails != null)
                    aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "The new certificate is invalid: " + sErrorDetails);
                else if (sNewUnifiedCert.equals(sOldUnifiedCert))
                    aFormErrors.addFieldError(FIELD_NEW_CERTIFICATE, "The new certificate is identical to the old certificate");
            }
            // Validate parameters
            if (aFormErrors.containsNoError()) {
                PhotonWorkerPool.getInstance().run("BulkChangeCertificate", new BulkChangeCertificate(aAllSIs, aDisplayLocale, sOldUnifiedCert, sNewCert));
                aWPEC.postRedirectGetInternal(success().addChildren(div("The bulk change of the endpoint certificate to"), _getCertificateDisplay(sNewUnifiedCert, aDisplayLocale), div("is now running in the background. Please manually refresh the page to see the update.")));
            }
        }
        final ICommonsSet<ISMPServiceGroup> aServiceGroups = aServiceGroupsGroupedPerURL.get(sOldUnifiedCert);
        final int nSGCount = CollectionHelper.getSize(aServiceGroups);
        final int nEPCount = CollectionHelper.getSize(aEndpointsGroupedPerURL.get(sOldUnifiedCert));
        aNodeList.addChild(info("The selected old certificate is currently used in " + nEPCount + " " + (nEPCount == 1 ? "endpoint" : "endpoints") + " of " + nSGCount + " " + (nSGCount == 1 ? "service group" : "service groups") + "."));
        // Show edit screen
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT));
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_SUBACTION, CPageParam.ACTION_SAVE));
        aForm.addChild(new HCHiddenField(FIELD_OLD_CERTIFICATE, sOldUnifiedCert));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Old certificate").setCtrl(_getCertificateDisplay(sOldUnifiedCert, aDisplayLocale)).setHelpText("The old certificate that is to be changed in all matching endpoints").setErrorList(aFormErrors.getListOfField(FIELD_OLD_CERTIFICATE)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("New certificate").setCtrl(new HCTextArea(new RequestField(FIELD_NEW_CERTIFICATE, sOldUnifiedCert)).setRows(10)).setHelpText("The new certificate that is used instead").setErrorList(aFormErrors.getListOfField(FIELD_NEW_CERTIFICATE)));
        final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
        aToolbar.addSubmitButton("Save changes", EDefaultIcon.SAVE);
        aToolbar.addButtonCancel(aDisplayLocale);
    }
    if (bShowList) {
        aNodeList.addChild(info().addChildren(div("This page lets you change the certificates of multiple endpoints at once. This is e.g. helpful when the old certificate expired."), div("Currently " + (nTotalEndpointCount == 1 ? "1 endpoint is" : nTotalEndpointCount + " endpoints are") + " registered.")));
        final HCTable aTable = new HCTable(new DTCol("Certificate").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Service Group Count").setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol("Endpoint Count").setDisplayType(EDTColType.INT, aDisplayLocale), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
        aEndpointsGroupedPerURL.forEach((sCert, aEndpoints) -> {
            final HCRow aRow = aTable.addBodyRow();
            aRow.addCell(_getCertificateDisplay(sCert, aDisplayLocale));
            final int nSGCount = CollectionHelper.getSize(aServiceGroupsGroupedPerURL.get(sCert));
            aRow.addCell(Integer.toString(nSGCount));
            aRow.addCell(Integer.toString(aEndpoints.size()));
            final ISimpleURL aEditURL = aWPEC.getSelfHref().add(CPageParam.PARAM_ACTION, CPageParam.ACTION_EDIT).add(FIELD_OLD_CERTIFICATE, sCert);
            aRow.addCell(new HCA(aEditURL).setTitle("Change all endpoints using this certificate").addChild(EDefaultIcon.EDIT.getAsNode()));
        });
        final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
        aNodeList.addChild(aTable).addChild(aDataTables);
    }
}
Also used : Locale(java.util.Locale) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) FormErrorList(com.helger.photon.core.form.FormErrorList) HCRow(com.helger.html.hc.html.tabular.HCRow) PDTToString(com.helger.commons.datetime.PDTToString) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) DataTables(com.helger.photon.uictrls.datatables.DataTables) RequestField(com.helger.photon.core.form.RequestField) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) HCA(com.helger.html.hc.html.textlevel.HCA) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCTable(com.helger.html.hc.html.tabular.HCTable) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup)

Aggregations

BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)35 RequestField (com.helger.photon.core.form.RequestField)34 HCEdit (com.helger.html.hc.html.forms.HCEdit)29 Locale (java.util.Locale)25 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)24 HCNodeList (com.helger.html.hc.impl.HCNodeList)20 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)19 FormErrorList (com.helger.photon.core.form.FormErrorList)18 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)12 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)12 RequestFieldBoolean (com.helger.photon.core.form.RequestFieldBoolean)10 PDTToString (com.helger.commons.datetime.PDTToString)8 HCTextArea (com.helger.html.hc.html.forms.HCTextArea)8 HCA (com.helger.html.hc.html.textlevel.HCA)7 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)7 HCHiddenField (com.helger.html.hc.html.forms.HCHiddenField)6 HCTextNode (com.helger.html.hc.impl.HCTextNode)6 ICommonsList (com.helger.commons.collection.impl.ICommonsList)5 IHCNode (com.helger.html.hc.IHCNode)5 HCDiv (com.helger.html.hc.html.grouping.HCDiv)5