added a comment textarea at the end of the comments of a feed, if any

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@94760 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-04-11 10:50:23 +00:00
parent aa935c0f79
commit f74c853142
8 changed files with 75 additions and 43 deletions

View File

@ -880,9 +880,9 @@ public class NewsFeedPanel extends Composite {
owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername())) )); owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername())) ));
owner.setCommentsFetched(true); owner.setCommentsFetched(true);
if (commentForm2Add) if (commentForm2Add)
owner.showAddCommentForm(); owner.showAddCommentForm(false);
owner.updateCommentsNumberCount(); owner.updateCommentsNumberCount();
owner.showAddCommentForm(); owner.showAddCommentForm(false);
} }
}); });

View File

@ -14,6 +14,7 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory; import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
@ -62,6 +63,7 @@ public class AddCommentTemplate extends Composite {
avatarImage.setUrl(myUserInfo.getAvatarId()); avatarImage.setUrl(myUserInfo.getAvatarId());
submitButton.setVisible(false); submitButton.setVisible(false);
cancelButton.setVisible(false); cancelButton.setVisible(false);
commentTextArea.setHeight("30px");
} }
/** /**
* called on edit comment * called on edit comment
@ -74,10 +76,16 @@ public class AddCommentTemplate extends Composite {
this.commentPanel = commentPanel; this.commentPanel = commentPanel;
isEditing = true; isEditing = true;
this.toEdit = toEdit; this.toEdit = toEdit;
String commentText = new HTML(toEdit.getText()).getText();
//replace the < & and >
commentText = commentText.replaceAll("&lt;","<").replaceAll("&gt;",">");
commentText = commentText.replaceAll("&amp;","&");
owner = caller; owner = caller;
avatarImage.setPixelSize(30, 30); avatarImage.setPixelSize(30, 30);
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId()); avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
commentTextArea.setText(new HTML(toEdit.getText()).getText()); commentTextArea.setText(commentText);
mainPanel.removeStyleName("comment-hidden"); mainPanel.removeStyleName("comment-hidden");
mainPanel.setStyleName("single-comment"); mainPanel.setStyleName("single-comment");
commentTextArea.addStyleName("comment-dark-color"); commentTextArea.addStyleName("comment-dark-color");
@ -87,11 +95,20 @@ public class AddCommentTemplate extends Composite {
@UiFactory SuperPosedTextArea build() { @UiFactory SuperPosedTextArea build() {
return new SuperPosedTextArea(highlighterDIV); return new SuperPosedTextArea(highlighterDIV);
} }
public void setFocus() { public void setFocus() {
//commentTextArea.setFocus(true); commentTextArea.setFocus(true);
//it needs a timer otherwise it won't work
Timer t = new Timer() {
@Override
public void run() {
setCaretPositionToBegin(commentTextArea.getAreaId());
}
};
t.schedule(200);
} }
@UiHandler("submitButton") @UiHandler("submitButton")
void onSubmitClick(ClickEvent e) { void onSubmitClick(ClickEvent e) {
String userComment = commentTextArea.getText().trim(); String userComment = commentTextArea.getText().trim();
@ -177,4 +194,26 @@ public class AddCommentTemplate extends Composite {
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;") return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
.replaceAll(">", "&gt;"); .replaceAll(">", "&gt;");
} }
/**
* this position the caret at the begin in a TextArea
* @param myAreaId the unique identifier of the textarea
*/
public static native void setCaretPositionToBegin(String myAreaId) /*-{
var elem = $doc.getElementById(myAreaId);
if(elem != null) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', 0);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(0, 0);
}
else
elem.focus();
}
}
}-*/;
} }

View File

@ -79,10 +79,16 @@ public class SingleComment extends Composite {
@UiHandler("seeMore") @UiHandler("seeMore")
void onSeeMoreClick(ClickEvent e) { void onSeeMoreClick(ClickEvent e) {
String commentToShow = myComment.getText();
//replace the < & and >
commentToShow = commentToShow.replaceAll("&lt;","<").replaceAll("&gt;",">");
commentToShow = commentToShow.replaceAll("&amp;","&");
commentText.setHTML("<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"?"+ commentText.setHTML("<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"?"+
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+ Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
Encoder.encode(myComment.getUserid())+"\">"+ Encoder.encode(myComment.getUserid())+"\">"+
myComment.getFullName()+"</a> " + myComment.getText()); myComment.getFullName()+"</a> " + commentToShow);
seeMore.setHTML(""); seeMore.setHTML("");
} }

View File

