#1756 implementation complete, it Rocks!

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@76891 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-06-07 15:42:36 +00:00
parent 4ba8a60061
commit fc4de390e0
14 changed files with 344 additions and 107 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/notifications-0.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/notifications-0.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/notifications-0.2.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/notifications-0.3.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,6 +1,6 @@
#Thu Apr 18 12:31:11 CEST 2013 #Fri Jun 07 17:40:05 CEST 2013
eclipse.preferences.version=1 eclipse.preferences.version=1
jarsExcludedFromWebInfLib= jarsExcludedFromWebInfLib=
lastWarOutDir=/Users/massi/Documents/workspace/notifications/target/notifications-0.2.0-SNAPSHOT lastWarOutDir=/Users/massi/Documents/workspace/notifications/target/notifications-0.3.0-SNAPSHOT
warSrcDir=src/main/webapp warSrcDir=src/main/webapp
warSrcDirIsOutput=false warSrcDirIsOutput=false

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>notifications</artifactId> <artifactId>notifications</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>0.2.0-SNAPSHOT</version> <version>0.3.0-SNAPSHOT</version>
<name>gCube Notifications Portlet</name> <name>gCube Notifications Portlet</name>
<properties> <properties>

View File

@ -6,6 +6,8 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync; import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync;
import org.gcube.portlets.user.notifications.client.view.templates.CategoryWrapper; import org.gcube.portlets.user.notifications.client.view.templates.CategoryWrapper;
@ -14,11 +16,13 @@ import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window; 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.Button;
import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
@ -37,85 +41,99 @@ import com.google.gwt.user.client.ui.Widget;
* @author Massimiliano Assante ISTI-CNR * @author Massimiliano Assante ISTI-CNR
* *
*/ */
public class NotificationSettings extends GCubeDialog { public class NotificationSettingsDialog extends GCubeDialog {
private VerticalPanel mainPanel = new VerticalPanel(); private VerticalPanel mainPanel = new VerticalPanel();
private VerticalPanel container = new VerticalPanel(); private VerticalPanel container = new VerticalPanel();
private HorizontalPanel buttonsContainerPanel = new HorizontalPanel(); private HorizontalPanel buttonsContainerPanel = new HorizontalPanel();
private HorizontalPanel buttonsPanel = new HorizontalPanel(); private HorizontalPanel buttonsPanel = new HorizontalPanel();
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif"; 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 mailSentOK = GWT.getModuleBaseURL() + "../images/yes.png";
public static final String mailSentNOK = GWT.getModuleBaseURL() + "../images/warning_blue.png"; public static final String mailSentNOK = GWT.getModuleBaseURL() + "../images/warning_blue.png";
ArrayList<CategoryWrapper> myCategories = new ArrayList<CategoryWrapper>();
private Button cancel = new Button("Cancel"); private Button cancel = new Button("Cancel");
private Button save = new Button("Save"); private Button save = new Button("Save");
private LinkedHashMap<String, ArrayList<NotificationPreference>> preferences; public NotificationSettingsDialog(LinkedHashMap<String, ArrayList<NotificationPreference>> preferences, final NotificationsServiceAsync notificationService) {
public NotificationSettings(LinkedHashMap<String, ArrayList<NotificationPreference>> preferences, final NotificationsServiceAsync notificationService) {
super(); super();
ScrollPanel scroller = new ScrollPanel(); ScrollPanel scroller = new ScrollPanel();
scroller.setWidth("890px"); scroller.setWidth("890px");
scroller.setHeight("500px"); scroller.setHeight("500px");
this.preferences = preferences;
buttonsPanel.setWidth("100%"); buttonsPanel.setWidth("100%");
buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
container.setStyleName("user-notification"); container.setStyleName("user-notification");
container.setWidth("850px"); container.setWidth("850px");
for (String category : preferences.keySet()) { for (String category : preferences.keySet()) {
container.add(new CategoryWrapper(category)); CategoryWrapper cat = new CategoryWrapper(category, preferences.get(category));
for (NotificationPreference pref : preferences.get(category)) { container.add(cat);
container.add(new NotificationPreferenceView(pref)); myCategories.add(cat);
}
} }
buttonsContainerPanel.add(cancel); buttonsContainerPanel.add(cancel);
buttonsContainerPanel.add(save); buttonsContainerPanel.add(save);
buttonsPanel.add(buttonsContainerPanel); buttonsPanel.add(buttonsContainerPanel);
//container.add(buttonsPanel); //container.add(buttonsPanel);
setText("Notification Settings"); setText("Notification Settings");
scroller.add(container); scroller.add(container);
mainPanel.add(scroller); mainPanel.add(scroller);
mainPanel.add(buttonsPanel); mainPanel.add(buttonsPanel);
setWidget(mainPanel); setWidget(mainPanel);
save.addClickHandler(new ClickHandler() { save.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
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);
}
});
} }
}); });
cancel.addClickHandler(new ClickHandler() { cancel.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
hide(); hide();
} }
}); });
} }
private void showDeliveryResult(boolean success) { private void showDeliveryResult(boolean success) {
container.clear(); mainPanel.clear();
container.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); mainPanel.setWidth("890px");
container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); mainPanel.setHeight("500px");
mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
if (success) { if (success) {
setText("Notifications Settings Saved"); setText("Notifications Settings Saved");
container.add(new Image(mailSentOK)); mainPanel.add(new HTML("<span style=\"font-size: 28px;\">Notifications Settings correctly saved.</span>"));
mainPanel.add(new Image(mailSentOK));
} }
else { else {
setText("Notifications Settings Saving Error"); setText("Notifications Settings Saving Error");
container.add(new Image(mailSentNOK)); mainPanel.add(new Image(mailSentNOK));
container.add(new HTML("There were problems contacting the server, please try again in a short while.")); mainPanel.add(new HTML("There were problems contacting the server, please try again in a short while."));
Button close = new Button("Close"); Button close = new Button("Close");
close.addClickHandler(new ClickHandler() { close.addClickHandler(new ClickHandler() {
@Override @Override
@ -125,13 +143,15 @@ public class NotificationSettings extends GCubeDialog {
}); });
} }
Button close = new Button("Close"); Button close = new Button("Close");
close.setSize("200px", "70px");
close.getElement().getStyle().setFontSize(24, Unit.PX);
close.addClickHandler(new ClickHandler() { close.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
hide(); hide();
} }
}); });
container.add(close); mainPanel.add(close);
} }
} }

