2013-01-31 20:23:36 +01:00
|
|
|
package org.gcube.portlets.user.notifications.client.view;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2013-02-01 00:29:10 +01:00
|
|
|
import java.util.HashMap;
|
2013-06-05 18:45:10 +02:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.TreeMap;
|
2013-01-31 20:23:36 +01:00
|
|
|
|
2013-06-07 17:42:36 +02:00
|
|
|
import org.gcube.portal.databook.shared.NotificationChannelType;
|
|
|
|
import org.gcube.portal.databook.shared.NotificationType;
|
2013-01-31 20:23:36 +01:00
|
|
|
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
|
2013-02-01 00:29:10 +01:00
|
|
|
import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync;
|
2013-06-05 18:45:10 +02:00
|
|
|
import org.gcube.portlets.user.notifications.client.view.templates.CategoryWrapper;
|
|
|
|
import org.gcube.portlets.user.notifications.client.view.templates.NotificationPreferenceView;
|
|
|
|
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
|
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
|
2013-02-01 00:29:10 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2013-06-07 17:42:36 +02:00
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
2013-02-01 00:29:10 +01:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2013-06-05 18:45:10 +02:00
|
|
|
import com.google.gwt.user.client.DOM;
|
|
|
|
import com.google.gwt.user.client.Timer;
|
|
|
|
import com.google.gwt.user.client.Window;
|
2013-06-07 17:42:36 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2013-01-31 20:23:36 +01:00
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.CheckBox;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
2013-02-01 00:29:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.HasAlignment;
|
2013-01-31 20:23:36 +01:00
|
|
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
2013-02-01 00:29:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
2013-01-31 20:23:36 +01:00
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
2013-02-01 00:29:10 +01:00
|
|
|
import com.google.gwt.user.client.ui.Image;
|
2013-06-05 18:45:10 +02:00
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
2013-01-31 20:23:36 +01:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2013-06-05 18:45:10 +02:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
|
2013-02-01 00:49:12 +01:00
|
|
|
/**
|
|
|
|
* @author Massimiliano Assante ISTI-CNR
|
|
|
|
*
|
|
|
|
*/
|
2013-06-10 18:39:29 +02:00
|
|
|
public class NotificationSettingsDialog extends GCubeDialog {
|
2013-01-31 20:23:36 +01:00
|
|
|
|
2013-06-06 18:53:28 +02:00
|
|
|
private VerticalPanel mainPanel = new VerticalPanel();
|
2013-01-31 20:23:36 +01:00
|
|
|
private VerticalPanel container = new VerticalPanel();
|
|
|
|
private HorizontalPanel buttonsContainerPanel = new HorizontalPanel();
|
|
|
|
private HorizontalPanel buttonsPanel = new HorizontalPanel();
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-02-01 00:29:10 +01:00
|
|
|
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif";
|
|
|
|
public static final String mailSentOK = GWT.getModuleBaseURL() + "../images/yes.png";
|
|
|
|
public static final String mailSentNOK = GWT.getModuleBaseURL() + "../images/warning_blue.png";
|
2013-06-07 17:42:36 +02:00
|
|
|
|
|
|
|
ArrayList<CategoryWrapper> myCategories = new ArrayList<CategoryWrapper>();
|
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
private Button cancel = new Button("Cancel");
|
|
|
|
private Button save = new Button("Save");
|
2013-06-07 17:42:36 +02:00
|
|
|
|
|
|
|
public NotificationSettingsDialog(LinkedHashMap<String, ArrayList<NotificationPreference>> preferences, final NotificationsServiceAsync notificationService) {
|
2013-01-31 20:23:36 +01:00
|
|
|
super();
|
2013-06-05 18:45:10 +02:00
|
|
|
ScrollPanel scroller = new ScrollPanel();
|
2013-06-06 18:53:28 +02:00
|
|
|
scroller.setWidth("890px");
|
2013-06-05 18:45:10 +02:00
|
|
|
scroller.setHeight("500px");
|
2013-01-31 20:23:36 +01:00
|
|
|
buttonsPanel.setWidth("100%");
|
|
|
|
buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
container.setStyleName("user-notification");
|
2013-06-06 18:53:28 +02:00
|
|
|
container.setWidth("850px");
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-06-05 18:45:10 +02:00
|
|
|
for (String category : preferences.keySet()) {
|
2013-06-07 17:42:36 +02:00
|
|
|
CategoryWrapper cat = new CategoryWrapper(category, preferences.get(category));
|
|
|
|
container.add(cat);
|
|
|
|
myCategories.add(cat);
|
2013-06-05 18:45:10 +02:00
|
|
|
}
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
buttonsContainerPanel.add(cancel);
|
|
|
|
buttonsContainerPanel.add(save);
|
|
|
|
buttonsPanel.add(buttonsContainerPanel);
|
2013-06-06 18:53:28 +02:00
|
|
|
//container.add(buttonsPanel);
|
2013-06-05 18:45:10 +02:00
|
|
|
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-01-31 20:23:36 +01:00
|
|
|
setText("Notification Settings");
|
2013-06-05 18:45:10 +02:00
|
|
|
scroller.add(container);
|
2013-06-06 18:53:28 +02:00
|
|
|
mainPanel.add(scroller);
|
|
|
|
mainPanel.add(buttonsPanel);
|
|
|
|
setWidget(mainPanel);
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-06-06 18:53:28 +02:00
|
|
|
save.addClickHandler(new ClickHandler() {
|
2013-06-05 18:45:10 +02:00
|
|
|
@Override
|
2013-06-06 18:53:28 +02:00
|
|
|
public void onClick(ClickEvent event) {
|
2013-06-07 17:42:36 +02:00
|
|
|
HashMap<NotificationType, NotificationChannelType[]> toStore = new HashMap<NotificationType, NotificationChannelType[]>();
|
|
|
|
for (CategoryWrapper cat : myCategories) {
|
|
|
|
for (NotificationType notType : cat.getSelectedChannels().keySet()) {
|
|
|
|
toStore.put(notType, cat.getSelectedChannels().get(notType));
|
|
|
|
//GWT.log(""+notType + " - " + cat.getSelectedChannels().get(notType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notificationService.setUserNotificationPreferences(toStore, new AsyncCallback<Boolean>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
showDeliveryResult(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
showDeliveryResult(false);
|
|
|
|
}
|
|
|
|
});
|
2013-02-01 00:29:10 +01:00
|
|
|
}
|
2013-06-06 18:53:28 +02:00
|
|
|
});
|
2013-06-07 17:42:36 +02:00
|
|
|
|
|
|
|
cancel.addClickHandler(new ClickHandler() {
|
2013-02-01 00:29:10 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-02-01 00:29:10 +01:00
|
|
|
}
|
2013-06-07 17:42:36 +02:00
|
|
|
|
2013-02-01 00:29:10 +01:00
|
|
|
private void showDeliveryResult(boolean success) {
|
2013-06-07 17:42:36 +02:00
|
|
|
mainPanel.clear();
|
|
|
|
mainPanel.setWidth("890px");
|
|
|
|
mainPanel.setHeight("500px");
|
|
|
|
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
|
|
|
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
2013-02-01 00:29:10 +01:00
|
|
|
if (success) {
|
|
|
|
setText("Notifications Settings Saved");
|
2013-07-12 15:34:05 +02:00
|
|
|
mainPanel.add(new HTML("<span style=\"font-size: 24px;\">Notifications Settings correctly saved.</span>"));
|
2013-06-07 17:42:36 +02:00
|
|
|
mainPanel.add(new Image(mailSentOK));
|
2013-02-01 00:29:10 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setText("Notifications Settings Saving Error");
|
2013-06-07 17:42:36 +02:00
|
|
|
mainPanel.add(new Image(mailSentNOK));
|
|
|
|
mainPanel.add(new HTML("There were problems contacting the server, please try again in a short while."));
|
2013-02-01 00:29:10 +01:00
|
|
|
Button close = new Button("Close");
|
|
|
|
close.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Button close = new Button("Close");
|
2013-07-12 15:34:05 +02:00
|
|
|
close.setSize("150px", "40px");
|
|
|
|
close.getElement().getStyle().setFontSize(16, Unit.PX);
|
2013-02-01 00:29:10 +01:00
|
|
|
close.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
2013-06-07 17:42:36 +02:00
|
|
|
mainPanel.add(close);
|
2013-01-31 20:23:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|