Пример #1
0
  public FriendsFeed(String id, final String ownerUserId, final String viewingUserId) {
    super(id);

    log.debug("FriendsFeed()");

    // heading
    Label heading = new Label("heading");

    if (viewingUserId.equals(ownerUserId)) {
      heading.setDefaultModel(new ResourceModel("heading.widget.my.friends"));
    } else {
      String displayName = sakaiProxy.getUserDisplayName(ownerUserId);
      heading.setDefaultModel(
          new StringResourceModel("heading.widget.view.friends", null, new Object[] {displayName}));
    }
    add(heading);

    // get our list of friends as an IDataProvider
    // the FriendDataProvider takes care of the privacy associated with the associated list
    // so what it returns will always be clean
    FriendsFeedDataProvider provider = new FriendsFeedDataProvider(ownerUserId);

    GridView<Person> dataView =
        new GridView<Person>("rows", provider) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void populateEmptyItem(Item<Person> item) {
            Link friendItem =
                new Link("friendsFeedItem") {
                  private static final long serialVersionUID = 1L;

                  public void onClick() {}
                };

            friendItem.add(
                new ProfileImageRenderer(
                    "friendPhoto",
                    null,
                    null,
                    null,
                    ProfileConstants.PROFILE_IMAGE_THUMBNAIL,
                    true));

            friendItem.add(new Label("friendName", "empty"));
            item.add(friendItem);
            friendItem.setVisible(false);
          }

          protected void populateItem(Item<Person> item) {
            final Person person = (Person) item.getDefaultModelObject();
            final String friendId = person.getUuid();

            // setup info
            String displayName = person.getDisplayName();
            boolean friend;

            // get friend status
            if (ownerUserId.equals(viewingUserId)) {
              friend = true; // viewing own list of friends so must be a friend
            } else {
              friend =
                  connectionsLogic.isUserXFriendOfUserY(
                      viewingUserId, friendId); // other person viewing, check if they are friends
            }

            // link to their profile
            Link<String> friendItem =
                new Link<String>("friendsFeedItem") {
                  private static final long serialVersionUID = 1L;

                  public void onClick() {
                    // link to own profile if link will point to self
                    if (viewingUserId.equals(friendId)) {
                      setResponsePage(new MyProfile());
                    } else {
                      setResponsePage(new ViewProfile(friendId));
                    }
                  }
                };

            /* IMAGE */
            friendItem.add(
                new ProfileImageRenderer(
                    "friendPhoto",
                    friendId,
                    person.getPreferences(),
                    person.getPrivacy(),
                    ProfileConstants.PROFILE_IMAGE_THUMBNAIL,
                    true));

            // name (will be linked also)
            Label friendLinkLabel = new Label("friendName", displayName);
            friendItem.add(friendLinkLabel);

            item.add(friendItem);
          }
        };

    dataView.setColumns(3);
    add(dataView);

    /* NUM FRIENDS LABEL (can't just use provider as it only ever returns the number in the grid */
    final int numFriends = connectionsLogic.getConnectionsForUserCount(ownerUserId);
    Label numFriendsLabel = new Label("numFriendsLabel");
    add(numFriendsLabel);

    /* VIEW ALL FRIENDS LINK */
    Link<String> viewFriendsLink =
        new Link<String>("viewFriendsLink") {
          private static final long serialVersionUID = 1L;

          public void onClick() {
            // this could come from a bookmarkablelink, but this works for now
            if (numFriends == 0) {
              setResponsePage(new MySearch());
            } else {
              // if own FriendsFeed, link to own MyFriends, otherwise link to ViewFriends
              if (sakaiProxy.isSuperUserAndProxiedToUser(ownerUserId)) {
                setResponsePage(new ViewFriends(ownerUserId));
              } else if (viewingUserId.equals(ownerUserId)) {
                setResponsePage(new MyFriends());
              } else {
                setResponsePage(new ViewFriends(ownerUserId));
              }
            }
          }
        };
    Label viewFriendsLabel = new Label("viewFriendsLabel");
    viewFriendsLink.add(viewFriendsLabel);
    add(viewFriendsLink);

    /* TESTS FOR THE ABOVE to change labels and links */
    if (numFriends == 0) {
      numFriendsLabel.setDefaultModel(new ResourceModel("text.friend.feed.num.none"));
      // numFriendsLabel.setVisible(false);
      // if own FriendsFeed, show search link, otherwise hide
      if (viewingUserId.equals(ownerUserId)) {
        viewFriendsLabel.setDefaultModel(new ResourceModel("link.friend.feed.search"));
      } else {
        viewFriendsLink.setVisible(false);
      }
    } else if (numFriends == 1) {
      numFriendsLabel.setDefaultModel(new ResourceModel("text.friend.feed.num.one"));
      viewFriendsLink.setVisible(false);
    } else {
      numFriendsLabel.setDefaultModel(
          new StringResourceModel("text.friend.feed.num.many", null, new Object[] {numFriends}));
      viewFriendsLabel.setDefaultModel(new ResourceModel("link.friend.feed.view"));
    }
  }
