2016-03-22 18:48:34 +01:00
|
|
|
package org.gcube.portlets.user.joinvre.client.ui;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.joinvre.client.JoinService;
|
|
|
|
import org.gcube.portlets.user.joinvre.client.JoinServiceAsync;
|
|
|
|
import org.gcube.portlets.user.joinvre.shared.VRE;
|
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
|
|
import com.github.gwtbootstrap.client.ui.HelpBlock;
|
2016-03-23 11:08:45 +01:00
|
|
|
import com.github.gwtbootstrap.client.ui.Icon;
|
2016-03-22 18:48:34 +01:00
|
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
2017-07-04 19:05:31 +02:00
|
|
|
import com.google.gwt.dom.client.Element;
|
2016-03-22 18:48:34 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
2017-07-04 19:05:31 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2016-03-22 18:48:34 +01:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
|
import com.google.gwt.user.client.Window.Location;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
2017-07-04 19:05:31 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2016-03-22 18:48:34 +01:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class AccessVREDialog extends Composite {
|
|
|
|
private final JoinServiceAsync joinService = GWT.create(JoinService.class);
|
2016-03-25 11:47:56 +01:00
|
|
|
private final static boolean IS_INVITATION = false;
|
2016-03-22 18:48:34 +01:00
|
|
|
private static AccessVREDialogUiBinder uiBinder = GWT
|
|
|
|
.create(AccessVREDialogUiBinder.class);
|
|
|
|
|
|
|
|
interface AccessVREDialogUiBinder extends UiBinder<Widget, AccessVREDialog> {
|
|
|
|
}
|
|
|
|
@UiField Modal m;
|
|
|
|
@UiField Button close;
|
|
|
|
@UiField Button confirmRequest;
|
|
|
|
@UiField HelpBlock helpBlock;
|
2017-07-04 19:05:31 +02:00
|
|
|
@UiField HelpBlock touGatewayBlock;
|
2016-03-23 11:08:45 +01:00
|
|
|
@UiField Icon loading;
|
2017-07-04 19:05:31 +02:00
|
|
|
@UiField HTML touText;
|
|
|
|
|
2016-03-22 18:48:34 +01:00
|
|
|
VRE myVRE = null;
|
2016-03-24 18:51:32 +01:00
|
|
|
public AccessVREDialog(final VRE vre) {
|
2016-03-22 18:48:34 +01:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
this.myVRE = vre;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void show() {
|
2017-07-04 19:05:31 +02:00
|
|
|
joinService.getTermsOfUse(this.myVRE.getId(), new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
m.setTitle("Ops, an error occurred please check your connection and try again");
|
|
|
|
confirmRequest.setText("Try again");
|
|
|
|
confirmRequest.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
Location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
m.show();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
if (result == null) { //no terms of use
|
|
|
|
String headerText = "Join VRE request for " + myVRE.getName();
|
|
|
|
String text = "You are about to enter " + myVRE.getName() + ", please confirm your request.";
|
|
|
|
m.setTitle(headerText);
|
|
|
|
helpBlock.setHTML(text);
|
|
|
|
touGatewayBlock.setVisible(true);
|
|
|
|
String buttonText = "Confirm Request";
|
|
|
|
confirmRequest.setText(buttonText);
|
|
|
|
}
|
|
|
|
else {// terms of use exist
|
|
|
|
String headerText = "Terms of Use for " + myVRE.getName();
|
|
|
|
String text = "By using <b>" + myVRE.getName() + "</b> VRE services, you are agreeing to these terms. Please read them carefully:";
|
|
|
|
m.setTitle(headerText);
|
|
|
|
helpBlock.setHTML(text);
|
|
|
|
String buttonText = "Accept Terms of Use";
|
|
|
|
confirmRequest.setText(buttonText);
|
|
|
|
m.addStyleName("modal-custom");
|
|
|
|
((Element)m.getElement().getChildNodes().getItem(1)).addClassName("modal-body-custom");
|
|
|
|
touText.setHTML(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
m.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-03-22 18:48:34 +01:00
|
|
|
}
|
2017-07-04 19:05:31 +02:00
|
|
|
|
2016-03-22 18:48:34 +01:00
|
|
|
@UiHandler("close")
|
|
|
|
void handleClick(ClickEvent e) {
|
|
|
|
m.hide();
|
|
|
|
}
|
|
|
|
@UiHandler("confirmRequest")
|
|
|
|
void confirm(ClickEvent e) {
|
|
|
|
helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... ");
|
2016-03-23 11:08:45 +01:00
|
|
|
loading.setVisible(true);
|
2016-08-25 15:43:58 +02:00
|
|
|
confirmRequest.setEnabled(false);
|
2016-03-25 11:47:56 +01:00
|
|
|
joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), IS_INVITATION, new AsyncCallback<Boolean>() {
|
2017-07-04 19:05:31 +02:00
|
|
|
|
2016-03-22 18:48:34 +01:00
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
Location.assign(myVRE.getFriendlyURL());
|
|
|
|
}
|
2017-07-04 19:05:31 +02:00
|
|
|
|
2016-03-22 18:48:34 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
confirmRequest.removeFromParent();
|
|
|
|
m.setTitle("An error occurred! Your request has not been sent");
|
|
|
|
helpBlock.setText("An email with the cause of the error has been sent to the support team, we'll be back to you shortly.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|