Search in sources :

Example 1 with ICommentThread

use of com.helger.peppol.comment.domain.ICommentThread in project peppol-practical by phax.

the class AjaxExecutorCommentAdd method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
    final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
    final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
    final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
    String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
    final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
    final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
    // Get info on current user
    final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
    final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
    if (aCurrentUser != null)
        sAuthor = aCurrentUser.getDisplayName();
    if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.canCurrentUserPostComments()) {
        // Create a dummy object
        final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
        final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
        if (aCommentThread != null) {
            final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
            if (aParentComment != null) {
                final CommentFormErrors aFormErrors = CommentFormErrors.createForReply(aCommentThread, aParentComment);
                if (StringHelper.hasNoText(sAuthor)) {
                    // No author provided
                    aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
                }
                if (StringHelper.hasNoText(sText)) {
                    // No text provided
                    aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
                }
                IHCNode aMessageBox = null;
                if (aFormErrors.isEmpty()) {
                    // Go ahead and save
                    final ESuccess eSuccess = CommentThreadManager.getInstance().addCommentToThread(aOwner, sCommentThreadID, sCommentID, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
                    if (eSuccess.isSuccess())
                        aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
                    else
                        aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
                }
                // List of exiting comments + message box
                aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createForComment(ECommentAction.ADD_COMMENT, aCommentThread, aParentComment), aFormErrors, aMessageBox, true));
                return;
            }
        }
    }
    // Somebody played around with the API
    LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for adding to comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
    aAjaxResponse.createNotFound();
}
Also used : Locale(java.util.Locale) ESuccess(com.helger.commons.state.ESuccess) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) CommentFormErrors(com.helger.peppol.comment.ui.CommentFormErrors) IComment(com.helger.peppol.comment.domain.IComment) Comment(com.helger.peppol.comment.domain.Comment) IComment(com.helger.peppol.comment.domain.IComment) IUser(com.helger.photon.security.user.IUser) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) IHCNode(com.helger.html.hc.IHCNode)

Example 2 with ICommentThread

use of com.helger.peppol.comment.domain.ICommentThread in project peppol-practical by phax.

the class AjaxExecutorCommentCreateThread method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
    final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
    String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
    final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
    final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
    // Get info on current user
    final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
    final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
    if (aCurrentUser != null)
        sAuthor = aCurrentUser.getDisplayName();
    if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && CommentSecurity.canCurrentUserPostComments()) {
        // Create a dummy object
        final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
        final CommentFormErrors aFormErrors = CommentFormErrors.createForNewThread();
        if (StringHelper.hasNoText(sAuthor)) {
            // No author provided
            aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
        }
        if (StringHelper.hasNoText(sText)) {
            // No text provided
            aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
        }
        IHCNode aMessageBox = null;
        if (aFormErrors.isEmpty()) {
            // Go ahead and save
            final ICommentThread aNewThread = CommentThreadManager.getInstance().createNewThread(aOwner, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
            if (aNewThread != null)
                aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
            else
                aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
        }
        // List of exiting comments + message box
        aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createGeneric(ECommentAction.CREATE_THREAD), aFormErrors, aMessageBox, true));
        return;
    }
    // Somebody played around with the API
    LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "'");
    aAjaxResponse.createNotFound();
}
Also used : Locale(java.util.Locale) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) CommentFormErrors(com.helger.peppol.comment.ui.CommentFormErrors) Comment(com.helger.peppol.comment.domain.Comment) IUser(com.helger.photon.security.user.IUser) IHCNode(com.helger.html.hc.IHCNode) ICommentThread(com.helger.peppol.comment.domain.ICommentThread)

Example 3 with ICommentThread

use of com.helger.peppol.comment.domain.ICommentThread in project peppol-practical by phax.