Пример #2
0
  public ComposeNewMessage(String id) {
    super(id);

    // current user
    final String userId = sakaiProxy.getCurrentUserId();

    // setup model
    NewMessageModel newMessage = new NewMessageModel();
    newMessage.setFrom(userId);

    // feedback for form submit action
    formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    add(formFeedback);

    // setup form
    final Form<NewMessageModel> form =
        new Form<NewMessageModel>("form", new Model<NewMessageModel>(newMessage));

    // close button
    /*
    WebMarkupContainer closeButton = new WebMarkupContainer("closeButton");
    closeButton.add(new AjaxFallbackLink<Void>("link") {
    	private static final long serialVersionUID = 1L;

    	public void onClick(AjaxRequestTarget target) {
    		if(target != null) {
    			target.prependJavascript("$('#" + thisPanel.getMarkupId() + "').slideUp();");
    			target.appendJavascript("setMainFrameHeight(window.name);");
    		}
    	}
    }.add(new ContextImage("img",new Model<String>(ProfileConstants.CLOSE_IMAGE))));
    form.add(closeButton);
    */

    // to label
    form.add(new Label("toLabel", new ResourceModel("message.to")));

    // get connections
    final List<Person> connections = connectionsLogic.getConnectionsForUser(userId);
    Collections.sort(connections);

    // list provider
    AutoCompletionChoicesProvider<Person> provider =
        new AutoCompletionChoicesProvider<Person>() {
          private static final long serialVersionUID = 1L;

          public Iterator<Person> getChoices(String input) {
            return connectionsLogic
                .getConnectionsSubsetForSearch(connections, input, true)
                .iterator();
          }
        };

    // renderer
    ObjectAutoCompleteRenderer<Person> renderer =
        new ObjectAutoCompleteRenderer<Person>() {
          private static final long serialVersionUID = 1L;

          protected String getIdValue(Person p) {
            return p.getUuid();
          }

          protected String getTextValue(Person p) {
            return p.getDisplayName();
          }
        };

    // autocompletefield builder
    ObjectAutoCompleteBuilder<Person, String> builder =
        new ObjectAutoCompleteBuilder<Person, String>(provider);
    builder.autoCompleteRenderer(renderer);
    builder.searchLinkImage(ResourceReferences.CROSS_IMG_LOCAL);
    builder.preselect();

    // autocompletefield
    final ObjectAutoCompleteField<Person, String> autocompleteField =
        builder.build("toField", new PropertyModel<String>(newMessage, "to"));
    toField = autocompleteField.getSearchTextField();
    toField.setMarkupId("messagerecipientinput");
    toField.setOutputMarkupId(true);
    toField.add(new AttributeModifier("class", true, new Model<String>("formInputField")));
    toField.setRequired(true);
    form.add(autocompleteField);

    // subject
    form.add(new Label("subjectLabel", new ResourceModel("message.subject")));
    final TextField<String> subjectField =
        new TextField<String>("subjectField", new PropertyModel<String>(newMessage, "subject"));
    subjectField.setMarkupId("messagesubjectinput");
    subjectField.setOutputMarkupId(true);
    subjectField.add(new RecipientEventBehavior("onfocus"));
    form.add(subjectField);

    // body
    form.add(new Label("messageLabel", new ResourceModel("message.message")));
    final TextArea<String> messageField =
        new TextArea<String>("messageField", new PropertyModel<String>(newMessage, "message"));
    messageField.setMarkupId("messagebodyinput");
    messageField.setOutputMarkupId(true);
    messageField.setRequired(true);
    messageField.add(new RecipientEventBehavior("onfocus"));
    form.add(messageField);

    // send button
    IndicatingAjaxButton sendButton =
        new IndicatingAjaxButton("sendButton", form) {
          private static final long serialVersionUID = 1L;

          protected void onSubmit(AjaxRequestTarget target, Form form) {

            // get the backing model
            NewMessageModel newMessage = (NewMessageModel) form.getModelObject();

            // generate the thread id
            String threadId = ProfileUtils.generateUuid();

            // save it, it will be abstracted into its proper parts and email notifications sent
            if (messagingLogic.sendNewMessage(
                newMessage.getTo(),
                newMessage.getFrom(),
                threadId,
                newMessage.getSubject(),
                newMessage.getMessage())) {

              // post event
              sakaiProxy.postEvent(
                  ProfileConstants.EVENT_MESSAGE_SENT, "/profile/" + newMessage.getTo(), true);

              // success
              formFeedback.setDefaultModel(new ResourceModel("success.message.send.ok"));
              formFeedback.add(new AttributeModifier("class", true, new Model<String>("success")));

              // target.appendJavascript("$('#" + form.getMarkupId() + "').slideUp();");
              target.appendJavaScript("setMainFrameHeight(window.name);");

              // PRFL-797 all fields when successful, to prevent multiple messages.
              // User can just click Compose message again to get a new form
              this.setEnabled(false);
              autocompleteField.setEnabled(false);
              subjectField.setEnabled(false);
              messageField.setEnabled(false);
              target.add(this);
              target.add(autocompleteField);
              target.add(subjectField);
              target.add(messageField);

            } else {
              // error
              formFeedback.setDefaultModel(new ResourceModel("error.message.send.failed"));
              formFeedback.add(
                  new AttributeModifier("class", true, new Model<String>("alertMessage")));
            }

            formFeedback.setVisible(true);
            target.add(formFeedback);
          }

          protected void onError(AjaxRequestTarget target, Form form) {

            // check which item didn't validate and update the feedback model
            if (!toField.isValid()) {
              formFeedback.setDefaultModel(new ResourceModel("error.message.required.to"));
            }
            if (!messageField.isValid()) {
              formFeedback.setDefaultModel(new ResourceModel("error.message.required.body"));
            }
            formFeedback.add(
                new AttributeModifier("class", true, new Model<String>("alertMessage")));

            target.add(formFeedback);
          }
        };
    form.add(sendButton);
    sendButton.setModel(new ResourceModel("button.message.send"));

    add(form);
  }