View File

@ -19,6 +19,8 @@ import org.gcube.portlets.user.notifications.client.view.templates.SingleNotific
import org.gcube.portlets.user.notifications.shared.NotificationPreference; import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
@ -100,7 +102,7 @@ public class NotificationsPanel extends Composite {
@Override @Override
public void onSuccess(LinkedHashMap<String, ArrayList<NotificationPreference>> result) { public void onSuccess(LinkedHashMap<String, ArrayList<NotificationPreference>> result) {
NotificationSettings dlg = new NotificationSettings(result, notificationService); NotificationSettingsDialog dlg = new NotificationSettingsDialog(result, notificationService);
dlg.center(); dlg.center();
dlg.show(); dlg.show();
showSettingsLoader(false); showSettingsLoader(false);
@ -173,10 +175,13 @@ public class NotificationsPanel extends Composite {
private void showSettingsLoader(boolean show) { private void showSettingsLoader(boolean show) {
if (show) { if (show) {
loadingPanel.setWidth("100%"); loadingPanel.setWidth("100%");
loadingPanel.getElement().getStyle().setPosition(Position.ABSOLUTE);
loadingPanel.getElement().getStyle().setTop(mainPanel.getAbsoluteTop()+200, Unit.PX);
loadingPanel.getElement().getStyle().setLeft(mainPanel.getAbsoluteLeft(), Unit.PX);
loadingPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); loadingPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
loadingPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); loadingPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
loadingPanel.add(loadingImage); loadingPanel.add(loadingImage);
mainPanel.insert(loadingPanel, 0); mainPanel.add(loadingPanel);
} else } else
mainPanel.remove(loadingPanel); mainPanel.remove(loadingPanel);
} }

View File

@ -1,10 +1,26 @@
package org.gcube.portlets.user.notifications.client.view.templates; package org.gcube.portlets.user.notifications.client.view.templates;
import static com.google.gwt.query.client.GQuery.$;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.user.gcubewidgets.client.switchbutton.SwitchButton;
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/** /**
@ -18,12 +34,96 @@ public class CategoryWrapper extends Composite {
interface CategoryWrapperUiBinder extends UiBinder<Widget, CategoryWrapper> { interface CategoryWrapperUiBinder extends UiBinder<Widget, CategoryWrapper> {
} }
@UiField HTML categoryLabel;
public CategoryWrapper(String catName) {
initWidget(uiBinder.createAndBindUi(this));
categoryLabel.setHTML(catName);
}
@UiField Span categoryLabel;
@UiField SwitchButton switchButton;
@UiField CheckBox portalCheckbox;
@UiField CheckBox emailCheckbox;
@UiField VerticalPanel categoryPanel;
ArrayList<NotificationPreferenceView> myPreferences = new ArrayList<NotificationPreferenceView>();
public CategoryWrapper(String catName, ArrayList<NotificationPreference> preferences) {
initWidget(uiBinder.createAndBindUi(this));
categoryLabel.setText(catName);
//set the view depending on the model
boolean atLeastOnePreferenceOn = false;
for (NotificationPreference pref : preferences) {
NotificationPreferenceView toAdd = new NotificationPreferenceView(pref);
categoryPanel.add(toAdd);
myPreferences.add(toAdd);
if (pref.getSelectedChannels()[0] != null && !atLeastOnePreferenceOn) { //if none were selected you get an array of size 1 having null
atLeastOnePreferenceOn = true;
}
}
if (!atLeastOnePreferenceOn)
setOff();
else
switchButton.setValue(true);
switchButton.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue()) {
for (int i = categoryPanel.getWidgetCount()-1; i >= 0; i--) {
$(categoryPanel.getWidget(i)).slideDown(300);
$(portalCheckbox).fadeIn(300);
$(emailCheckbox).fadeIn(300);
}
} else {
for (int i = categoryPanel.getWidgetCount()-1; i >= 0; i--) {
$(categoryPanel.getWidget(i)).slideUp(300);
$(portalCheckbox).fadeOut(300);
$(emailCheckbox).fadeOut(300);
}
}
}
});
emailCheckbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
for (NotificationPreferenceView notPref : myPreferences) {
notPref.setEmailPrefValue(event.getValue());
}
}
});
portalCheckbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
for (NotificationPreferenceView notPref : myPreferences) {
notPref.setPortalPrefValue(event.getValue());
}
}
});
}
public void setOff() {
for (int i = categoryPanel.getWidgetCount()-1; i >= 0; i--) {
$(categoryPanel.getWidget(i)).slideUp(0);
$(portalCheckbox).fadeOut(50);
$(emailCheckbox).fadeOut(50);
}
switchButton.setValue(false);
}
/**
* @return the selected notification channels in the view
*/
public HashMap<NotificationType, NotificationChannelType[]> getSelectedChannels() {
HashMap<NotificationType, NotificationChannelType[]> toReturn = new HashMap<NotificationType, NotificationChannelType[]>();
if (switchButton.getValue()) {
for (NotificationPreferenceView notPref : myPreferences)
if (notPref.getSelectedChannels() != null && notPref.getSelectedChannels().length > 0)
toReturn.put(notPref.getNotificationType(), notPref.getSelectedChannels());
else
toReturn.put(notPref.getNotificationType(), new NotificationChannelType[0]); //none were selected
}
else { //all OFF
for (NotificationPreferenceView notPref : myPreferences)
toReturn.put(notPref.getNotificationType(), new NotificationChannelType[0]);
}
return toReturn;
}
} }

