2014-01-20 12:48:21 +01:00
|
|
|
package org.gcube.portlets.user.shareupdates.client.view;
|
2013-01-26 20:02:51 +01:00
|
|
|
|
2013-06-02 16:26:58 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter;
|
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
|
|
|
|
|
|
|
|
import org.gcube.portal.databook.shared.ClientFeed;
|
|
|
|
import org.gcube.portal.databook.shared.ClientFeed.ClientFeedJsonizer;
|
|
|
|
import org.gcube.portal.databook.shared.FeedType;
|
|
|
|
import org.gcube.portal.databook.shared.PrivacyLevel;
|
|
|
|
import org.gcube.portal.databook.shared.UserInfo;
|
|
|
|
import org.gcube.portlets.user.shareupdates.client.ShareUpdateService;
|
|
|
|
import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync;
|
|
|
|
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
|
2013-04-11 18:46:58 +02:00
|
|
|
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
|
2014-01-17 19:21:35 +01:00
|
|
|
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent;
|
|
|
|
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;
|
|
|
|
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressPanel;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.jsonmaker.gwt.client.Jsonizer;
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
2013-04-11 18:46:58 +02:00
|
|
|
import com.google.gwt.dom.client.Document;
|
2014-01-20 00:23:08 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Display;
|
2014-03-11 14:56:41 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
2014-01-20 00:23:08 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Visibility;
|
2013-01-26 20:02:51 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
2014-02-13 16:35:43 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2014-01-17 19:21:35 +01:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2013-01-26 20:02:51 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
2014-01-17 19:21:35 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiFactory;
|
2013-01-26 20:02:51 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
2014-01-20 00:23:08 +01:00
|
|
|
import com.google.gwt.user.client.Element;
|
2013-01-26 20:02:51 +01:00
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
2014-01-20 00:23:08 +01:00
|
|
|
import com.google.gwt.user.client.ui.FileUpload;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2013-04-11 18:46:58 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
2014-02-13 16:35:43 +01:00
|
|
|
import com.google.gwt.user.client.ui.HasAlignment;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
2013-01-26 20:02:51 +01:00
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.ListBox;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante
|
|
|
|
* @version 1.2 Nov 2012
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ShareUpdateForm extends Composite {
|
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side Greeting service.
|
|
|
|
*/
|
|
|
|
private final ShareUpdateServiceAsync shareupdateService = GWT
|
|
|
|
.create(ShareUpdateService.class);
|
|
|
|
|
|
|
|
final PageBusAdapter pageBusAdapter = new PageBusAdapter();
|
2014-03-05 00:38:20 +01:00
|
|
|
// the label for all Vres/channels
|
|
|
|
private final static String ALL_VRES = "Share with: your Virtual Research Environments";
|
|
|
|
|
2013-06-02 16:26:58 +02:00
|
|
|
protected final static String SHARE_UPDATE_TEXT = "Share an update or paste a link, use “@” to mention someone";
|
2013-01-26 20:02:51 +01:00
|
|
|
protected final static String ERROR_UPDATE_TEXT = "Looks like empty to me!";
|
2014-01-30 16:39:42 +01:00
|
|
|
public final static String NO_TEXT_FILE_SHARE = "_N0_73X7_SH4R3_";
|
2013-01-26 20:02:51 +01:00
|
|
|
private final static String LISTBOX_LEVEL = " - ";
|
2014-03-05 00:38:20 +01:00
|
|
|
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
public static final String loading = GWT.getModuleBaseURL() + "../images/avatarLoader.gif";
|
|
|
|
public static final String avatar_default = GWT.getModuleBaseURL() + "../images/Avatar_default.png";
|
2014-01-20 00:23:08 +01:00
|
|
|
public static final String attach = GWT.getModuleBaseURL() + "../images/attach.png";
|
2013-01-26 20:02:51 +01:00
|
|
|
|
2014-01-30 16:39:42 +01:00
|
|
|
/**
|
|
|
|
* needed to know where to find the (possible) uploaded file
|
|
|
|
*/
|
|
|
|
private String uploadedFilePathOnServer;
|
|
|
|
private String uploadedFileNameOnServer;
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
private HandlerManager eventBus = new HandlerManager(null);
|
2014-01-14 23:44:43 +01:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
private static ShareUpdateFormUiBinder uiBinder = GWT
|
|
|
|
.create(ShareUpdateFormUiBinder.class);
|
|
|
|
|
|
|
|
private LinkPreviewer myLinkPreviewer;
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
private UploadProgressPanel uploadProgress;
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
interface ShareUpdateFormUiBinder extends UiBinder<Widget, ShareUpdateForm> {
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ShareUpdateForm singleton;
|
|
|
|
|
|
|
|
public static ShareUpdateForm get() {
|
|
|
|
return singleton;
|
|
|
|
}
|
2013-04-11 18:46:58 +02:00
|
|
|
@UiField
|
|
|
|
HTMLPanel mainPanel;
|
2013-06-02 16:26:58 +02:00
|
|
|
@UiField
|
2014-01-20 19:35:57 +01:00
|
|
|
Placeholder preview;
|
2013-06-02 16:26:58 +02:00
|
|
|
|
|
|
|
@UiField
|
|
|
|
Button submitButton;
|
2014-01-17 19:21:35 +01:00
|
|
|
|
2014-01-14 19:02:43 +01:00
|
|
|
@UiField
|
2014-01-20 00:23:08 +01:00
|
|
|
HTML attachButton;
|
2013-06-02 16:26:58 +02:00
|
|
|
|
|
|
|
@UiField
|
|
|
|
Image avatarImage;
|
|
|
|
|
|
|
|
@UiField SuperPosedTextArea shareTextArea;
|
|
|
|
|
2014-03-05 00:38:20 +01:00
|
|
|
@UiField
|
|
|
|
ListBox privacyLevel = new ListBox(false);
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
ListBox notifyListbox = new ListBox(false);
|
2013-01-26 20:02:51 +01:00
|
|
|
|
2014-01-30 16:39:42 +01:00
|
|
|
private UserInfo myUserInfo;
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
|
2014-01-20 12:48:21 +01:00
|
|
|
private void bind() {
|
|
|
|
/**
|
|
|
|
* get the uploaded file result
|
|
|
|
*/
|
|
|
|
eventBus.addHandler(FileUploadCompleteEvent.TYPE, new FileUploadCompleteEventHandler() {
|
|
|
|
@Override
|
|
|
|
public void onUploadComplete(FileUploadCompleteEvent event) {
|
|
|
|
String absolutePathOnServer = event.getUploadedFileInfo().getAbsolutePath();
|
|
|
|
GWT.log("uploaded on Server here: " + absolutePathOnServer);
|
|
|
|
checkFile(event.getUploadedFileInfo().getFilename(), absolutePathOnServer);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
public ShareUpdateForm() {
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
singleton = this;
|
2014-01-17 19:21:35 +01:00
|
|
|
bind();
|
2013-01-26 20:02:51 +01:00
|
|
|
avatarImage.setUrl(loading);
|
|
|
|
shareTextArea.setText(SHARE_UPDATE_TEXT);
|
2014-01-20 00:23:08 +01:00
|
|
|
|
|
|
|
attachButton.getElement().getStyle().setDisplay(Display.INLINE);
|
|
|
|
attachButton.setHTML("<span style=\"padding: 5px 1px; background: url('"+attach+"') 50% 50% no-repeat;\"> </span>");
|
|
|
|
|
|
|
|
|
2013-04-11 18:46:58 +02:00
|
|
|
shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
2013-01-26 20:02:51 +01:00
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
avatarImage.setSize("60px", "60px");
|
|
|
|
avatarImage.setUrl(avatar_default);
|
|
|
|
}
|
|
|
|
|
2013-04-11 18:46:58 +02:00
|
|
|
public void onSuccess(UserSettings userSettings) {
|
|
|
|
myUserInfo = userSettings.getUserInfo();
|
|
|
|
avatarImage.getElement().getParentElement().setAttribute("href", myUserInfo.getAccountURL());
|
2013-01-26 20:02:51 +01:00
|
|
|
avatarImage.setSize("60px", "60px");
|
2013-04-11 18:46:58 +02:00
|
|
|
avatarImage.setUrl(myUserInfo.getAvatarId());
|
|
|
|
String singleVREName = "";
|
|
|
|
if (myUserInfo.getOwnVREs().size() > 1) {
|
2014-03-05 00:38:20 +01:00
|
|
|
privacyLevel.addItem(ALL_VRES, PrivacyLevel.VRES.toString());
|
2013-01-26 20:02:51 +01:00
|
|
|
for (String vreId : myUserInfo.getOwnVREs().keySet())
|
2014-03-05 00:38:20 +01:00
|
|
|
privacyLevel.addItem(LISTBOX_LEVEL + "Share with: " + myUserInfo.getOwnVREs().get(vreId), vreId);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
else if (myUserInfo.getOwnVREs().size() == 1)
|
2013-04-11 18:46:58 +02:00
|
|
|
for (String vreId : myUserInfo.getOwnVREs().keySet()) {
|
|
|
|
singleVREName = myUserInfo.getOwnVREs().get(vreId);
|
2014-03-05 00:38:20 +01:00
|
|
|
privacyLevel.addItem(LISTBOX_LEVEL + "Share with: " + singleVREName, vreId);
|
2013-04-11 18:46:58 +02:00
|
|
|
}
|
2014-01-17 19:21:35 +01:00
|
|
|
|
2013-02-02 18:41:39 +01:00
|
|
|
//privacyLevel.addItem("My Connections", PrivacyLevel.CONNECTION.toString());
|
2014-10-02 19:47:15 +02:00
|
|
|
if (myUserInfo.isAdmin())
|
2014-03-05 00:38:20 +01:00
|
|
|
privacyLevel.addItem("Share with: Everyone", PrivacyLevel.PORTAL.toString());
|
2013-04-11 18:46:58 +02:00
|
|
|
//change css if deployed in VRE scope
|
|
|
|
if (!userSettings.isInfrastructure()) {
|
|
|
|
mainPanel.addStyleName("framed");
|
2014-03-05 00:38:20 +01:00
|
|
|
notifyListbox.addItem("Share with: " + singleVREName);
|
|
|
|
notifyListbox.addItem("Share with: " + singleVREName+" + Notification to members");
|
|
|
|
notifyListbox.setVisible(true);
|
2013-04-11 18:46:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
privacyLevel.setVisible(true);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-01-20 00:23:08 +01:00
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
/** Used by UiBinder to instantiate UploadProgressView */
|
|
|
|
@UiFactory
|
|
|
|
UploadProgressPanel instatiateProgressView() {
|
|
|
|
uploadProgress = new UploadProgressPanel(eventBus);
|
|
|
|
uploadProgress.setVisible(false);
|
|
|
|
return uploadProgress;
|
|
|
|
}
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
@UiHandler("shareTextArea")
|
|
|
|
void onShareUpdateClick(ClickEvent e) {
|
|
|
|
shareTextArea.removeSampleText();
|
|
|
|
}
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
@UiHandler("attachButton")
|
|
|
|
void onAttachClick(ClickEvent e) {
|
|
|
|
if (myLinkPreviewer == null) {
|
2014-01-20 00:23:08 +01:00
|
|
|
FileUpload up = uploadProgress.initialize();
|
|
|
|
up.setVisible(false);
|
|
|
|
fileBrowse(up.getElement());
|
2014-01-21 18:43:03 +01:00
|
|
|
uploadProgress.setVisible(true);
|
2014-01-17 19:21:35 +01:00
|
|
|
} else {
|
|
|
|
Window.alert("You cannot post two files, please remove the previous one first.");
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 00:23:08 +01:00
|
|
|
/**
|
|
|
|
* this simulates the click on the hidden native GWT FileUpload Button
|
|
|
|
* @param el
|
|
|
|
*/
|
|
|
|
public static native void fileBrowse(Element el) /*-{
|
|
|
|
el.click();
|
|
|
|
}-*/;
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
@UiHandler("submitButton")
|
2014-01-21 18:43:03 +01:00
|
|
|
void onClick(ClickEvent e) {
|
|
|
|
attachButton.getElement().getStyle().setVisibility(Visibility.VISIBLE); //beacuse otherwise it looses the other properties setting
|
2013-04-17 17:29:44 +02:00
|
|
|
shareupdateService.getUserSettings(new AsyncCallback<UserSettings>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Window.alert("Ops! we encountered some problems delivering your message, server is not responding, please try again in a short while.");
|
|
|
|
}
|
|
|
|
public void onSuccess(UserSettings result) {
|
|
|
|
if (result.getUserInfo().getUsername().equals("test.user")) {
|
|
|
|
Window.alert("Your session has expired, please log out and login again");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
myUserInfo = result.getUserInfo();
|
|
|
|
String toShare = shareTextArea.getText().trim();
|
2014-01-30 16:39:42 +01:00
|
|
|
|
|
|
|
//We allow to post a file without writing nothing in the sharing textarea
|
|
|
|
if (myLinkPreviewer != null && myLinkPreviewer.isSharingFile() && (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) ) {
|
|
|
|
toShare = NO_TEXT_FILE_SHARE;
|
|
|
|
}
|
2013-04-17 17:29:44 +02:00
|
|
|
if (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) {
|
|
|
|
shareTextArea.addStyleName("error");
|
|
|
|
shareTextArea.setText(ERROR_UPDATE_TEXT);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-30 16:39:42 +01:00
|
|
|
//then you can post but you have to pass html checks now
|
|
|
|
String toPost = toShare;
|
2013-06-02 16:26:58 +02:00
|
|
|
postTweet(toPost, shareTextArea.getMentionedUsers());
|
2013-04-17 17:29:44 +02:00
|
|
|
}
|
|
|
|
});
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2014-01-17 19:21:35 +01:00
|
|
|
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param textToPost
|
|
|
|
*/
|
2013-06-02 16:26:58 +02:00
|
|
|
private void postTweet(String textToPost, ArrayList<String> mentionedUsers) {
|
|
|
|
String toShare = escapeHtml(textToPost);
|
|
|
|
if (! checkTextLength(toShare)) {
|
2013-01-26 20:02:51 +01:00
|
|
|
Window.alert("We found a single word containing more than 50 chars and it's not a link, is it meaningful?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
submitButton.setEnabled(false);
|
|
|
|
shareTextArea.setEnabled(false);
|
|
|
|
|
|
|
|
String vreId = "";
|
|
|
|
if (getPrivacyLevel() == PrivacyLevel.SINGLE_VRE) {
|
|
|
|
vreId = privacyLevel.getValue(privacyLevel.getSelectedIndex());
|
|
|
|
}
|
2014-01-30 16:39:42 +01:00
|
|
|
//preparing to send stuff
|
|
|
|
String linkTitle = "", linkDescription = "" , linkUrl = "", linkUrlThumbnail = "", linkHost = "", fileName = null, filePath = null;
|
2013-01-26 20:02:51 +01:00
|
|
|
if (myLinkPreviewer != null) {
|
|
|
|
linkTitle = myLinkPreviewer.getLinkTitle();
|
|
|
|
linkDescription = myLinkPreviewer.getLinkDescription();
|
|
|
|
linkUrl = myLinkPreviewer.getUrl();
|
|
|
|
linkUrlThumbnail = myLinkPreviewer.getUrlThumbnail();
|
2014-01-30 16:39:42 +01:00
|
|
|
linkHost = myLinkPreviewer.getHost();
|
|
|
|
if (myLinkPreviewer.isSaveCopySelected()) {
|
|
|
|
fileName = uploadedFileNameOnServer;
|
|
|
|
filePath = uploadedFilePathOnServer;
|
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2014-01-30 16:39:42 +01:00
|
|
|
LinkPreview preview2Share = new LinkPreview(linkTitle, linkDescription, linkUrl, linkHost, null);
|
2014-03-05 00:38:20 +01:00
|
|
|
boolean notifyGroup = notifyListbox.getSelectedIndex() > 0;
|
|
|
|
shareupdateService.share(toShare, FeedType.TWEET, getPrivacyLevel(), vreId, preview2Share, linkUrlThumbnail, mentionedUsers, fileName, filePath, notifyGroup, new AsyncCallback<ClientFeed>() {
|
2013-01-26 20:02:51 +01:00
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
submitButton.setEnabled(true);
|
|
|
|
shareTextArea.setEnabled(true);
|
|
|
|
shareTextArea.setText(SHARE_UPDATE_TEXT);
|
2014-03-11 14:56:41 +01:00
|
|
|
shareTextArea.cleanHighlighterDiv();
|
2013-01-26 20:02:51 +01:00
|
|
|
preview.clear();
|
|
|
|
myLinkPreviewer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(ClientFeed feed) {
|
|
|
|
submitButton.setEnabled(true);
|
|
|
|
shareTextArea.setEnabled(true);
|
|
|
|
shareTextArea.setText(SHARE_UPDATE_TEXT);
|
2014-03-11 14:56:41 +01:00
|
|
|
shareTextArea.cleanHighlighterDiv();
|
2013-01-26 20:02:51 +01:00
|
|
|
preview.clear();
|
|
|
|
myLinkPreviewer = null;
|
|
|
|
if (feed == null)
|
|
|
|
Window.alert("Ops! we encountered some problems delivering your message, please try again in a short while.");
|
|
|
|
else {
|
|
|
|
// publish a message with the refresh notification
|
|
|
|
try {
|
|
|
|
pageBusAdapter.PageBusPublish("org.gcube.portal.databook.shared", feed, (Jsonizer)GWT.create(ClientFeedJsonizer.class));
|
|
|
|
} catch (PageBusAdapterException ex) {
|
|
|
|
GWT.log(ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2014-03-11 14:56:41 +01:00
|
|
|
//needed when posting long texts otherwise it stays with the current height
|
|
|
|
shareTextArea.getElement().getStyle().setHeight(54, Unit.PX);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private PrivacyLevel getPrivacyLevel() {
|
|
|
|
String selected = privacyLevel.getValue(privacyLevel.getSelectedIndex());
|
|
|
|
if (selected.compareTo(PrivacyLevel.CONNECTION.toString()) == 0)
|
|
|
|
return PrivacyLevel.CONNECTION;
|
|
|
|
else if (selected.compareTo(PrivacyLevel.VRES.toString()) == 0)
|
|
|
|
return PrivacyLevel.VRES;
|
|
|
|
else if (selected.compareTo(PrivacyLevel.PRIVATE.toString()) == 0)
|
|
|
|
return PrivacyLevel.PRIVATE;
|
|
|
|
else if (selected.compareTo(PrivacyLevel.PORTAL.toString()) == 0)
|
|
|
|
return PrivacyLevel.PORTAL;
|
|
|
|
else
|
|
|
|
return PrivacyLevel.SINGLE_VRE;
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Escape an html string. Escaping data received from the client helps to
|
|
|
|
* prevent cross-site script vulnerabilities.
|
|
|
|
*
|
|
|
|
* @param html the html string to escape
|
|
|
|
* @return the escaped string
|
|
|
|
*/
|
|
|
|
private String escapeHtml(String html) {
|
|
|
|
if (html == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return html.replaceAll("&", "&").replaceAll("<", "<")
|
|
|
|
.replaceAll(">", ">");
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* called when pasting a possible link
|
|
|
|
* @param linkToCheck
|
|
|
|
*/
|
|
|
|
protected void checkLink(String textToCheck) {
|
|
|
|
if (myLinkPreviewer == null) {
|
|
|
|
String [] parts = textToCheck.split("\\s");
|
|
|
|
// Attempt to convert each item into an URL.
|
|
|
|
for( String item : parts ) {
|
2014-04-01 15:00:37 +02:00
|
|
|
if (item.startsWith("http") || item.startsWith("www")) {
|
2013-01-26 20:02:51 +01:00
|
|
|
preview.add(new LinkLoader());
|
2014-02-13 16:35:43 +01:00
|
|
|
submitButton.setEnabled(false);
|
2013-01-26 20:02:51 +01:00
|
|
|
//GWT.log("It's http link:" + linkToCheck);
|
|
|
|
shareupdateService.checkLink(textToCheck, new AsyncCallback<LinkPreview>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
preview.clear();
|
2014-02-13 16:35:43 +01:00
|
|
|
submitButton.setEnabled(true);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(LinkPreview result) {
|
|
|
|
preview.clear();
|
|
|
|
if (result != null)
|
2014-02-13 16:35:43 +01:00
|
|
|
addPreview(result, false);
|
|
|
|
submitButton.setEnabled(true);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Window.alert("You cannot post two links, please remove the previous one first.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
/**
|
|
|
|
* called when the file was correctly uploaded on server
|
|
|
|
* @param fileName the name of the file
|
|
|
|
* @param absolutePathOnServer the path of the file ending with its name on the server temp
|
|
|
|
*/
|
2014-01-30 16:39:42 +01:00
|
|
|
protected void checkFile(final String fileName, final String absolutePathOnServer) {
|
2014-01-17 19:21:35 +01:00
|
|
|
preview.add(new LinkLoader());
|
2014-02-13 16:35:43 +01:00
|
|
|
submitButton.setEnabled(false);
|
2014-01-17 19:21:35 +01:00
|
|
|
shareupdateService.checkUploadedFile(fileName, absolutePathOnServer, new AsyncCallback<LinkPreview>() {
|
|
|
|
public void onFailure(Throwable caught) {
|
2014-02-13 16:35:43 +01:00
|
|
|
GWT.log("Failed");
|
2014-01-17 19:21:35 +01:00
|
|
|
uploadProgress.showRegisteringResult(false);
|
|
|
|
preview.clear();
|
2014-01-20 00:23:08 +01:00
|
|
|
attachButton.getElement().getStyle().setVisibility(Visibility.VISIBLE); //beacuse otherwise it looses the other properties setting
|
2014-02-13 16:35:43 +01:00
|
|
|
submitButton.setEnabled(true);
|
|
|
|
final HorizontalPanel hp = new HorizontalPanel();
|
|
|
|
final Button close = new Button("Try Again");
|
|
|
|
final HTML reportIssue = new HTML("<a href=\"https://support.d4science.research-infrastructures.eu\" target=\"_blank\">"
|
|
|
|
+ "<span>Report the issue</span></a>");
|
|
|
|
|
|
|
|
close.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
uploadProgress.setVisible(false);
|
|
|
|
preview.remove(hp);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
hp.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE);
|
|
|
|
hp.add(close);
|
|
|
|
hp.add(reportIssue);
|
|
|
|
preview.add(hp);
|
2014-01-17 19:21:35 +01:00
|
|
|
}
|
|
|
|
|
2014-01-30 16:39:42 +01:00
|
|
|
public void onSuccess(LinkPreview result) {
|
2014-01-17 19:21:35 +01:00
|
|
|
preview.clear();
|
|
|
|
uploadProgress.setVisible(false);
|
|
|
|
if (result != null)
|
2014-01-21 18:43:03 +01:00
|
|
|
addPreview(result, true);
|
|
|
|
attachButton.getElement().getStyle().setVisibility(Visibility.HIDDEN); //beacuse otherwise it looses the other properties setting
|
2014-01-30 16:39:42 +01:00
|
|
|
uploadedFilePathOnServer = absolutePathOnServer;
|
|
|
|
uploadedFileNameOnServer = fileName;
|
2014-02-13 16:35:43 +01:00
|
|
|
submitButton.setEnabled(true);
|
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
|
|
|
* called when pasting. it tries to avoid pasting long non spaced strings
|
|
|
|
* @param linkToCheck
|
|
|
|
*/
|
|
|
|
private boolean checkTextLength(String textToCheck) {
|
|
|
|
|
|
|
|
String [] parts = textToCheck.split("\\s");
|
|
|
|
// check the length of tokens
|
|
|
|
for( String item : parts ) {
|
|
|
|
if (! item.startsWith("http")) { //url are accepted as they can be trunked
|
|
|
|
if (item.length() > 50) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* add the link preview in the view
|
|
|
|
* @param result
|
|
|
|
*/
|
2014-01-20 19:35:57 +01:00
|
|
|
private void addPreview(LinkPreview result, boolean isFilePreview) {
|
2014-01-17 19:27:48 +01:00
|
|
|
uploadProgress.setVisible(false);
|
2014-01-20 19:35:57 +01:00
|
|
|
myLinkPreviewer = new LinkPreviewer(this, result, isFilePreview);
|
2013-01-26 20:02:51 +01:00
|
|
|
preview.add(myLinkPreviewer);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected void cancelPreview() {
|
|
|
|
preview.clear();
|
|
|
|
myLinkPreviewer = null;
|
2014-01-20 00:23:08 +01:00
|
|
|
attachButton.getElement().getStyle().setVisibility(Visibility.VISIBLE); //beacuse otherwise it looses the other properties setting
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
}
|