2014-11-28 15:13:31 +01:00
|
|
|
package org.gcube.portlets.user.questions.client;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2014-11-28 19:12:21 +01:00
|
|
|
import java.util.List;
|
2014-11-28 15:13:31 +01:00
|
|
|
|
|
|
|
import org.gcube.portal.databook.shared.UserInfo;
|
2016-05-06 18:12:32 +02:00
|
|
|
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
|
2014-11-28 15:13:31 +01:00
|
|
|
import org.gcube.portlets.user.questions.client.resources.Images;
|
|
|
|
import org.gcube.portlets.user.questions.client.ui.DisplayBadge;
|
2016-05-06 18:12:32 +02:00
|
|
|
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
2014-11-28 19:12:21 +01:00
|
|
|
import org.gcube.portlets.widgets.wsmail.client.forms.MailForm;
|
2014-11-28 15:13:31 +01:00
|
|
|
|
2016-05-06 18:12:32 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
2015-04-28 15:37:50 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2016-05-06 18:12:32 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Label;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
2014-11-28 15:13:31 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2014-11-28 19:12:21 +01:00
|
|
|
import com.google.gwt.core.client.RunAsyncCallback;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
import com.google.gwt.user.client.Window;
|
2016-05-06 18:12:32 +02:00
|
|
|
import com.google.gwt.user.client.Window.Location;
|
2014-11-28 15:13:31 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HasAlignment;
|
|
|
|
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
2015-04-28 15:37:50 +02:00
|
|
|
import com.google.gwt.user.client.ui.SimplePanel;
|
2014-11-28 15:13:31 +01:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
|
|
|
public class VREManagersPanel extends Composite {
|
2016-05-06 18:12:32 +02:00
|
|
|
|
2014-11-28 15:13:31 +01:00
|
|
|
private final QuestionsServiceAsync service = GWT.create(QuestionsService.class);
|
|
|
|
|
|
|
|
private Image loadingImage;
|
2014-11-28 19:12:21 +01:00
|
|
|
private Image postToImage;
|
2015-04-28 15:37:50 +02:00
|
|
|
private Button messageManagers = new Button();
|
2016-05-06 18:12:32 +02:00
|
|
|
private Button leaveVreButton = new Button("Leave Group");
|
|
|
|
private AlertBlock alertBlockOnLeave = new AlertBlock();
|
|
|
|
|
|
|
|
private static final String leaveAlertMessage = "Are you sure you want to leave this group? "
|
|
|
|
+ "By leaving this group you will no longer receive updates and lose the workspace folder related to the group.";
|
2014-11-28 15:13:31 +01:00
|
|
|
|
2016-05-06 18:12:32 +02:00
|
|
|
// main panel
|
2014-11-28 15:13:31 +01:00
|
|
|
private VerticalPanel mainPanel = new VerticalPanel();
|
2016-05-06 18:12:32 +02:00
|
|
|
|
|
|
|
// panel for Questions? Ask the managers option
|
|
|
|
private VerticalPanel askManagersOption = new VerticalPanel();
|
|
|
|
|
|
|
|
// panel for leave group option
|
|
|
|
private VerticalPanel leaveVREOption = new VerticalPanel();
|
|
|
|
|
|
|
|
// list of managers
|
2014-11-28 19:12:21 +01:00
|
|
|
private ArrayList<UserInfo> managers;
|
2016-05-06 18:12:32 +02:00
|
|
|
|
2014-11-28 15:13:31 +01:00
|
|
|
public VREManagersPanel() {
|
|
|
|
super();
|
2016-05-06 18:12:32 +02:00
|
|
|
initWidget(mainPanel);
|
|
|
|
|
2014-11-28 15:13:31 +01:00
|
|
|
Images images = GWT.create(Images.class);
|
|
|
|
loadingImage = new Image(images.membersLoader().getSafeUri());
|
2014-11-28 19:12:21 +01:00
|
|
|
postToImage = new Image(images.postToIcon().getSafeUri());
|
2016-05-06 18:12:32 +02:00
|
|
|
|
|
|
|
// add options subpanels to the main one
|
|
|
|
mainPanel.add(askManagersOption); // this is always present ...
|
|
|
|
|
|
|
|
// more options label to show the other ones (if present)
|
|
|
|
final Button showMoreOptions = new Button("Show more options ...");
|
|
|
|
showMoreOptions.setType(ButtonType.LINK);
|
|
|
|
|
|
|
|
// handler
|
|
|
|
showMoreOptions.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
|
|
|
// hide the button itself
|
|
|
|
showMoreOptions.setVisible(false);
|
|
|
|
|
|
|
|
// show other options
|
|
|
|
leaveVREOption.setVisible(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mainPanel.add(showMoreOptions);
|
|
|
|
mainPanel.add(leaveVREOption);
|
|
|
|
|
|
|
|
// hide options but askManagersOption
|
|
|
|
leaveVREOption.setVisible(false);
|
|
|
|
|
|
|
|
// show loaders for the panels
|
|
|
|
showLoader(askManagersOption);
|
|
|
|
showLoader(leaveVREOption);
|
|
|
|
|
2014-11-28 15:13:31 +01:00
|
|
|
service.getManagers(new AsyncCallback<ArrayList<UserInfo>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ArrayList<UserInfo> users) {
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.clear();
|
2014-11-28 19:12:21 +01:00
|
|
|
managers = users;
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
|
|
|
askManagersOption.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
|
|
|
askManagersOption.setStyleName("questions-frame");
|
2014-11-28 19:12:21 +01:00
|
|
|
postToImage.setStyleName("manager-post-image");
|
|
|
|
postToImage.setTitle("Message privately to the Managers");
|
2014-11-28 15:13:31 +01:00
|
|
|
if (users == null || users.isEmpty()) {
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.add(new HTML("<div class=\"frame\" style=\"font-size: 16px;\">Ops, something went wrong. Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>"));
|
2014-11-28 15:13:31 +01:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < users.size(); i++) {
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.add(new DisplayBadge(users.get(i)));
|
2014-11-28 15:13:31 +01:00
|
|
|
}
|
2015-04-28 15:37:50 +02:00
|
|
|
if (users.size() > 1)
|
|
|
|
messageManagers.setText("Message managers");
|
|
|
|
else
|
|
|
|
messageManagers.setText("Message manager");
|
2014-11-28 15:13:31 +01:00
|
|
|
}
|
2015-04-28 15:37:50 +02:00
|
|
|
SimplePanel bPanel = new SimplePanel();
|
|
|
|
bPanel.setStyleName("manager-action");
|
|
|
|
bPanel.setWidget(messageManagers);
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.add(bPanel);
|
2014-11-28 15:13:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-05-06 18:12:32 +02:00
|
|
|
askManagersOption.clear();
|
|
|
|
askManagersOption.add(new HTML("<div class=\"nofeed-message\">" +
|
2014-11-28 15:13:31 +01:00
|
|
|
"Sorry, looks like something is broken with the server connection<br> " +
|
|
|
|
"Please check your connection and try refresh this page.</div>"));
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-28 15:37:50 +02:00
|
|
|
messageManagers.addClickHandler(new ClickHandler() {
|
2014-11-28 19:12:21 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
final List<String> listToLogin = new ArrayList<String>();
|
|
|
|
for (UserInfo user : managers) {
|
|
|
|
listToLogin.add(user.getUsername());
|
|
|
|
}
|
2016-05-06 18:12:32 +02:00
|
|
|
|
2014-11-28 19:12:21 +01:00
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess() {
|
|
|
|
new MailForm(listToLogin);
|
|
|
|
}
|
|
|
|
public void onFailure(Throwable reason) {
|
|
|
|
Window.alert("Could not load this component: " + reason.getMessage());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-05-06 18:12:32 +02:00
|
|
|
|
|
|
|
service.isLeaveButtonAvailable(Location.getHref(), new AsyncCallback<Boolean>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
leaveVREOption.clear();
|
|
|
|
leaveVREOption.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
|
|
|
if(!result)
|
|
|
|
addLeaveVREButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
leaveVREOption.clear();
|
|
|
|
}
|
|
|
|
});
|
2014-11-28 15:13:31 +01:00
|
|
|
}
|
|
|
|
|
2016-05-06 18:12:32 +02:00
|
|
|
private void addLeaveVREButton(){
|
|
|
|
|
|
|
|
// add leave VRE button
|
|
|
|
leaveVreButton.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
|
|
|
// show alert block
|
|
|
|
alertBlockOnLeave.setVisible(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add Cancel and Confirm Leave buttons
|
|
|
|
Span cancel = new Span("Cancel");
|
|
|
|
Span confirmLeave = new Span("Confirm Leave");
|
|
|
|
cancel.setStyleName("cancel-leave-button");
|
|
|
|
confirmLeave.setStyleName("cancel-leave-button");
|
|
|
|
|
|
|
|
// add to main panel
|
|
|
|
alertBlockOnLeave.setHTML(leaveAlertMessage + "<br><br>");
|
|
|
|
alertBlockOnLeave.add(cancel);
|
|
|
|
alertBlockOnLeave.add(new Label(" or "));
|
|
|
|
alertBlockOnLeave.add(confirmLeave);
|
|
|
|
alertBlockOnLeave.setType(AlertType.WARNING);
|
|
|
|
alertBlockOnLeave.setHeading("WARNING!");
|
|
|
|
alertBlockOnLeave.setClose(false);
|
|
|
|
alertBlockOnLeave.setVisible(false);
|
|
|
|
leaveVREOption.add(alertBlockOnLeave);
|
|
|
|
leaveVREOption.add(leaveVreButton);
|
|
|
|
|
|
|
|
// add handlers
|
|
|
|
cancel.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
|
|
|
// just hide alertBlock
|
|
|
|
alertBlockOnLeave.setVisible(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
confirmLeave.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event){
|
|
|
|
service.removeUserFromVRE(new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
if (result != null)
|
|
|
|
Location.assign(result);
|
|
|
|
else
|
|
|
|
CheckSession.showLogoutDialog();
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Window.alert("We're sorry we couldn't reach the server, try again later ... " + caught.getMessage());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-11-28 15:13:31 +01:00
|
|
|
|
2016-05-06 18:12:32 +02:00
|
|
|
private void showLoader(VerticalPanel panel) {
|
|
|
|
panel.clear();
|
|
|
|
panel.setWidth("100%");
|
|
|
|
panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
|
|
|
panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
|
|
|
panel.add(loadingImage);
|
2014-11-28 15:13:31 +01:00
|
|
|
}
|
|
|
|
}
|