예제 #1
0
  public void printComment(
      SimplePageComment comment,
      UIContainer tofill,
      boolean highlight,
      boolean anonymous,
      boolean showModifiers,
      CommentsViewParameters params,
      SimplePageItem commentsItem,
      SimplePage currentPage) {
    if (canEditPage && itemToPageowner != null && comment.getItemId() != lastTitle) {
      UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
      UIOutput.make(
          commentContainer,
          "commentTitle",
          messageLocator
              .getMessage("simplepage.comments-grading")
              .replace("{}", itemToPageowner.get(comment.getItemId())));
      lastTitle = comment.getItemId();
    }

    // print title if this is a comment on a different page. Normally this
    // shold only happen for subpages of student pages
    String pageTitle = null;
    if (currentPage.getPageId() != comment.getPageId()) {
      SimplePage commentPage = simplePageBean.getPage(comment.getPageId());
      pageTitle = commentPage.getTitle();
    }

    UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
    UIOutput.make(commentContainer, "commentDiv");
    if (highlight) commentContainer.decorate(new UIStyleDecorator("highlight-comment"));

    if (!filter && params.author != null && params.author.equals(comment.getAuthor())) {
      commentContainer.decorate(new UIStyleDecorator("backgroundHighlight"));
    }

    String author;

    if (!anonymous) {
      try {
        User user = UserDirectoryService.getUser(comment.getAuthor());
        author = user.getDisplayName();
      } catch (Exception ex) {
        author = messageLocator.getMessage("simplepage.comment-unknown-user");
        ex.printStackTrace();
      }
    } else {
      author = anonymousLookup.get(comment.getAuthor());

      if (comment.getAuthor().equals(owner)) {
        author = messageLocator.getMessage("simplepage.comment-author-owner");
      }

      if (author == null) author = "Anonymous User"; // Shouldn't ever occur

      if (simplePageBean.getEditPrivs() == 0) {
        try {
          User user = UserDirectoryService.getUser(comment.getAuthor());
          author += " (" + user.getDisplayName() + ")";
        } catch (Exception ex) {
          author += " (" + messageLocator.getMessage("simplepage.comment-unknown-user") + ")";
        }
      } else if (comment.getAuthor().equals(currentUserId)) {
        author += " (" + messageLocator.getMessage("simplepage.comment-you") + ")";
      }
    }

    UIOutput authorOutput = UIOutput.make(commentContainer, "userId", author);

    if (comment.getAuthor().equals(currentUserId)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("personalComment"));
    } else if (comment.getAuthor().equals(owner)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("ownerComment"));
    }

    if (pageTitle != null) UIOutput.make(commentContainer, "pageTitle", pageTitle);

    String timeDifference = getTimeDifference(comment.getTimePosted().getTime());

    UIOutput.make(commentContainer, "timePosted", timeDifference);

    if (showModifiers) {
      UIOutput.make(commentContainer, "deleteSpan");

      CommentsViewParameters eParams = (CommentsViewParameters) params.copy();
      eParams.placementId = params.placementId;
      eParams.deleteComment = comment.getUUID();
      eParams.pageId = params.pageId;
      eParams.siteId = params.siteId;

      UIInternalLink.make(commentContainer, "deleteCommentURL", eParams);
      UIOutput.make(commentContainer, "deleteComment")
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-delete").replace("{}", author)));
      UIOutput.make(commentContainer, "editComment")
          .decorate(
              new UIFreeAttributeDecorator("onclick", "edit($(this), " + comment.getId() + ");"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-edit").replace("{}", author)));

      if (!filter && simplePageBean.getEditPrivs() == 0 && commentsItem.getGradebookId() != null) {
        UIOutput.make(commentContainer, "gradingSpan");
        UIOutput.make(commentContainer, "commentsUUID", comment.getUUID());
        UIOutput.make(
            commentContainer,
            "commentPoints",
            (comment.getPoints() == null ? "" : String.valueOf(comment.getPoints())));
        UIOutput.make(commentContainer, "pointsBox")
            .decorate(
                new UIFreeAttributeDecorator(
                    "title",
                    messageLocator
                        .getMessage("simplepage.grade-for-student")
                        .replace("{}", author)));

        UIOutput.make(commentContainer, "maxpoints", " / " + commentsItem.getGradebookPoints());
        UIOutput.make(commentContainer, "authorUUID", comment.getAuthor());
      }
    }

    if (filter && simplePageBean.getEditPrivs() == 0) {
      UIOutput.make(commentContainer, "contextSpan");

      // because this is called via /faces, the full Sakai context is not set up.
      // in particular, UIInternalLink will generate the wrong thing. Thus we
      // make up a full URL ourselves.
      String pars =
          "/portal/tool/"
              + URLEncoder.encode(params.placementId)
              + "/ShowPage?path=none"
              + "&author="
              + URLEncoder.encode(comment.getAuthor());
      // Need to provide the item ID
      if (!params.studentContentItem && params.pageItemId != -1L) {
        pars += "&itemId=" + URLEncoder.encode(Long.toString(params.pageItemId));
      }
      UILink contextLink =
          UILink.make(
              commentContainer,
              "contextLink",
              messageLocator.getMessage("simplepage.show-context"),
              pars);
      if (itemToPageowner == null)
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-1")
                    .replace("{}", author)));
      else
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-2")
                    .replace("{1}", author)
                    .replace("{2}", itemToPageowner.get(comment.getItemId()))));
    }

    String dateString = df.format(comment.getTimePosted());

    if (!filter)
      UIOutput.make(commentContainer, "replyTo")
          .decorate(
              new UIFreeAttributeDecorator(
                  "onclick",
                  "replyToComment($(this),'"
                      + messageLocator
                          .getMessage("simplepage.in-reply-to")
                          .replace("{1}", author)
                          .replace("{2}", dateString)
                      + "')"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-reply").replace("{}", author)));

    if (!comment.getHtml()) {
      UIOutput.make(commentContainer, "comment", comment.getComment());
    } else {
      UIVerbatim.make(commentContainer, "comment", comment.getComment());
    }
  }
예제 #2
0
  public void fillComponents(
      UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) {
    CommentsGradingPaneViewParameters params = (CommentsGradingPaneViewParameters) viewparams;

    SimplePage currentPage = simplePageToolDao.getPage(params.pageId);
    simplePageBean.setCurrentSiteId(params.siteId);
    simplePageBean.setCurrentPage(currentPage);
    simplePageBean.setCurrentPageId(params.pageId);

    GeneralViewParameters backParams =
        new GeneralViewParameters(ShowPageProducer.VIEW_ID, params.pageId);
    backParams.setItemId(params.pageItemId);
    backParams.setPath("log");

    UIOutput.make(tofill, "html")
        .decorate(new UIFreeAttributeDecorator("lang", localeGetter.get().getLanguage()))
        .decorate(new UIFreeAttributeDecorator("xml:lang", localeGetter.get().getLanguage()));

    UIInternalLink.make(
        tofill, "back-link", messageLocator.getMessage("simplepage.go-back"), backParams);

    if (simplePageBean.getEditPrivs() != 0) {
      UIOutput.make(tofill, "permissionsError");
      return;
    }

    String heading = null;
    if (params.studentContentItem) {
      heading = messageLocator.getMessage("simplepage.student-comments-grading");
    } else {
      heading = messageLocator.getMessage("simplepage.comments-grading");
    }

    SimplePageItem commentItem = simplePageToolDao.findItem(params.commentsItemId);
    SimplePage containingPage = simplePageToolDao.getPage(commentItem.getPageId());
    heading = heading.replace("{}", containingPage.getTitle());

    UIOutput.make(tofill, "page-header", heading);

    List<SimplePageComment> comments;

    if (!params.studentContentItem) {
      comments = simplePageToolDao.findComments(params.commentsItemId);
    } else {
      List<SimpleStudentPage> studentPages =
          simplePageToolDao.findStudentPages(params.commentsItemId);

      List<Long> commentsItemIds = new ArrayList<Long>();
      for (SimpleStudentPage p : studentPages) {
        // If the page is deleted, don't show the comments
        if (!p.isDeleted()) {
          commentsItemIds.add(p.getCommentsSection());
        }
      }

      comments = simplePageToolDao.findCommentsOnItems(commentsItemIds);
    }

    ArrayList<String> userIds = new ArrayList<String>();
    HashMap<String, SimpleUser> users = new HashMap<String, SimpleUser>();

    for (SimplePageComment comment : comments) {
      if (comment.getComment() == null || comment.getComment().equals("")) {
        continue;
      }

      if (!userIds.contains(comment.getAuthor())) {
        userIds.add(comment.getAuthor());
        try {
          SimpleUser user = new SimpleUser();
          user.displayName = UserDirectoryService.getUser(comment.getAuthor()).getDisplayName();
          user.postCount++;
          user.userId = comment.getAuthor();
          user.grade = comment.getPoints();
          user.uuid = comment.getUUID();

          if (params.studentContentItem) {
            user.pages.add(comment.getPageId());
          }

          users.put(comment.getAuthor(), user);
        } catch (Exception ex) {
        }
      } else {
        SimpleUser user = users.get(comment.getAuthor());
        if (user != null) {
          user.postCount++;

          if (params.studentContentItem && !user.pages.contains(comment.getPageId())) {
            user.pages.add(comment.getPageId());
          }
        }
      }
    }

    ArrayList<SimpleUser> simpleUsers = new ArrayList<SimpleUser>(users.values());
    Collections.sort(simpleUsers);

    if (params.studentContentItem) {
      UIOutput.make(
          tofill, "unique-header", messageLocator.getMessage("simplepage.grading-unique"));
    }

    if (simpleUsers.size() > 0) {
      UIOutput.make(tofill, "gradingTable");
    } else {
      UIOutput.make(tofill, "noEntriesWarning");
    }

    if (params.studentContentItem) UIOutput.make(tofill, "clickfiller");

    UIOutput.make(tofill, "clickToSubmit", messageLocator.getMessage("simplepage.update-points"))
        .decorate(
            new UIFreeAttributeDecorator(
                "title", messageLocator.getMessage("simplepage.update-points")));

    for (SimpleUser user : simpleUsers) {
      UIBranchContainer branch = UIBranchContainer.make(tofill, "student-row:");

      UIOutput.make(branch, "first-row");
      UIOutput.make(branch, "details-row");
      UIOutput detailsCell = UIOutput.make(branch, "details-cell");

      // Set the column span based on which type of item it is.  Student content
      // items have an extra column, so we have to accommodate.
      if (params.studentContentItem) {
        detailsCell.decorate(new UIFreeAttributeDecorator("colspan", "5"));
      } else {
        detailsCell.decorate(new UIFreeAttributeDecorator("colspan", "4"));
      }
      UIOutput.make(branch, "student-name", user.displayName);
      UIOutput.make(branch, "student-total", String.valueOf(user.postCount));

      if (params.studentContentItem) {
        UIOutput.make(branch, "student-unique", String.valueOf(user.pages.size()));
      }

      // Add the link that will be fetched using Ajax
      CommentsViewParameters eParams = new CommentsViewParameters(CommentsProducer.VIEW_ID);
      eParams.placementId = ToolManager.getCurrentPlacement().getId();
      eParams.itemId = params.commentsItemId;
      eParams.author = user.userId;
      eParams.filter = true;
      eParams.pageItemId = params.pageItemId;
      eParams.studentContentItem = params.studentContentItem;
      eParams.siteId = simplePageBean.getCurrentSiteId();
      eParams.pageId = containingPage.getPageId();
      UIInternalLink.make(branch, "commentsLink", eParams);

      // The grading stuff
      UIOutput.make(branch, "student-grade");
      UIOutput.make(branch, "gradingSpan");
      UIOutput.make(branch, "commentsUUID", user.uuid);
      UIOutput.make(
          branch, "commentPoints", (user.grade == null ? "" : String.valueOf(user.grade)));
      UIOutput.make(branch, "pointsBox")
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator
                      .getMessage("simplepage.grade-for-student")
                      .replace("{}", user.displayName)));
      UIOutput.make(
          branch,
          "maxpoints",
          " / "
              + (params.studentContentItem
                  ? commentItem.getAltPoints()
                  : commentItem.getGradebookPoints()));
      UIOutput.make(
              branch, "clickToExpand", messageLocator.getMessage("simplepage.click-to-expand"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator
                      .getMessage("simplepage.expand-for-student")
                      .replace("{}", user.displayName)));

      UIOutput.make(branch, "authorUUID", user.userId);
    }

    UIForm gradingForm = UIForm.make(tofill, "gradingForm");

    gradingForm.viewparams = new SimpleViewParameters(UVBProducer.VIEW_ID);

    UIInput idInput = UIInput.make(gradingForm, "gradingForm-id", "gradingBean.id");
    UIInput jsIdInput = UIInput.make(gradingForm, "gradingForm-jsId", "gradingBean.jsId");
    UIInput pointsInput = UIInput.make(gradingForm, "gradingForm-points", "gradingBean.points");
    UIInput typeInput = UIInput.make(gradingForm, "gradingForm-type", "gradingBean.type");
    Object sessionToken = SessionManager.getCurrentSession().getAttribute("sakai.csrf.token");
    UIInput csrfInput =
        UIInput.make(
            gradingForm,
            "csrf",
            "gradingBean.csrfToken",
            (sessionToken == null ? "" : sessionToken.toString()));

    UIInitBlock.make(
        tofill,
        "gradingForm-init",
        "initGradingForm",
        new Object[] {
          idInput, pointsInput, jsIdInput, typeInput, csrfInput, "gradingBean.results"
        });
  }