Search in sources :

Example 1 with JSAssocArray

use of com.helger.html.jscode.JSAssocArray in project phoss-smp by phax.

the class PageSecureBusinessCard method _createEntityInputForm.

@Nonnull
private static IHCNode _createEntityInputForm(@Nonnull final LayoutExecutionContext aLEC, @Nullable final SMPBusinessCardEntity aExistingEntity, @Nullable final String sExistingID, @Nonnull final FormErrorList aFormErrors, final boolean bFormSubmitted) {
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final String sEntityID = StringHelper.hasText(sExistingID) ? sExistingID : TMP_ID_PREFIX + Integer.toString(GlobalIDFactory.getNewIntID());
    final BootstrapCard aPanel = new BootstrapCard().setID(sEntityID);
    aPanel.createAndAddHeader().addChild("Business Entity");
    final BootstrapCardBody aBody = aPanel.createAndAddBody();
    final BootstrapViewForm aForm = aBody.addAndReturnChild(new BootstrapViewForm());
    final String sFieldName = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_NAME);
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(sFieldName, aExistingEntity == null ? null : aExistingEntity.names().getFirst().getName()))).setErrorList(aFormErrors.getListOfField(sFieldName)));
    final String sFieldCountryCode = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_COUNTRY_CODE);
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Country").setCtrl(new HCCountrySelect(new RequestField(sFieldCountryCode, aExistingEntity == null ? null : aExistingEntity.getCountryCode()), aDisplayLocale, HCCountrySelect.getAllCountries(EWithDeprecated.DEFAULT), (aLocale, aContentLocale) -> aLocale.getDisplayCountry(aContentLocale) + " (" + aLocale.getCountry() + ")")).setErrorList(aFormErrors.getListOfField(sFieldCountryCode)));
    final String sFieldGeoInfo = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_GEO_INFO);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Geographical Information").setCtrl(new HCTextArea(new RequestField(sFieldGeoInfo, aExistingEntity == null ? null : aExistingEntity.getGeographicalInformation()))).setErrorList(aFormErrors.getListOfField(sFieldGeoInfo)));
    // Identifiers
    {
        final String sBodyID = sEntityID + PREFIX_IDENTIFIER;
        final HCNodeList aNL = new HCNodeList();
        final BootstrapTable aTable = aNL.addAndReturnChild(new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star()));
        aTable.addHeaderRow().addCells("Scheme", "Value", "");
        aTable.setBodyID(sBodyID);
        final IRequestParamMap aIdentifiers = aLEC.getRequestParamMap().getMap(PREFIX_ENTITY, sEntityID, PREFIX_IDENTIFIER);
        if (bFormSubmitted) {
            // Re-show of form
            if (aIdentifiers != null)
                for (final String sIdentifierRowID : aIdentifiers.keySet()) aTable.addBodyRow(_createIdentifierInputForm(aLEC, sEntityID, null, sIdentifierRowID, aFormErrors));
        } else {
            if (aExistingEntity != null) {
                // add all existing stored entities
                for (final SMPBusinessCardIdentifier aIdentifier : aExistingEntity.identifiers()) aTable.addBodyRow(_createIdentifierInputForm(aLEC, sEntityID, aIdentifier, (String) null, aFormErrors));
            }
        }
        {
            final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
            final JSVar aJSAppendData = aJSAppend.param("data");
            aJSAppend.body().add(JQuery.idRef(sBodyID).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
            final JSPackage aOnAdd = new JSPackage();
            aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_IDENTIFIER.getInvocationURL(aRequestScope).add(PARAM_ENTITY_ID, sEntityID)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
            aNL.addChild(new BootstrapButton().setIcon(EDefaultIcon.PLUS).addChild("Add Identifier").setOnClick(aOnAdd));
        }
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Identifiers").setCtrl(aNL));
    }
    // Website URIs
    final String sFieldWebsiteURIs = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_WEBSITE_URIS);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Website URIs").setCtrl(new HCTextArea(new RequestField(sFieldWebsiteURIs, aExistingEntity == null ? null : StringHelper.getImploded('\n', aExistingEntity.websiteURIs())))).setHelpText("Put each Website URI in a separate line").setErrorList(aFormErrors.getListOfField(sFieldWebsiteURIs)));
    // Contacts
    {
        final String sBodyID = sEntityID + PREFIX_CONTACT;
        final HCNodeList aNL = new HCNodeList();
        final BootstrapTable aTable = aNL.addAndReturnChild(new BootstrapTable(HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star(), HCCol.star()));
        aTable.addHeaderRow().addCells("Type", "Name", "Phone number", "Email address", "");
        aTable.setBodyID(sBodyID);
        final IRequestParamMap aContacts = aLEC.getRequestParamMap().getMap(PREFIX_ENTITY, sEntityID, PREFIX_CONTACT);
        if (bFormSubmitted) {
            // Re-show of form
            if (aContacts != null)
                for (final String sIdentifierRowID : aContacts.keySet()) aTable.addBodyRow(_createContactInputForm(aLEC, sEntityID, null, sIdentifierRowID, aFormErrors));
        } else {
            if (aExistingEntity != null) {
                // add all existing stored entities
                for (final SMPBusinessCardContact aContact : aExistingEntity.contacts()) aTable.addBodyRow(_createContactInputForm(aLEC, sEntityID, aContact, (String) null, aFormErrors));
            }
        }
        {
            final JSAnonymousFunction aJSAppend = new JSAnonymousFunction();
            final JSVar aJSAppendData = aJSAppend.param("data");
            aJSAppend.body().add(JQuery.idRef(sBodyID).append(aJSAppendData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
            final JSPackage aOnAdd = new JSPackage();
            aOnAdd.add(new JQueryAjaxBuilder().url(AJAX_CREATE_CONTACT.getInvocationURL(aRequestScope).add(PARAM_ENTITY_ID, sEntityID)).data(new JSAssocArray()).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aJSAppend, null)).build());
            aNL.addChild(new BootstrapButton().setIcon(EDefaultIcon.PLUS).addChild("Add Contact").setOnClick(aOnAdd));
        }
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Contacts").setCtrl(aNL));
    }
    final String sFieldAdditionalInfo = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_ADDITIONAL_INFO);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Additional Information").setCtrl(new HCTextArea(new RequestField(sFieldAdditionalInfo, aExistingEntity == null ? null : aExistingEntity.getAdditionalInformation()))).setErrorList(aFormErrors.getListOfField(sFieldAdditionalInfo)));
    final String sFieldRegDate = RequestParamMap.getFieldName(PREFIX_ENTITY, sEntityID, SUFFIX_REG_DATE);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Registration Date").setCtrl(BootstrapDateTimePicker.create(sFieldRegDate, aExistingEntity == null ? null : aExistingEntity.getRegistrationDate(), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(sFieldRegDate)));
    final BootstrapButtonToolbar aToolbar = aBody.addAndReturnChild(new BootstrapButtonToolbar(aLEC));
    aToolbar.addButton("Delete this Entity", JQuery.idRef(aPanel).remove(), EDefaultIcon.DELETE);
    return aPanel;
}
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) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCTextArea(com.helger.html.hc.html.forms.HCTextArea) JSVar(com.helger.html.jscode.JSVar) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) HCEdit(com.helger.html.hc.html.forms.HCEdit) PDTToString(com.helger.commons.datetime.PDTToString) PDTFromString(com.helger.commons.datetime.PDTFromString) SMPBusinessCardIdentifier(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardIdentifier) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) SMPBusinessCardContact(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardContact) HCCountrySelect(com.helger.photon.uicore.html.select.HCCountrySelect) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) 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) 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 2 with JSAssocArray