the class PageSecureCommentAdmin method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CommentThreadManager aCommentThreadMgr = CommentThreadManager.getInstance();
    boolean bShowList = true;
    final String sSelectedObjectType = aWPEC.params().getAsString(PARAM_TYPE);
    final String sSelectedOwningObjectID = aWPEC.params().getAsString(CPageParam.PARAM_OBJECT);
    if (aWPEC.hasAction(CPageParam.ACTION_VIEW) && StringHelper.hasText(sSelectedObjectType) && StringHelper.hasText(sSelectedOwningObjectID)) {
        final TypedObject<String> aTO = TypedObject.create(new ObjectType(sSelectedObjectType), sSelectedOwningObjectID);
        final List<ICommentThread> aCommentThreads = aCommentThreadMgr.getAllCommentThreadsOfObject(aTO);
        if (!aCommentThreads.isEmpty()) {
            // Don't allow comment creation
            aNodeList.addChild(CommentUI.getCommentList(aWPEC, aTO, CommentAction.createGeneric(ECommentAction.NONE), null, null, false));
            // Toolbar
            final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
            aToolbar.addButton(EPhotonCoreText.BACK_TO_OVERVIEW.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.BACK_TO_LIST);
            aNodeList.addChild(aToolbar);
            bShowList = false;
        }
    }
    if (bShowList) {
        // Refresh button
        final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton(EPhotonCoreText.BUTTON_REFRESH.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aNodeList.addChild(aToolbar);
        final ITabBox<?> aTabBox = new BootstrapTabBox();
        for (final ObjectType aOT : CollectionHelper.getSorted(aCommentThreadMgr.getAllRegisteredObjectTypes())) {
            final HCNodeList aTab = new HCNodeList();
            final HCTable aTable = new HCTable(new DTCol(EText.HEADER_OBJECT_ID.getDisplayText(aDisplayLocale)), new DTCol(EText.HEADER_THREADS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_ACTIVE_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_LAST_CHANGE.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.DATETIME, aDisplayLocale).setInitialSorting(ESortOrder.DESCENDING)).setID(getID() + aOT.getName());
            final CommentThreadObjectTypeManager aCTOTMgr = aCommentThreadMgr.getManagerOfObjectType(aOT);
            for (final Map.Entry<String, ICommonsList<ICommentThread>> aEntry : aCTOTMgr.getAllCommentThreads().entrySet()) {
                final String sOwningObjectID = aEntry.getKey();
                final ISimpleURL aViewURL = AbstractWebPageForm.createViewURL(aWPEC, sOwningObjectID).add(PARAM_TYPE, aOT.getName());
                final HCRow aRow = aTable.addBodyRow();
                aRow.addCell(new HCA(aViewURL).addChild(sOwningObjectID));
                aRow.addCell(Integer.toString(aEntry.getValue().size()));
                int nActiveComments = 0;
                final ICommonsList<IComment> aAllComments = new CommonsArrayList<>();
                for (final ICommentThread aCommentThread : aEntry.getValue()) {
                    aAllComments.addAll(aCommentThread.getAllComments());
                    nActiveComments += aCommentThread.getTotalActiveCommentCount();
                }
                Collections.sort(aAllComments, Comparator.comparing(IComment::getLastChangeDateTime).reversed());
                aRow.addCell(Integer.toString(aAllComments.size()));
                aRow.addCell(Integer.toString(nActiveComments));
                if (aAllComments.isEmpty())
                    aRow.addCell();
                else
                    aRow.addCell(PDTToString.getAsString(aAllComments.get(0).getLastChangeDateTime(), aDisplayLocale));
            }
            aTab.addChild(aTable);
            final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
            aTab.addChild(aDataTables);
            aTabBox.addTab(aOT.getName(), aOT.getName(), aTab, aOT.getName().equals(sSelectedObjectType));
        }
        aNodeList.addChild(aTabBox);
    }
}
Also used : Locale(java.util.Locale) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IComment(com.helger.peppol.comment.domain.IComment) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCRow(com.helger.html.hc.html.tabular.HCRow) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) ObjectType(com.helger.commons.type.ObjectType) CommentThreadObjectTypeManager(com.helger.peppol.comment.domain.CommentThreadObjectTypeManager) ISimpleURL(com.helger.commons.url.ISimpleURL) CommentThreadManager(com.helger.peppol.comment.domain.CommentThreadManager) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) HCA(com.helger.html.hc.html.textlevel.HCA) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) Map(java.util.Map) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 4 with ICommentThread

use of com.helger.peppol.comment.domain.ICommentThread 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)

Example 5 with ICommentThread

use of com.helger.peppol.comment.domain.ICommentThread in project peppol-practical by phax.

the class AjaxExecutorCommentDelete method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
    final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
    final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
    final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
    if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.isCurrentUserCommentModerator()) {
        // Create a dummy object
        final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
        final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
        if (aCommentThread != null) {
            final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
            if (aParentComment != null) {
                // Go ahead and delete
                final EChange eChange = CommentThreadManager.getInstance().updateCommentState(aOwner, sCommentThreadID, sCommentID, ECommentState.DELETED_BY_MODERATOR);
                IHCNode aMessageBox;
                if (eChange.isChanged())
                    aMessageBox = success(ECommentText.MSG_COMMENT_DELETE_SUCCESS.getDisplayText(aDisplayLocale));
                else
                    aMessageBox = error(ECommentText.MSG_COMMENT_DELETE_FAILURE.getDisplayText(aDisplayLocale));
                // Message box + list of exiting comments
                aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createForComment(ECommentAction.DELETE_COMMENT, aCommentThread, aParentComment), null, aMessageBox, true));
                return;
            }
        }
    }
    // Somebody played around with the API
    LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for deletion of comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
    aAjaxResponse.createNotFound();
}
Also used : Locale(java.util.Locale) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) IComment(com.helger.peppol.comment.domain.IComment) EChange(com.helger.commons.state.EChange) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) IHCNode(com.helger.html.hc.IHCNode)

Aggregations

ICommentThread (com.helger.peppol.comment.domain.ICommentThread)6 ObjectType (com.helger.commons.type.ObjectType)5 IComment (com.helger.peppol.comment.domain.IComment)5 Locale (java.util.Locale)5 IHCNode (com.helger.html.hc.IHCNode)4 LayoutExecutionContext (com.helger.photon.core.execcontext.LayoutExecutionContext)4 IUser (com.helger.photon.security.user.IUser)3 PDTToString (com.helger.commons.datetime.PDTToString)2 Comment (com.helger.peppol.comment.domain.Comment)2 CommentFormErrors (com.helger.peppol.comment.ui.CommentFormErrors)2 NonBlockingStack (com.helger.commons.collection.NonBlockingStack)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 EChange (com.helger.commons.state.EChange)1 ESuccess (com.helger.commons.state.ESuccess)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 AbstractHCDiv (com.helger.html.hc.html.grouping.AbstractHCDiv)1 HCDiv (com.helger.html.hc.html.grouping.HCDiv)1 HCRow (com.helger.html.hc.html.tabular.HCRow)1 HCTable (com.helger.html.hc.html.tabular.HCTable)1