View File

@ -1,7 +1,18 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:w="urn:import:org.gcube.portlets.user.gcubewidgets.client.switchbutton"
xmlns:e="urn:import:org.gcube.portlets.user.gcubewidgets.client.elements"
xmlns:g="urn:import:com.google.gwt.user.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel styleName="day-wrapper"> <g:HTMLPanel>
<g:HTML ui:field="categoryLabel" styleName="day-label"/> <div class="day-wrapper">
<e:Span styleName="day-label" ui:field="categoryLabel" />
<div class="floatingRight">
<g:CheckBox ui:field="portalCheckbox">Portal</g:CheckBox>
<g:CheckBox ui:field="emailCheckbox">Email</g:CheckBox>
<w:SwitchButton ui:field="switchButton" styleName="floatingRight paddingLeft" />
</div>
</div>
<g:VerticalPanel ui:field="categoryPanel"></g:VerticalPanel>
</g:HTMLPanel> </g:HTMLPanel>
</ui:UiBinder> </ui:UiBinder>

View File

@ -1,5 +1,9 @@
package org.gcube.portlets.user.notifications.client.view.templates; package org.gcube.portlets.user.notifications.client.view.templates;
import java.util.ArrayList;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.gcubewidgets.client.elements.Span; import org.gcube.portlets.user.gcubewidgets.client.elements.Span;
import org.gcube.portlets.user.gcubewidgets.client.switchbutton.SwitchButton; import org.gcube.portlets.user.gcubewidgets.client.switchbutton.SwitchButton;
import org.gcube.portlets.user.notifications.shared.NotificationPreference; import org.gcube.portlets.user.notifications.shared.NotificationPreference;
@ -11,6 +15,7 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import static com.google.gwt.query.client.GQuery.*; import static com.google.gwt.query.client.GQuery.*;
@ -31,32 +36,94 @@ public class NotificationPreferenceView extends Composite {
@UiField CheckBox portalCheckbox; @UiField CheckBox portalCheckbox;
@UiField CheckBox emailCheckbox; @UiField CheckBox emailCheckbox;
@UiField SwitchButton switchButton; @UiField SwitchButton switchButton;
NotificationPreference myPreference;
public NotificationPreferenceView(NotificationPreference toDisplay) { public NotificationPreferenceView(NotificationPreference toDisplay) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
myPreference = toDisplay;
updateViewValues(toDisplay);
prefType.setHTML(toDisplay.getTypeLabel()); prefType.setHTML(toDisplay.getTypeLabel());
prefDesc.setHTML("("+toDisplay.getTypeDesc()+")"); prefDesc.setHTML(toDisplay.getTypeDesc());
switchButton.setValue(true);
switchButton.addValueChangeHandler(new ValueChangeHandler<Boolean>() { switchButton.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override @Override
public void onValueChange(ValueChangeEvent<Boolean> event) { public void onValueChange(ValueChangeEvent<Boolean> event) {
setCheckBoxValue(portalCheckbox, event.getValue());
setCheckBoxValue(emailCheckbox, event.getValue());
if (event.getValue()) { if (event.getValue()) {
portalCheckbox.setValue(true);
emailCheckbox.setValue(true);
$(portalCheckbox).fadeIn(300); $(portalCheckbox).fadeIn(300);
$(emailCheckbox).fadeIn(300); $(emailCheckbox).fadeIn(300);
} else { } else {
portalCheckbox.setValue(false);
emailCheckbox.setValue(false);
$(portalCheckbox).fadeOut(300); $(portalCheckbox).fadeOut(300);
$(emailCheckbox).fadeOut(300); $(emailCheckbox).fadeOut(300);
} }
} }
}); });
} }
/**
* called initially, report the preferences from the server in the view
* @param setting the preference
*/
private void updateViewValues(NotificationPreference setting) {
NotificationChannelType[] currChannels = setting.getSelectedChannels();
if (currChannels == null || currChannels.length == 0) {
setCheckBoxValue(portalCheckbox, false);
setCheckBoxValue(portalCheckbox, false);
}
else {
for (int i = 0; i < currChannels.length; i++) {
//GWT.log(currChannels[i].toString() + "-"+setting.getType());
if (currChannels[i] == NotificationChannelType.PORTAL) {
setCheckBoxValue(portalCheckbox, true);
}
if (currChannels[i] == NotificationChannelType.EMAIL) {
setCheckBoxValue(emailCheckbox, true);
}
}
}
//if either one is true switch is ON
boolean overAll = portalCheckbox.getValue() || emailCheckbox.getValue();
switchButton.setValue(overAll);
if (! overAll) {
$(portalCheckbox).fadeOut(300);
$(emailCheckbox).fadeOut(300);
}
}
/**
* this was meant also to color the checkbox label depending on true or false, had no time to complete
* @param toSet the CheckBox instance to check
* @param value just set the value
*/
private void setCheckBoxValue(CheckBox toSet, boolean value) {
toSet.setValue(value);
//TODO next time, no time now
//toSet.getElement().getElementsByTagName("label").getItem(0).setClassName(value ? "labelOn" : "labelOff");
}
public NotificationType getNotificationType() {
return myPreference.getType();
}
/**
* @return the selected notification channels in the view, null if none were selected
*/
public NotificationChannelType[] getSelectedChannels() {
if (switchButton.getValue()) {
ArrayList<NotificationChannelType> toReturn = new ArrayList<NotificationChannelType>();
if (portalCheckbox.getValue())
toReturn.add(NotificationChannelType.PORTAL);
if (emailCheckbox.getValue())
toReturn.add(NotificationChannelType.EMAIL);
return toReturn.toArray(new NotificationChannelType[toReturn.size()]);
}
else
return new NotificationChannelType[0];
}
public void setPortalPrefValue(boolean value) {
setCheckBoxValue(portalCheckbox, value);
}
public void setEmailPrefValue(boolean value) {
setCheckBoxValue(emailCheckbox, value);
}
} }