use of com.helger.html.jscode.JSAssocArray 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 3 with JSAssocArray

use of com.helger.html.jscode.JSAssocArray in project phoss-directory by phax.

the class AppCommonUI method init.

public static void init() {
    BootstrapDataTables.setConfigurator((aLEC, aTable, aDataTables) -> {
        final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
        aDataTables.setAutoWidth(false).setLengthMenu(LENGTH_MENU).setAjaxBuilder(new JQueryAjaxBuilder().url(CAjax.DATATABLES.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorDataTables.OBJECT_ID, aTable.getID()))).setServerFilterType(EDataTablesFilterType.ALL_TERMS_PER_ROW).setTextLoadingURL(CAjax.DATATABLES_I18N.getInvocationURL(aRequestScope), AjaxExecutorDataTablesI18N.LANGUAGE_ID).addPlugin(new DataTablesPluginSearchHighlight());
    });
    // By default allow markdown in system message
    BootstrapSystemMessage.setDefaultUseMarkdown(true);
    // Change logo image?
    final String sLogoImageURL = PDServerConfiguration.getLogoImageURL();
    if (StringHelper.hasText(sLogoImageURL))
        CPDPublisher.setLogoImageURL(sLogoImageURL);
}
Also used : IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) JSAssocArray(com.helger.html.jscode.JSAssocArray) DataTablesPluginSearchHighlight(com.helger.photon.uictrls.datatables.plugins.DataTablesPluginSearchHighlight)

Example 4 with JSAssocArray

use of com.helger.html.jscode.JSAssocArray 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 5 with JSAssocArray

use of com.helger.html.jscode.JSAssocArray in project phoss-smp by phax.

the class SMPCommonUI method createViewLoginForm.

@Nonnull
public static BootstrapForm createViewLoginForm(@Nonnull final ILayoutExecutionContext 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());
    aForm.setLeft(4);
    // 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).addClass(CBootstrapCSS.MX_2));
    // 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) PDTToString(com.helger.commons.datetime.PDTToString) 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)

Aggregations

JQueryAjaxBuilder (com.helger.html.jquery.JQueryAjaxBuilder)6 JSAssocArray (com.helger.html.jscode.JSAssocArray)6 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)5 HCEdit (com.helger.html.hc.html.forms.HCEdit)4 HCDiv (com.helger.html.hc.html.grouping.HCDiv)4 JSAnonymousFunction (com.helger.html.jscode.JSAnonymousFunction)4 JSPackage (com.helger.html.jscode.JSPackage)4 JSVar (com.helger.html.jscode.JSVar)4 PDTToString (com.helger.commons.datetime.PDTToString)3 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)3 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)3 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)3 RequestField (com.helger.photon.core.form.RequestField)3 Locale (java.util.Locale)3 Nonnull (javax.annotation.Nonnull)3 Nonempty (com.helger.commons.annotation.Nonempty)2 WorkInProgress (com.helger.commons.annotation.WorkInProgress)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)2