Search in sources :

Example 21 with HCDiv

use of com.helger.html.hc.html.grouping.HCDiv 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 22 with HCDiv

use of com.helger.html.hc.html.grouping.HCDiv 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)

Example 23 with HCDiv

use of com.helger.html.hc.html.grouping.HCDiv in project phoss-smp by phax.

the class SMPLoginHTMLProvider method createFormFooter.

@Override
@Nullable
protected IHCNode createFormFooter(@Nonnull final ISimpleWebExecutionContext aSWEC) {
    final HCDiv aDiv = new HCDiv().addClass(CBootstrapCSS.D_FLEX).addClass(CBootstrapCSS.MT_3);
    aDiv.addChild(new HCSmall().addChild(CSMP.getApplicationTitleAndVersion()));
    return aDiv;
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCSmall(com.helger.html.hc.html.textlevel.HCSmall) Nullable(javax.annotation.Nullable)

Example 24 with HCDiv

use of com.helger.html.hc.html.grouping.HCDiv in project phoss-smp by phax.

the class SMPRendererSecure method getMenuContent.

@Nonnull
public static IHCNode getMenuContent(@Nonnull final ILayoutExecutionContext aLEC) {
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final HCNodeList ret = new HCNodeList();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    ret.addChild(BootstrapMenuItemRenderer.createSideBarMenu(aLEC));
    final BootstrapSuccessBox aBox = new BootstrapSuccessBox().addClass(CBootstrapCSS.MT_2);
    if (SMPMetaManager.getInstance().getBackendConnectionState().isFalse()) {
        aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" No database connection: ").addChild(new HCA(CAjax.FUNCTION_BACKEND_CONNECTION_RESET.getInvocationURL(aRequestScope)).addChild("Retry")));
        aBox.setType(EBootstrapAlertType.DANGER);
    }
    // Information on SML usage
    if (aSettings.isSMLEnabled()) {
        aBox.addChild(new HCDiv().addChild(EDefaultIcon.YES.getAsNode()).addChild(" SML connection is configured."));
        if (aSettings.getSMLInfo() == null) {
            aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" No SML is selected. ").addChild(new HCA(aLEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).addChild("Fix me")));
            aBox.setType(EBootstrapAlertType.DANGER);
        }
    } else {
        // Warn only if SML is needed
        if (aSettings.isSMLRequired()) {
            aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" SML connection is NOT configured. ").addChild(new HCA(aLEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).addChild("Fix me")));
            aBox.setTypeIfWorse(EBootstrapAlertType.WARNING);
        }
    }
    if (aSettings.isDirectoryIntegrationRequired()) {
        if (aSettings.isDirectoryIntegrationEnabled()) {
            aBox.addChild(new HCDiv().addChild(EDefaultIcon.YES.getAsNode()).addChild(" Directory support is configured."));
            if (StringHelper.hasNoText(aSettings.getDirectoryHostName())) {
                aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" No Directory host is provided. ").addChild(new HCA(aLEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).addChild("Fix me")));
                aBox.setType(EBootstrapAlertType.DANGER);
            }
        } else {
            // Warn only if Directory is needed
            aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" Directory support is NOT configured. ").addChild(new HCA(aLEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).addChild("Fix me")));
            aBox.setTypeIfWorse(EBootstrapAlertType.WARNING);
        }
    }
    // Information on certificate
    if (!SMPKeyManager.isKeyStoreValid()) {
        aBox.addChild(new HCDiv().addChild(EDefaultIcon.NO.getAsNode()).addChild(" Certificate configuration is invalid."));
        aBox.setType(EBootstrapAlertType.DANGER);
    }
    ret.addChild(aBox);
    return ret;
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) HCA(com.helger.html.hc.html.textlevel.HCA) BootstrapSuccessBox(com.helger.photon.bootstrap4.alert.BootstrapSuccessBox) Nonnull(javax.annotation.Nonnull)

Example 25 with HCDiv

use of com.helger.html.hc.html.grouping.HCDiv in project peppol-practical by phax.

the class CommentUI method getCommentList.

