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);