@ -193,27 +193,13 @@ public class SuperPosedTextArea extends TextArea {
GWT.log(toReturn.toString()); GWT.log(toReturn.toString());
return mentionedUsers; return mentionedUsers;
} }
/** /**
* this position the caret at the begin * return the unique identifier of this textarea, useful for getElementById JS method
* @return
*/ */
public static native void setCaretPositionToBegin(String myAreaId) /*-{ public String getAreaId() {
var elem = $doc.getElementById(myAreaId); return areaId;
if(elem != null) { }
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', 0);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(0, 0);
}
else
elem.focus();
}
}
}-*/;
} }

View File

@ -219,7 +219,7 @@ public class TweetTemplate extends Composite {
for (Comment comment : myFeed.getComments()) { for (Comment comment : myFeed.getComments()) {
addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername())))); addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))));
} }
showAddCommentForm(); showAddCommentForm(false);
} }
} }
@ -337,7 +337,7 @@ public class TweetTemplate extends Composite {
fireSeeComments(true); fireSeeComments(true);
} }
else { else {
showAddCommentForm(); showAddCommentForm(true);
} }
} }
else else
@ -362,19 +362,18 @@ public class TweetTemplate extends Composite {
} }
} }
public void showAddCommentForm() { public void showAddCommentForm(boolean focus) {
final AddCommentTemplate toAdd = new AddCommentTemplate(this, myUserInfo, eventBus); final AddCommentTemplate toAdd = new AddCommentTemplate(this, myUserInfo, eventBus);
commentsPanel.add(toAdd); commentsPanel.add(toAdd);
commentingDisabled = true; commentingDisabled = true;
final Timer t = new Timer() { final Timer t = new Timer() {
@Override @Override
public void run() { public void run() {
toAdd.setStyleName("comment-show"); toAdd.setStyleName("comment-show");
toAdd.setFocus();
} }
}; };
if (focus)
toAdd.setFocus();
t.schedule(10); t.schedule(10);
} }

View File

@ -549,8 +549,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override @Override
public Comment editComment(Comment toEdit) { public Comment editComment(Comment toEdit) {
UserInfo user = getUserSettings().getUserInfo(); UserInfo user = getUserSettings().getUserInfo();
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(), Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
new Date(), toEdit.getFeedid(), transformUrls(escapeHtml(toEdit.getText())), user.getFullName(), user.getAvatarId()); new Date(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId());
try { try {
store.editComment(edited); store.editComment(edited);
} catch (Exception e) { } catch (Exception e) {

View File

@ -4,7 +4,7 @@
<inherits name='com.google.gwt.user.User' /> <inherits name='com.google.gwt.user.User' />
<!-- To Comment out --> <!-- To Comment out -->
<!-- <set-property name="user.agent" value="safari,gecko1_8,ie9" /> --> <set-property name="user.agent" value="safari,gecko1_8,ie9" />
<!-- Other module inherits --> <!-- Other module inherits -->
<inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" /> <inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" />

View File

@ -18,7 +18,7 @@ table {
top: 0; top: 0;
cursor: text; cursor: text;
width: 460px; width: 460px;
height: 54px; height: 50px;
} }
#comment-inputContainer { #comment-inputContainer {
@ -39,7 +39,7 @@ table {
border: 1px solid transparent; border: 1px solid transparent;
width: 460px; width: 460px;
min-height: 40px; min-height: 30px;
word-wrap: break-word; /* this is very important when usere paste long links*/ word-wrap: break-word; /* this is very important when usere paste long links*/
} }
@ -59,7 +59,7 @@ table {
border: 1px solid #C3CDE7; border: 1px solid #C3CDE7;
width: 460px; width: 460px;
min-height: 40px; min-height: 30px;
} }
.highlightedUser { .highlightedUser {
@ -242,7 +242,7 @@ table {
} }
.comment-show { .comment-show {
background-color: #EDEFF4; background-color: #EFF3F5;
opacity: 1; opacity: 1;
transition: opacity .45s ease-in-out; transition: opacity .45s ease-in-out;
-moz-transition: opacity .45s ease-in-out; -moz-transition: opacity .45s ease-in-out;
@ -256,7 +256,7 @@ table {
} }
.more-comment { .more-comment {
background-color: #EDEFF4; background-color: #EFF3F5;
width: 100%; width: 100%;
text-align: center; text-align: center;
padding-top: 3px; padding-top: 3px;
@ -266,7 +266,7 @@ table {
} }
.single-comment { .single-comment {
background-color: #EDEFF4; background-color: #EFF3F5;
border-bottom-color: #FFF; border-bottom-color: #FFF;
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 1px; border-bottom-width: 1px;
@ -275,7 +275,7 @@ table {
} }
.comment-bgcolor { .comment-bgcolor {
background-color: #EDEFF4; background-color: #EFF3F5;
} }
.uiCloseButton { .uiCloseButton {