From dad9ae7b6b459ba0d2c499c22bc05a0ca9b1a8cb Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 1 Mar 2019 13:05:09 +0000 Subject: [PATCH] Feature #16205: News Feed avoid refresh page when user is commenting git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@178412 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ui/AddCommentTemplate.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java index 716a406..47b8d18 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java @@ -66,6 +66,16 @@ public class AddCommentTemplate extends Composite { cancelButton.setVisible(false); commentTextArea.setHeight("30px"); commentTextArea.setContext(owner.getVREContext()); + + // add onWindowClosing handler to alert the user who didn't share post if really wants to leave + Window.addWindowClosingHandler(new Window.ClosingHandler() { + public void onWindowClosing(Window.ClosingEvent closingEvent) { + String currentText = commentTextArea.getText(); + if(!currentText.isEmpty()){ + closingEvent.setMessage("Do you really want to leave the page?"); + } + } + }); } /** * called on edit comment @@ -93,12 +103,23 @@ public class AddCommentTemplate extends Composite { mainPanel.setStyleName("single-comment"); commentTextArea.addStyleName("comment-dark-color"); submitButton.setText("Edit"); + + // add onWindowClosing handler to alert the user who didn't share post if really wants to leave + Window.addWindowClosingHandler(new Window.ClosingHandler() { + public void onWindowClosing(Window.ClosingEvent closingEvent) { + String currentText = commentTextArea.getText(); + if(!currentText.isEmpty()){ + closingEvent.setMessage("Do you really want to leave the page?"); + } + } + }); } /** Used by AddCommentTemplate to instantiate SuperPosedTextArea */ @UiFactory SuperPosedTextArea build() { return new SuperPosedTextArea(highlighterDIV); } + public void setFocus() { commentTextArea.setFocus(true); submitButton.setVisible(true);