View File

@ -10,9 +10,9 @@
<e:Span styleName="user-notification" ui:field="prefType" /> <e:Span styleName="user-notification" ui:field="prefType" />
</td> </td>
<td valign="TOP" style="width: 250px;"> <td valign="TOP" style="width: 250px;">
<w:SwitchButton ui:field="switchButton"/> <g:CheckBox ui:field="portalCheckbox">Portal</g:CheckBox>
<g:CheckBox ui:field="portalCheckbox" value="true">Portal</g:CheckBox> <g:CheckBox ui:field="emailCheckbox">Email</g:CheckBox>
<g:CheckBox ui:field="emailCheckbox" value="true">Email</g:CheckBox> <w:SwitchButton ui:field="switchButton" styleName="floatingRight paddingRight"/>
</td> </td>
<td valign="TOP"> <td valign="TOP">
<e:Span styleName="user-notification-comment" ui:field="prefDesc" /> <e:Span styleName="user-notification-comment" ui:field="prefDesc" />

View File

@ -5,6 +5,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -34,6 +35,8 @@ import com.liferay.portal.model.UserModel;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.theme.ThemeDisplay;
import edu.emory.mathcs.backport.java.util.Collections;
/** /**
* The server side implementation of the RPC service. * The server side implementation of the RPC service.
*/ */
@ -183,19 +186,19 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
String typeDesc = descriptions.getProperty(type.toString()); String typeDesc = descriptions.getProperty(type.toString());
if (category != null) { if (category != null) {
if (treeMap.containsKey(category)) { if (treeMap.containsKey(category)) {
treeMap.get(category).add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type.toString()))); treeMap.get(category).add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type)));
} else { } else {
ArrayList<NotificationPreference> toAdd = new ArrayList<NotificationPreference>(); ArrayList<NotificationPreference> toAdd = new ArrayList<NotificationPreference>();
toAdd.add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type.toString()))); toAdd.add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type)));
treeMap.put(category, toAdd); treeMap.put(category, toAdd);
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
_log.error("While trying to get getUser Notification Preferences"); _log.error("While trying to get getUser Notification Preferences for " + userid);
e.printStackTrace(); e.printStackTrace();
} }
_log.debug("Got Notification Preferences from Cassandra cluster, returning to the client for user: " + userid); _log.debug("Got Notification Preferences, returning to the client for user: " + userid);
//need the key in revers order so that workspace appears first //need the key in revers order so that workspace appears first
LinkedHashMap<String, ArrayList<NotificationPreference>> toReturn = new LinkedHashMap<String, ArrayList<NotificationPreference>>(); LinkedHashMap<String, ArrayList<NotificationPreference>> toReturn = new LinkedHashMap<String, ArrayList<NotificationPreference>>();
for (String category : treeMap.descendingKeySet()) { for (String category : treeMap.descendingKeySet()) {
@ -203,6 +206,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
for (NotificationPreference pref : treeMap.get(category)) { for (NotificationPreference pref : treeMap.get(category)) {
toAdd.add(pref); toAdd.add(pref);
} }
Collections.sort(toAdd); //sort the labels from the less length to the more length
toReturn.put(category, toAdd); toReturn.put(category, toAdd);
} }
return toReturn; return toReturn;

