Пример #1
0
 public UICommentForm() throws Exception {
   currentUser_ = FAQUtils.getCurrentUser();
   addUIFormInput(
       (new UIFormStringInput(TITLE_USERNAME, TITLE_USERNAME, currentUser_)).setReadOnly(true));
   UIFormWYSIWYGInput commentContent =
       new UIFormWYSIWYGInput(COMMENT_CONTENT, COMMENT_CONTENT, "");
   commentContent.setFCKConfig(WebUIUtils.getFCKConfig());
   commentContent.setToolBarName("Basic");
   this.addChild(commentContent);
 }
Пример #2
0
    public void onEvent(
        Event<UICommentForm> event, UICommentForm commentForm, final String objectId)
        throws Exception {
      String comment =
          ((UIFormWYSIWYGInput) commentForm.getChildById(commentForm.COMMENT_CONTENT)).getValue();
      if (CommonUtils.isEmpty(comment) || !ValidatorDataInput.fckContentIsNotEmpty(comment)) {
        warning("UICommentForm.msg.comment-is-null");
        return;
      }
      if (!commentForm.getFAQService().isExisting(commentForm.question_.getPath())) {
        warning("UIQuestions.msg.comment-id-deleted");
        return;
      }
      UIAnswersPortlet portlet = commentForm.getAncestorOfType(UIAnswersPortlet.class);
      UIAnswersContainer answersContainer = portlet.getChild(UIAnswersContainer.class);
      UIQuestions questions = answersContainer.getChild(UIQuestions.class);
      comment = CommonUtils.encodeSpecialCharInContent(comment);
      try {
        // Create link by Vu Duy Tu.
        if (FAQUtils.isFieldEmpty(commentForm.question_.getLink())) {
          commentForm.question_.setLink(
              FAQUtils.getQuestionURI(commentForm.question_.getId(), false));
        }
        if (commentForm.comment != null) {
          commentForm.comment.setNew(false);
        } else {
          commentForm.comment = new Comment();
          commentForm.comment.setNew(true);
        }
        commentForm.comment.setComments(comment);
        // For discuss in forum
        String topicId = commentForm.question_.getTopicIdDiscuss();
        if (topicId != null && topicId.length() > 0) {
          ForumService forumService =
              (ForumService)
                  PortalContainer.getInstance().getComponentInstanceOfType(ForumService.class);
          Topic topic =
              (Topic)
                  forumService.getObjectNameById(
                      topicId, org.exoplatform.forum.service.Utils.TOPIC);
          if (topic != null) {
            String remoteAddr = WebUIUtils.getRemoteIP();
            String[] ids = topic.getPath().split("/");
            int t = ids.length;
            String linkForum = FAQUtils.getLinkDiscuss(topicId);
            String postId = commentForm.comment.getPostId();
            if (postId == null || postId.length() == 0) {
              Post post = new Post();
              post.setOwner(commentForm.currentUser_);
              post.setIcon("ViewIcon");
              post.setName("Re: " + commentForm.question_.getQuestion());
              post.setMessage(comment);
              post.setLink(linkForum + "/" + postId);
              post.setIsApproved(!topic.getIsModeratePost());
              post.setRemoteAddr(remoteAddr);
              try {
                forumService.savePost(
                    ids[t - 3], ids[t - 2], topicId, post, true, new MessageBuilder());
              } catch (Exception e) {
                event.getSource().log.debug("Saving post fail: ", e);
              }
              commentForm.comment.setPostId(post.getId());
            } else {
              try {
                Post post = forumService.getPost(ids[t - 3], ids[t - 2], topicId, postId);
                boolean isNew = false;
                if (post == null) {
                  post = new Post();
                  isNew = true;
                  post.setOwner(commentForm.currentUser_);
                  post.setIcon("ViewIcon");
                  post.setName("Re: " + commentForm.question_.getQuestion());
                  commentForm.comment.setPostId(post.getId());
                  post.setLink(linkForum + "/" + postId);
                  post.setRemoteAddr(remoteAddr);
                } else {
                  post.setModifiedBy(commentForm.currentUser_);
                }
                post.setIsApproved(!topic.getIsModeratePost());
                post.setMessage(comment);
                forumService.savePost(
                    ids[t - 3], ids[t - 2], topicId, post, isNew, new MessageBuilder());
              } catch (Exception e) {
                event.getSource().log.debug("Saving post fail: ", e);
              }
            }
          }
        }

        String language = "";
        if (!commentForm.languageSelected.equals(commentForm.question_.getLanguage()))
          language = commentForm.languageSelected;
        String currentUser = FAQUtils.getCurrentUser();
        commentForm.comment.setCommentBy(currentUser);
        commentForm.comment.setFullName(FAQUtils.getFullName(null));
        commentForm
            .getFAQService()
            .saveComment(commentForm.question_.getPath(), commentForm.comment, language);
        if (!commentForm.languageSelected.equals(commentForm.question_.getLanguage())) {
          try {
            questions.updateCurrentLanguage();
          } catch (Exception e) {
            questions.updateQuestionLanguageByLanguage(
                commentForm.question_.getPath(), commentForm.languageSelected);
          }
        } else {
          questions.updateQuestionLanguageByLanguage(
              commentForm.question_.getPath(), commentForm.languageSelected);
        }
      } catch (Exception e) {
        event.getSource().log.error("Fail to save action: ", e);
        warning("UIQuestions.msg.category-id-deleted", false);
      }
      portlet.cancelAction();
      event.getRequestContext().addUIComponentToUpdateByAjax(answersContainer);
    }