@Nonnull
public static IHCNode getCommentList(@Nonnull final ILayoutExecutionContext aLEC, @Nonnull final ITypedObject<String> aObject, @Nonnull final CommentAction aCommentAction, @Nullable final CommentFormErrors aFormErrors, @Nullable final IHCNode aMessageBox, final boolean bShowCreateComments) {
    ValueEnforcer.notNull(aLEC, "LEC");
    ValueEnforcer.notNull(aObject, "Object");
    ValueEnforcer.notNull(aCommentAction, "CommentAction");
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final HCDiv ret = new HCDiv();
    final String sResultDivID = ret.ensureID().getID();
    final boolean bUserCanCreateComments = CommentSecurity.canCurrentUserPostComments();
    final boolean bIsAdmin = aLEC.isLoggedInUserAdministrator();
    // Get all existing comments
    final List<ICommentThread> aComments = CommentThreadManager.getInstance().getAllCommentThreadsOfObject(aObject);
    if (CollectionHelper.isNotEmpty(aComments)) {
        final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
        final boolean bIsCommentModerator = CommentSecurity.isCurrentUserCommentModerator();
        // Container for all threads
        final HCDiv aAllThreadsContainer = new HCDiv().addClass(CCommentCSS.CSS_CLASS_COMMENT_CONTAINER);
        for (final ICommentThread aCommentThread : CollectionHelper.getSorted(aComments, Comparator.comparing(ICommentThread::getInitialCommentCreationDateTime))) {
            // Container for this thread
            final HCDiv aThreadContainer = new HCDiv();
            aThreadContainer.addClass(CCommentCSS.CSS_CLASS_COMMENT_THREAD);
            final NonBlockingStack<AbstractHCDiv<?>> aStack = new NonBlockingStack<>();
            aStack.push(aThreadContainer);
            aCommentThread.iterateAllComments(new ICommentIterationCallback() {

                public void onCommentStart(final int nLevel, @Nullable final IComment aParentComment, @Nonnull final IComment aComment) {
                    // Show only approved comments
                    final boolean bIsApproved = aComment.getState().isApproved();
                    if (bIsApproved || bIsCommentModerator) {
                        // Get author name and determine if it is a registered user
                        boolean bRegisteredUser = false;
                        String sAuthor = null;
                        if (StringHelper.hasText(aComment.getUserID())) {
                            final IUser aUser = aUserMgr.getUserOfID(aComment.getUserID());
                            if (aUser != null) {
                                sAuthor = aUser.getDisplayName();
                                bRegisteredUser = true;
                            }
                        }
                        if (sAuthor == null)
                            sAuthor = aComment.getCreatorName();
                        // Fill panel header
                        final BootstrapCard aCommentPanel = new BootstrapCard();
                        final BootstrapCardHeader aHeader = aCommentPanel.createAndAddHeader();
                        final BootstrapCardBody aBody = aCommentPanel.createAndAddBody();
                        if (!bIsApproved)
                            aHeader.addClass(CBootstrapCSS.BG_DANGER);
                        // Is comment deleted?
                        if (aComment.isDeleted())
                            aHeader.addChild(new HCStrong().addChild(ECommentText.MSG_IS_DELETED.getDisplayText(aDisplayLocale)));
                        // Creation date
                        aHeader.addChild(new HCSpan().addChild(PDTToString.getAsString(aComment.getCreationDateTime(), aDisplayLocale)).addClass(CCommentCSS.CSS_CLASS_COMMENT_CREATIONDT));
                        // Author
                        aHeader.addChild(ECommentText.MSG_BY.getDisplayText(aDisplayLocale));
                        final HCSpan aAuthor = new HCSpan().addChild(sAuthor).addClass(CCommentCSS.CSS_CLASS_COMMENT_AUTHOR);
                        if (bRegisteredUser)
                            aAuthor.addClass(CCommentCSS.CSS_CLASS_COMMENT_REGISTERED_USER);
                        if (bIsAdmin)
                            aAuthor.addChild(bRegisteredUser ? " [registered]" : " [not-registered]");
                        aHeader.addChild(aAuthor);
                        // Title
                        if (StringHelper.hasText(aComment.getTitle())) {
                            aHeader.addChild(ECommentText.MSG_SEPARATOR_AUTHOR_TITLE.getDisplayText(aDisplayLocale));
                            aHeader.addChild(new HCSpan().addChild(aComment.getTitle()).addClass(CCommentCSS.CSS_CLASS_COMMENT_TITLE));
                        }
                        // Toolbar
                        final HCSpan aCommentToolbar = new HCSpan().addClass(CCommentCSS.CSS_CLASS_COMMENT_TOOLBAR);
                        HCDiv aCommentResponseContainer = null;
                        // Respond to a comment - at maximum 6 levels
                        if (bShowCreateComments && bUserCanCreateComments && !aComment.isDeleted() && nLevel < 6) {
                            aCommentResponseContainer = new HCDiv();
                            final BootstrapButton aResponseButton = new BootstrapButton(EBootstrapButtonSize.SMALL).setIcon(EDefaultIcon.ADD);
                            aCommentToolbar.addChild(aResponseButton);
                            aCommentToolbar.addChild(new BootstrapTooltip(aResponseButton).setTitle(ECommentText.TOOLTIP_RESPONSE.getDisplayText(aDisplayLocale)));
                            if (aCommentAction.isMatching(ECommentAction.ADD_COMMENT, aCommentThread, aComment) && aFormErrors != null && aFormErrors.isReplyTo(aCommentThread, aComment)) {
                                // Upon adding a response
                                if (aMessageBox == null || !aFormErrors.isEmpty()) {
                                    // Show the input form again
                                    aCommentResponseContainer.addChild(getCreateComment(aLEC, sResultDivID, aObject, aCommentThread, aComment, aFormErrors, aMessageBox));
                                } else {
                                    // Show the success or error message
                                    aBody.addChild(aMessageBox);
                                }
                            } else {
                                // Add the JS to show the input form
                                final JSAnonymousFunction aOnSuccess = new JSAnonymousFunction();
                                final JSVar aJSData = aOnSuccess.param("data");
                                aOnSuccess.body().add(JQuery.idRef(aCommentResponseContainer).empty().append(aJSData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
                                final JQueryInvocation aResponseAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_SHOW_INPUT.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentShowInput.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentShowInput.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentShowInput.PARAM_COMMENT_THREAD_ID, aCommentThread.getID()).add(AjaxExecutorCommentShowInput.PARAM_COMMENT_ID, aComment.getID()).add(AjaxExecutorCommentShowInput.PARAM_RESULT_DIV_ID, sResultDivID)).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
                                aResponseButton.setOnClick(aResponseAction);
                            }
                        }
                        if (bIsCommentModerator) {
                            if (aCommentAction.isMatching(ECommentAction.DELETE_COMMENT, aCommentThread, aComment))
                                aBody.addChild(aMessageBox);
                            // Can the comment be deleted?
                            if (!aComment.isDeleted()) {
                                final BootstrapButton aDeleteButton = new BootstrapButton(EBootstrapButtonSize.SMALL).setIcon(EDefaultIcon.DELETE);
                                aCommentToolbar.addChild(aDeleteButton);
                                aCommentToolbar.addChild(new BootstrapTooltip(aDeleteButton).setTitle(ECommentText.TOOLTIP_DELETE.getDisplayText(aDisplayLocale)));
                                final JSAnonymousFunction aOnSuccess = new JSAnonymousFunction();
                                final JSVar aJSData = aOnSuccess.param("data");
                                aOnSuccess.body().add(JQuery.idRef(sResultDivID).replaceWith(aJSData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
                                final JQueryInvocation aDeleteAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_DELETE.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentDelete.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentDelete.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentDelete.PARAM_COMMENT_THREAD_ID, aCommentThread.getID()).add(AjaxExecutorCommentDelete.PARAM_COMMENT_ID, aComment.getID())).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
                                aDeleteButton.setOnClick(aDeleteAction);
                            }
                            // Show source host and further info
                            aCommentToolbar.addChild(BootstrapSimpleTooltip.createSimpleTooltip(ECommentText.TOOLTIP_HOST.getDisplayTextWithArgs(aDisplayLocale, aComment.getHost())));
                        }
                        if (aCommentToolbar.hasChildren())
                            aHeader.addChild(aCommentToolbar);
                        // Last modification
                        if (aComment.getLastModificationDateTime() != null) {
                            final String sLastModDT = PDTToString.getAsString(aComment.getLastModificationDateTime(), aDisplayLocale);
                            final String sLastModText = aComment.getEditCount() > 0 ? ECommentText.MSG_EDITED_AND_LAST_MODIFICATION.getDisplayTextWithArgs(aDisplayLocale, Integer.valueOf(aComment.getEditCount()), sLastModDT) : ECommentText.MSG_LAST_MODIFICATION.getDisplayTextWithArgs(aDisplayLocale, sLastModDT);
                            aHeader.addChild(new HCDiv().addChild(sLastModText).addClass(CCommentCSS.CSS_CLASS_COMMENT_LAST_MODIFICATION));
                        }
                        // Show the main comment text
                        aBody.addClass(CCommentCSS.CSS_CLASS_SINGLE_COMMENT);
                        // Always put the text as the first part of the body
                        aBody.addChildAt(0, new HCDiv().addChildren(HCExtHelper.nl2brList(aComment.getText())).addClass(CCommentCSS.CSS_CLASS_COMMENT_TEXT));
                        // the dummy container for new comment form
                        aBody.addChild(aCommentResponseContainer);
                        aStack.peek().addChild(aCommentPanel);
                        aStack.push(aBody);
                    } else {
                        // Don't display - push the previous item
                        aStack.push(aStack.peek());
                    }
                }

                public void onCommentEnd(final int nLevel, @Nullable final IComment aParentComment, @Nonnull final IComment aComment) {
                    aStack.pop();
                }
            });
            // Show only thread panels which contain at least one comment
            if (aThreadContainer.hasChildren())
                aAllThreadsContainer.addChild(aThreadContainer);
        }
        ret.addChild(aAllThreadsContainer);
    }
    if (bShowCreateComments) {
        // Create comment only for logged in users
        if (bUserCanCreateComments) {
            // Add "create comment" button
            final boolean bIsForCreateThread = aCommentAction.isMatching(ECommentAction.CREATE_THREAD);
            ret.addChild(getCreateComment(aLEC, sResultDivID, aObject, null, null, bIsForCreateThread ? aFormErrors : null, bIsForCreateThread ? aMessageBox : null));
        } else
            ret.addChild(new BootstrapBadge(EBootstrapBadgeType.INFO).addChild(ECommentText.MSG_LOGIN_TO_COMMENT.getDisplayText(aDisplayLocale)));
    }
    return ret;
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) AbstractHCDiv(com.helger.html.hc.html.grouping.AbstractHCDiv) BootstrapCardHeader(com.helger.photon.bootstrap4.card.BootstrapCardHeader) IComment(com.helger.peppol.comment.domain.IComment) JQueryInvocation(com.helger.html.jquery.JQueryInvocation) IUserManager(com.helger.photon.security.user.IUserManager) PDTToString(com.helger.commons.datetime.PDTToString) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) HCSpan(com.helger.html.hc.html.textlevel.HCSpan) JQueryAjaxBuilder(com.helger.html.jquery.JQueryAjaxBuilder) IUser(com.helger.photon.security.user.IUser) ICommentIterationCallback(com.helger.peppol.comment.domain.ICommentIterationCallback) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) HCStrong(com.helger.html.hc.html.textlevel.HCStrong) JSAnonymousFunction(com.helger.html.jscode.JSAnonymousFunction) BootstrapBadge(com.helger.photon.bootstrap4.badge.BootstrapBadge) JSVar(com.helger.html.jscode.JSVar) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) AbstractHCDiv(com.helger.html.hc.html.grouping.AbstractHCDiv) BootstrapTooltip(com.helger.photon.bootstrap4.tooltip.BootstrapTooltip) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) JSAssocArray(com.helger.html.jscode.JSAssocArray) NonBlockingStack(com.helger.commons.collection.NonBlockingStack) Nonnull(javax.annotation.Nonnull)

Aggregations

HCDiv (com.helger.html.hc.html.grouping.HCDiv)32 Nonnull (javax.annotation.Nonnull)21 HCNodeList (com.helger.html.hc.impl.HCNodeList)18 Locale (java.util.Locale)16 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)11 HCEdit (com.helger.html.hc.html.forms.HCEdit)9 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)9 PDTToString (com.helger.commons.datetime.PDTToString)8 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)8 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)8 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)7 BootstrapTable (com.helger.photon.bootstrap4.table.BootstrapTable)7 RequestField (com.helger.photon.core.form.RequestField)7 HCSpan (com.helger.html.hc.html.textlevel.HCSpan)6 HCTextNode (com.helger.html.hc.impl.HCTextNode)6 JQueryAjaxBuilder (com.helger.html.jquery.JQueryAjaxBuilder)6 JSAnonymousFunction (com.helger.html.jscode.JSAnonymousFunction)6 JSAssocArray (com.helger.html.jscode.JSAssocArray)6 JSVar (com.helger.html.jscode.JSVar)6 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)6