View File

@ -11,7 +11,7 @@ import org.gcube.portal.databook.shared.NotificationType;
* and the channels selected by the user for this type * and the channels selected by the user for this type
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class NotificationPreference implements Serializable { public class NotificationPreference implements Serializable, Comparable<NotificationPreference> {
NotificationType type; NotificationType type;
String typeLabel; String typeLabel;
String typeDesc; String typeDesc;
@ -73,6 +73,15 @@ public class NotificationPreference implements Serializable {
+ Arrays.toString(selectedChannels) + "]"; + Arrays.toString(selectedChannels) + "]";
} }
@Override
public int compareTo(NotificationPreference o) {
if (this.typeLabel.length() <= o.getTypeLabel().length())
return -1;
else
return 1;
}
} }

View File

@ -25,7 +25,7 @@ a.link:hover {
border-bottom-color: #DADADA; border-bottom-color: #DADADA;
border-bottom-style: solid; border-bottom-style: solid;
border-bottom-width: 1px; border-bottom-width: 1px;
padding: 5px 7px 3px; padding: 15px 7px 3px;
} }
.day-label { .day-label {
@ -108,3 +108,24 @@ a.link:hover {
.floatingLeft { .floatingLeft {
float:left; float:left;
} }
.floatingRight {
float:right;
}
.paddingRight {
padding-right: 15px;
}
.paddingLeft {
padding-left: 15px;
}
.labelOn {
color: #0088CC;
}
.labelOff {
color: #777;
}

View File

@ -1,20 +1,20 @@
WP_FOLDER_SHARE=sharing of workspace folders with you WP_FOLDER_SHARE=Sharing of workspace folders with you
WP_FOLDER_ADDEDUSER=someone added users one to one of your workspace shared folder WP_FOLDER_ADDEDUSER=Someone added users one to one of your workspace shared folder
WP_FOLDER_REMOVEDUSER=someone removed users from one of your workspace shared folder WP_FOLDER_REMOVEDUSER=Someone removed users from one of your workspace shared folder
WP_FOLDER_RENAMED=someone renamed one of your workspace shared folder WP_FOLDER_RENAMED=Someone renamed one of your workspace shared folder
WP_ITEM_DELETE=someone deleted an item in one of your workspace shared folder WP_ITEM_DELETE=Someone deleted an item in one of your workspace shared folder
WP_ITEM_UPDATED=someone updated an item in one of your workspace shared folder WP_ITEM_UPDATED=Someone updated an item in one of your workspace shared folder
WP_ITEM_RENAMED=someone renamed an item in one of your workspace shared folder WP_ITEM_RENAMED=Someone renamed an item in one of your workspace shared folder
WP_ITEM_NEW=someone added an item in one of your workspace shared folder WP_ITEM_NEW=Someone added an item in one of your workspace shared folder
OWN_COMMENT=someone replied to your post OWN_COMMENT=Someone replied to your post
COMMENT=someone replied too to a post you replied COMMENT=Someone replied too to a post you replied
MENTION=someone mentioned you in a post MENTION=Someone mentioned you in a post
LIKE=someone set favorite your post LIKE=Someone set favorite your post
MESSAGE=someone sent you a message MESSAGE=Someone sent you a message
DOCUMENT_WORKFLOW_EDIT=a document workflow you created was editeded DOCUMENT_WORKFLOW_EDIT=A document workflow you created was editeded
DOCUMENT_WORKFLOW_VIEW=a document workflow you created was viewed DOCUMENT_WORKFLOW_VIEW=A document workflow you created was viewed
DOCUMENT_WORKFLOW_STEP_REQUEST_TASK=someone requested you to perform a task on his document workflow DOCUMENT_WORKFLOW_STEP_REQUEST_TASK=Someone requested you to perform a task on his document workflow
DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT=someone involved you on his document workflow DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT=Someone involved you on his document workflow
DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER=a document workflow you created was forwarded to another step DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER=A document workflow you created was forwarded to another step
DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER=a document workflow you created was forwarded to the another step by all the users involved in the step DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER=A document workflow you created was forwarded to the another step by all the users involved in the step
DOCUMENT_WORKFLOW_STEP_FORWARD_PEER=someone completed his task on a document workflow where you still need to do yours DOCUMENT_WORKFLOW_STEP_FORWARD_PEER=Someone completed his task on a document workflow where you still need to do yours

View File

@ -1,20 +1,20 @@
WP_FOLDER_SHARE=shared folder WP_FOLDER_SHARE=Shared folder
WP_FOLDER_ADDEDUSER=user added to shared folder WP_FOLDER_ADDEDUSER=User added to shared folder
WP_FOLDER_REMOVEDUSER=user removed from shared folder WP_FOLDER_REMOVEDUSER=User removed from shared folder
WP_FOLDER_RENAMED=shared folder renamed WP_FOLDER_RENAMED=Shared folder renamed
WP_ITEM_DELETE=shared item deleted WP_ITEM_DELETE=Shared item deleted
WP_ITEM_UPDATED=shared item updated WP_ITEM_UPDATED=Shared item updated
WP_ITEM_RENAMED=shared item renamed WP_ITEM_RENAMED=Shared item renamed
WP_ITEM_NEW=shared item added WP_ITEM_NEW=Shared item added
OWN_COMMENT=own replies OWN_COMMENT=Own replies
COMMENT=replies COMMENT=Replies
MENTION=mentions MENTION=Mentions
LIKE=favorites LIKE=Favorites
MESSAGE=messages MESSAGE=Messages
DOCUMENT_WORKFLOW_EDIT=edit DOCUMENT_WORKFLOW_EDIT=Edit
DOCUMENT_WORKFLOW_VIEW=view DOCUMENT_WORKFLOW_VIEW=View
DOCUMENT_WORKFLOW_STEP_REQUEST_TASK=task request DOCUMENT_WORKFLOW_STEP_REQUEST_TASK=Task request
DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT=involvement request DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT=Involvement request
DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER=forward DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER=Forward
DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER=step completed DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER=Step completed
DOCUMENT_WORKFLOW_STEP_FORWARD_PEER=forward from peer DOCUMENT_WORKFLOW_STEP_FORWARD_PEER=Forward from peer