2014-04-11 13:02:15 +02:00
|
|
|
package org.gcube.portlets.user.newsfeed.client.ui;
|
2013-04-04 15:41:17 +02:00
|
|
|
|
2016-04-06 16:35:20 +02:00
|
|
|
import org.gcube.common.portal.GCubePortalConstants;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
2013-04-04 15:41:17 +02:00
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
2013-07-18 19:01:36 +02:00
|
|
|
import org.gcube.portal.databook.client.util.Encoder;
|
2013-04-04 15:41:17 +02:00
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
2016-04-06 16:35:20 +02:00
|
|
|
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
|
2013-04-04 15:41:17 +02:00
|
|
|
import org.gcube.portlets.user.newsfeed.client.event.DeleteCommentEvent;
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.MouseOutEvent;
|
|
|
|
import com.google.gwt.event.dom.client.MouseOverEvent;
|
|
|
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
2014-02-14 15:11:09 +01:00
|
|
|
import com.google.gwt.user.client.Event;
|
2016-04-06 16:35:20 +02:00
|
|
|
import com.google.gwt.user.client.Window.Location;
|
2013-04-04 15:41:17 +02:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class SingleComment extends Composite {
|
|
|
|
|
|
|
|
private static SingleCommentUiBinder uiBinder = GWT
|
|
|
|
.create(SingleCommentUiBinder.class);
|
|
|
|
|
|
|
|
interface SingleCommentUiBinder extends UiBinder<Widget, SingleComment> {
|
|
|
|
}
|
2015-10-12 16:33:04 +02:00
|
|
|
private static final int MAX_SHOWTEXT_LENGTH = 450;
|
2013-04-04 15:41:17 +02:00
|
|
|
|
|
|
|
private boolean isUsers = false;
|
|
|
|
private TweetTemplate owner;
|
|
|
|
private String myCommentid;
|
|
|
|
private Comment myComment;
|
|
|
|
|
|
|
|
@UiField HTMLPanel mainPanel;
|
|
|
|
@UiField Image avatarImage;
|
2014-04-13 12:07:10 +02:00
|
|
|
@UiField AvatarReplacement4Comments avatarReplacement;
|
2013-04-04 15:41:17 +02:00
|
|
|
@UiField HTML commentText;
|
|
|
|
@UiField HTML timeArea;
|
|
|
|
@UiField HTML closeImage;
|
|
|
|
@UiField HTML editImage;
|
|
|
|
@UiField HTML seeMore;
|
|
|
|
|
|
|
|
public SingleComment(Comment toShow, TweetTemplate owner, boolean isUsers) {
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2014-02-14 15:11:09 +01:00
|
|
|
sinkEvents(Event.ONPASTE);
|
2013-04-04 15:41:17 +02:00
|
|
|
this.owner = owner;
|
|
|
|
this.isUsers = isUsers;
|
|
|
|
this.myComment = toShow;
|
|
|
|
myCommentid = toShow.getKey();
|
|
|
|
avatarImage.setPixelSize(30, 30);
|
|
|
|
avatarImage.setUrl(toShow.getThumbnailURL());
|
|
|
|
|
2014-04-13 12:07:10 +02:00
|
|
|
//check if the user has his own avatar
|
|
|
|
if (toShow.getThumbnailURL().endsWith("img_id=0") || !toShow.getThumbnailURL().contains("?")) { //it means no avatar is set
|
|
|
|
avatarImage.setVisible(false);
|
|
|
|
String f = "A";
|
|
|
|
String s = "Z";
|
|
|
|
if (toShow.getFullName() != null) {
|
|
|
|
String[] parts = toShow.getFullName().split("\\s");
|
|
|
|
if (parts.length > 0) {
|
|
|
|
f = parts[0].toUpperCase();
|
|
|
|
s = parts[parts.length-1].toUpperCase();
|
|
|
|
} else {
|
|
|
|
f = toShow.getFullName().substring(0,1);
|
|
|
|
s = toShow.getFullName().substring(1,2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
avatarReplacement.setInitials(toShow.getUserid(), f, s);
|
|
|
|
avatarReplacement.setVisible(true);
|
|
|
|
}
|
|
|
|
|
2013-04-04 15:41:17 +02:00
|
|
|
String commentToShow = toShow.getText();
|
2014-04-10 17:45:50 +02:00
|
|
|
|
|
|
|
//replace the < & and >
|
|
|
|
commentToShow = commentToShow.replaceAll("<","<").replaceAll(">",">");
|
|
|
|
commentToShow = commentToShow.replaceAll("&","&");
|
|
|
|
|
2015-10-12 16:33:04 +02:00
|
|
|
|
|
|
|
|
2013-04-04 15:41:17 +02:00
|
|
|
if (commentToShow.length() > MAX_SHOWTEXT_LENGTH) {
|
2015-10-12 16:33:04 +02:00
|
|
|
final int TEXT_TO_SHOW_LENGHT = (commentToShow.length() < 700) ? (commentToShow.length() - (commentToShow.length() / 3)) : 700;
|
|
|
|
commentToShow = commentToShow.substring(0, TEXT_TO_SHOW_LENGHT) + "...";
|
2013-04-04 15:41:17 +02:00
|
|
|
seeMore.setHTML("<a class=\"seemore\"> See More </a>");
|
|
|
|
}
|
2016-04-06 16:35:20 +02:00
|
|
|
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + ClientScopeHelper.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
|
|
|
|
|
|
|
commentText.setHTML("<a class=\"link\" href=\"" + profilePageURL + "?"+
|
2013-07-18 19:01:36 +02:00
|
|
|
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
|
|
|
Encoder.encode(toShow.getUserid())+"\">"+toShow.getFullName()+
|
|
|
|
"</a> " + commentToShow);
|
2015-12-11 14:16:21 +01:00
|
|
|
if(toShow.isEdit())
|
|
|
|
timeArea.setHTML(DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime()) +
|
|
|
|
" (Last edit on " + DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getLastEditTime()) + ")");
|
|
|
|
else
|
2013-04-04 15:41:17 +02:00
|
|
|
timeArea.setHTML(DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime()));
|
|
|
|
if (isUsers) {
|
|
|
|
closeImage.setStyleName("closeImage");
|
|
|
|
closeImage.setTitle("Delete");
|
|
|
|
editImage.setStyleName("editImage");
|
|
|
|
editImage.setTitle("Edit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("seeMore")
|
|
|
|
void onSeeMoreClick(ClickEvent e) {
|
2014-04-11 12:50:23 +02:00
|
|
|
String commentToShow = myComment.getText();
|
|
|
|
//replace the < & and >
|
|
|
|
commentToShow = commentToShow.replaceAll("<","<").replaceAll(">",">");
|
|
|
|
commentToShow = commentToShow.replaceAll("&","&");
|
|
|
|
|
2016-04-06 16:35:20 +02:00
|
|
|
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + ClientScopeHelper.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
|
|
|
|
|
|
|
commentText.setHTML("<a class=\"link\" href=\"" + profilePageURL + "?"+
|
2013-07-18 19:01:36 +02:00
|
|
|
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
|
|
|
Encoder.encode(myComment.getUserid())+"\">"+
|
2014-04-11 12:50:23 +02:00
|
|
|
myComment.getFullName()+"</a> " + commentToShow);
|
2013-04-04 15:41:17 +02:00
|
|
|
seeMore.setHTML("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@UiHandler("closeImage")
|
|
|
|
void onDeleteCommentClick(ClickEvent e) {
|
|
|
|
if (isUsers)
|
|
|
|
owner.getEventBus().fireEvent(new DeleteCommentEvent(owner, myCommentid));
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("editImage")
|
|
|
|
void onEditCommentClick(ClickEvent e) {
|
|
|
|
if (isUsers) {
|
|
|
|
AddCommentTemplate addComm = new AddCommentTemplate(owner, myComment, mainPanel);
|
|
|
|
mainPanel.getElement().setInnerHTML("");
|
|
|
|
mainPanel.add(addComm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@UiHandler("commentText")
|
|
|
|
public void onHover(MouseOverEvent event) {
|
|
|
|
if (isUsers) {
|
|
|
|
closeImage.addStyleName("uiCloseButton");
|
|
|
|
editImage.addStyleName("uiEditButton");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiHandler("commentText")
|
|
|
|
public void onHover(MouseOutEvent event) {
|
|
|
|
if (isUsers) {
|
|
|
|
closeImage.removeStyleName("uiCloseButton");
|
|
|
|
editImage.removeStyleName("uiEditButton");
|
|
|
|
}
|
|
|
|
}
|
2015-12-11 14:16:21 +01:00
|
|
|
|
|
|
|
public String getCommentKey() {
|
|
|
|
return myCommentid;
|
|
|
|
}
|
2014-04-10 17:45:50 +02:00
|
|
|
|
|
|
|
|
2013-04-04 15:41:17 +02:00
|
|
|
}
|