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.setCommentsFetched(true);
if (commentForm2Add)
owner.showAddCommentForm();
owner.showAddCommentForm(false);
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.UiField;
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.ui.Button;
import com.google.gwt.user.client.ui.Composite;
@ -62,6 +63,7 @@ public class AddCommentTemplate extends Composite {
avatarImage.setUrl(myUserInfo.getAvatarId());
submitButton.setVisible(false);
cancelButton.setVisible(false);
commentTextArea.setHeight("30px");
}
/**
* called on edit comment
@ -74,10 +76,16 @@ public class AddCommentTemplate extends Composite {
this.commentPanel = commentPanel;
isEditing = true;
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;
avatarImage.setPixelSize(30, 30);
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
commentTextArea.setText(new HTML(toEdit.getText()).getText());
commentTextArea.setText(commentText);
mainPanel.removeStyleName("comment-hidden");
mainPanel.setStyleName("single-comment");
commentTextArea.addStyleName("comment-dark-color");
@ -87,11 +95,20 @@ public class AddCommentTemplate extends Composite {
@UiFactory SuperPosedTextArea build() {
return new SuperPosedTextArea(highlighterDIV);
}
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")
void onSubmitClick(ClickEvent e) {
String userComment = commentTextArea.getText().trim();
@ -177,4 +194,26 @@ public class AddCommentTemplate extends Composite {
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
.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")
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+"?"+
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
Encoder.encode(myComment.getUserid())+"\">"+
myComment.getFullName()+"</a> " + myComment.getText());
myComment.getFullName()+"</a> " + commentToShow);
seeMore.setHTML("");
}

View File

@ -193,27 +193,13 @@ public class SuperPosedTextArea extends TextArea {
GWT.log(toReturn.toString());
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) /*-{
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();
}
}
}-*/;
public String getAreaId() {
return areaId;
}
}

View File

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

View File

@ -549,8 +549,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public Comment editComment(Comment toEdit) {
UserInfo user = getUserSettings().getUserInfo();
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
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 {
store.editComment(edited);
} catch (Exception e) {

View File

@ -4,7 +4,7 @@
<inherits name='com.google.gwt.user.User' />
<!-- 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 -->
<inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" />

View File

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