From f74c8531429f72ef6d67afe319292f86cee52cd1 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 11 Apr 2014 10:50:23 +0000 Subject: [PATCH] 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 --- .../newsfeed/client/panels/NewsFeedPanel.java | 4 +- .../client/templates/AddCommentTemplate.java | 45 +++++++++++++++++-- .../client/templates/SingleComment.java | 8 +++- .../client/templates/SuperPosedTextArea.java | 28 +++--------- .../client/templates/TweetTemplate.java | 13 +++--- .../user/newsfeed/server/NewsServiceImpl.java | 4 +- .../portlets/user/newsfeed/NewsFeed.gwt.xml | 2 +- src/main/webapp/NewsFeed.css | 14 +++--- 8 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java index 29e07a8..90a7471 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java @@ -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); } }); diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java index c58e27b..3ce5875 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java @@ -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("<","<").replaceAll(">",">"); + commentText = commentText.replaceAll("&","&"); + 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("&", "&").replaceAll("<", "<") .replaceAll(">", ">"); } + /** + * 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(); + } + } + }-*/; } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java index 8e1c4b4..763dfb1 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java @@ -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("<","<").replaceAll(">",">"); + commentToShow = commentToShow.replaceAll("&","&"); + + commentText.setHTML(""+ - myComment.getFullName()+" " + myComment.getText()); + myComment.getFullName()+" " + commentToShow); seeMore.setHTML(""); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SuperPosedTextArea.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SuperPosedTextArea.java index d892bf4..921b3ba 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SuperPosedTextArea.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SuperPosedTextArea.java @@ -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; + } + + } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java index 9c4e86b..c6cd440 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java @@ -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); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java index eb1ef93..7eb83b4 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java @@ -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) { diff --git a/src/main/resources/org/gcube/portlets/user/newsfeed/NewsFeed.gwt.xml b/src/main/resources/org/gcube/portlets/user/newsfeed/NewsFeed.gwt.xml index 61246ea..96b280d 100644 --- a/src/main/resources/org/gcube/portlets/user/newsfeed/NewsFeed.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/newsfeed/NewsFeed.gwt.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/webapp/NewsFeed.css b/src/main/webapp/NewsFeed.css index 7ac6bb8..9f5e2b5 100644 --- a/src/main/webapp/NewsFeed.css +++ b/src/main/webapp/NewsFeed.css @@ -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 {