Buttons to delete and re-send the welcome email added and working

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/create-users@125883 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-03-21 15:29:48 +00:00
parent b7d038c670
commit e342908ac2
8 changed files with 223 additions and 105 deletions

View File

@ -29,7 +29,7 @@
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.7.0</gwtVersion>
<liferayVersion>6.2.5</liferayVersion>
<liferayVersion>6.0.6</liferayVersion>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

View File

@ -11,11 +11,8 @@ import com.github.gwtbootstrap.client.ui.TabPane;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
@ -37,9 +34,6 @@ public class CreateUsersPanel extends Composite {
// registered users subpanel
private TabPane registeredUsersSubPanel = new TabPane("Already Created Users") ;
// TODO remove
private TabPane sendMailTabPane = new TabPane("Send Mail");
// Create a remote service proxy to talk to the server-side user manager service.
private final HandleUsersServiceAsync userServices = GWT.create(HandleUsersService.class);
@ -63,32 +57,6 @@ public class CreateUsersPanel extends Composite {
loader.setVisible(true);
registeredUsersSubPanel.add(loader);
// TODO remove
Button sendMail = new Button("Test send email");
sendMail.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("send email requested");
userServices.sendEmailToUser("costantino.perciante@isti.cnr.it", new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
GWT.log("ok");
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
GWT.log("not ok");
}
});
}
});
sendMailTabPane.add(sendMail);
navTabs.add(sendMailTabPane);
// add stuff to the main panel
navTabs.add(addUserSubPanel);
navTabs.add(registeredUsersSubPanel);
@ -115,7 +83,7 @@ public class CreateUsersPanel extends Composite {
}
GWT.log("List of registered users received!");
registeredUsersTable = new RegisteredUsersTable(result, eventBus);
registeredUsersTable = new RegisteredUsersTable(result, eventBus, userServices);
registeredUsersSubPanel.clear();
registeredUsersSubPanel.add(registeredUsersTable);
}

View File

@ -9,6 +9,7 @@ import com.github.gwtbootstrap.client.ui.AlertBlock;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.Form;
import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
@ -32,6 +33,11 @@ public class AddUserForm extends Composite{
private static AddUserFormUiBinder uiBinder = GWT
.create(AddUserFormUiBinder.class);
/**
* Path of the image to be shown during loading
*/
public static final String imagePath = GWT.getModuleBaseURL() + "../images/loader.gif";
interface AddUserFormUiBinder extends UiBinder<Widget, AddUserForm> {
}
@ -44,8 +50,8 @@ public class AddUserForm extends Composite{
@UiField
CheckBox sendMailCheckbox;
// @UiField
// RadioButton maleCheckbox;
@UiField
Image performingRequest;
@UiField
TextBox emailTextbox;
@ -84,6 +90,9 @@ public class AddUserForm extends Composite{
this.registrationService = userServices;
this.eventBus = eventBus;
this.parent = parent;
// set loader url
performingRequest.setUrl(imagePath);
}
@ -142,6 +151,12 @@ public class AddUserForm extends Composite{
}else{
// show loading image
performingRequest.setVisible(true);
// disable add button
submit.setEnabled(false);
// remote service invocation
registrationService.register(
actualName,
@ -199,6 +214,12 @@ public class AddUserForm extends Composite{
private void showAlertBlockThenHide(final AlertBlock alert, String msg, int hideAfterMs){
// hide loading image
performingRequest.setVisible(false);
// enable button again
submit.setEnabled(true);
// set text
alert.setText(msg);
alert.setVisible(true);

View File

@ -75,10 +75,10 @@
b:id="surname" title="User's surname" ui:field="surnameTextbox" />
</b:Controls>
<b:ControlLabel for="company" title="User's company">Company:</b:ControlLabel>
<b:ControlLabel for="company" title="User's company">Institution/Organization:</b:ControlLabel>
<b:Controls>
<b:TextBox alternateSize="LARGE" placeholder="Company"
b:id="company" title="User's company" ui:field="companyTextbox" />
<b:TextBox alternateSize="LARGE" placeholder="Institution/Organization"
b:id="company" title="User's Institution/Organization" ui:field="companyTextbox" />
</b:Controls>
<b:ControlLabel for="sendmail"
@ -105,6 +105,8 @@
<br></br>
<b:Image ui:field="performingRequest" visible="false"></b:Image>
<b:AlertBlock type="ERROR" close="false" animation="true"
visible="false" ui:field="errorBlock" styleName="{style.block-alert-style}"></b:AlertBlock>

View File

@ -1,9 +0,0 @@
package org.gcube.portlets.admin.createusers.client.ui;
import com.google.gwt.user.client.ui.PopupPanel;
public class PopupPanelExtended extends PopupPanel {
}

View File

@ -3,24 +3,27 @@ import java.util.Comparator;
import java.util.Date;
import java.util.List;
import org.gcube.portlets.admin.createusers.client.HandleUsersServiceAsync;
import org.gcube.portlets.admin.createusers.client.event.AddUserEvent;
import org.gcube.portlets.admin.createusers.client.event.AddUserEventHandler;
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CellTable;
import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.view.client.CellPreviewEvent;
import com.google.gwt.view.client.CellPreviewEvent.Handler;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.Range;
@ -36,7 +39,7 @@ public class RegisteredUsersTable extends Composite {
private CellTable<VreUserBean> table = new CellTable<VreUserBean>(1, tableRes);
private final HandlerManager eventBus;
public RegisteredUsersTable(List<VreUserBean> registeredUsers, HandlerManager eventBus) {
public RegisteredUsersTable(List<VreUserBean> registeredUsers, HandlerManager eventBus, final HandleUsersServiceAsync userServices) {
super();
initWidget(table);
@ -182,41 +185,136 @@ public class RegisteredUsersTable extends Composite {
table.addColumnSortHandler(registrationDateColHandler);
table.getColumnSortList().push(registrationDate);
// add row click handler
table.addCellPreviewHandler(new Handler<VreUserBean>() {
// delete option
Column<VreUserBean, String> deleteUser = new Column<VreUserBean, String>(new ButtonCell()) {
@Override
public void onCellPreview(CellPreviewEvent<VreUserBean> event) {
boolean isClick = "click".equals(event.getNativeEvent().getType());
if(isClick){
public String getValue(VreUserBean object) {
return object.isPasswordChanged() ? "True" : "False"; // useless
}
int rowIndex = event.getIndex();
PopupPanel drop = new PopupPanel();
drop.setGlassEnabled(true);
@Override
public void render(Cell.Context context, VreUserBean value, SafeHtmlBuilder sb){
// add buttons and events
VreUserBean rowBean = dataProvider.getList().get(rowIndex);
if(value == null)
return;
Button deleteUserButton = new Button("Delete User");
Button sendWelcomeButton = new Button("Send Email");
if(!rowBean.isPasswordChanged())
deleteUserButton.setEnabled(false);
// add to drop
drop.add(deleteUserButton);
drop.add(sendWelcomeButton);
// position and show
int left = table.getRowElement(rowIndex).getAbsoluteLeft();
int top = table.getRowElement(rowIndex).getAbsoluteTop();
drop.setPopupPosition(left, top);
drop.show();
if(!value.isPasswordChanged())
sb.appendHtmlConstant("<Button>Delete User</Button>");
else
sb.appendHtmlConstant("<Button disabled>Delete User</Button>");
}
@Override
public void onBrowserEvent(Cell.Context context, final Element parent, final VreUserBean user, NativeEvent event) {
event.preventDefault();
if(!"click".equals(event.getType()))
return;
EventTarget eventTarget = event.getEventTarget();
if(parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))){
// get the button and disable it
parent.getFirstChildElement().setPropertyBoolean("disabled", true);
userServices.deleteInvitedUser(user.getEmail(), new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
// delete this row too
if(result){
dataProvider.getList().remove(user);
table.setVisibleRange(new Range(0, dataProvider.getList().size()));
table.setRowCount(dataProvider.getList().size(), true);
dataProvider.refresh();
Window.alert("Deleted user with email " + user.getEmail());
}else
Window.alert("Unable to delete this user, sorry!");
// enable the button again
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Unable to delete this user, sorry!");
// enable the button again
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
}
});
}
};
};
// send email option
Column<VreUserBean, String> sendWelcomeMessage = new Column<VreUserBean, String>(new ButtonCell()) {
@Override
public String getValue(VreUserBean object) {
return "Send Welcome"; // useless
}
@Override
public void render(Cell.Context context, VreUserBean value, SafeHtmlBuilder sb){
if(value == null)
return;
sb.appendHtmlConstant("<Button>Send Welcome</Button>");
}
@Override
public void onBrowserEvent(Cell.Context context, final Element parent, final VreUserBean user, NativeEvent event) {
event.preventDefault();
if(!"click".equals(event.getType()))
return;
EventTarget eventTarget = event.getEventTarget();
if(parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))){
// get the button and disable it
parent.getFirstChildElement().setPropertyBoolean("disabled", true);
userServices.sendEmailToUser(user.getEmail(), new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
Window.alert("Welcome message sent to " + user.getEmail());
// get the button and enable it
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Unable to send the welcome message to " + user.getEmail());
// get the button and enable it
parent.getFirstChildElement().setPropertyBoolean("disabled", false);
}
});
}
}
};
// add columns
SafeHtmlBuilder builder = new SafeHtmlBuilder();
@ -249,7 +347,16 @@ public class RegisteredUsersTable extends Composite {
builder.appendEscaped("Registration date");
builder.appendHtmlConstant("</span>");
table.addColumn(registrationDate, builder.toSafeHtml());
builder = new SafeHtmlBuilder();
builder.appendHtmlConstant("<span title=\"" + "Delete User"+ "\">");
builder.appendEscaped("Delete");
builder.appendHtmlConstant("</span>");
table.addColumn(deleteUser, builder.toSafeHtml());
builder = new SafeHtmlBuilder();
builder.appendHtmlConstant("<span title=\"" + "Send Welcome Message" + "\">");
builder.appendEscaped("Send Welcome");
builder.appendHtmlConstant("</span>");
table.addColumn(sendWelcomeMessage, builder.toSafeHtml());
}
/**
@ -306,7 +413,6 @@ public class RegisteredUsersTable extends Composite {
C getValue(VreUserBean user);
}
/**
* get a column
*

View File

@ -15,7 +15,6 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.admin.createusers.client.HandleUsersService;
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
@ -34,6 +33,10 @@ import com.liferay.portal.kernel.dao.jdbc.DataAccess;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.mail.MailMessage;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Company;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
@ -61,6 +64,8 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
private static final String FIELD_REGISTRATION_DATE = "registration_date";
private static final String FIELD_VRE = "vre";
public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com";
@Override
public void init(){
@ -180,6 +185,14 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
@Override
public boolean deleteInvitedUser(String email) {
// if in dev mode return some samples
if (!isWithinPortal()) {
logger.debug("In dev mode.");
return false;
}else{
try{
Connection con = DataAccess.getConnection();
@ -193,6 +206,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
return false;
}
}
@Override
public void sendEmailToUser(String email) {
@ -208,7 +222,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
InternetAddress from = new InternetAddress(emailSender);
LiferayUserManager userManager = new LiferayUserManager();
String portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHostname(), 443, true);
String portalUrl = PortalUtil.getPortalURL(getCompany().getVirtualHost(), 443, true);
String username = userManager.getFullNameFromEmail(email);
MailMessage mailMessage = new MailMessage();
@ -216,14 +230,11 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
mailMessage.setTo(to);
String body = "<p>Dear " + username + ",<br />" + "<br />" +
"Welcome! You recently created an account at http:// " + portalUrl + ". Your password is not sent by email for security purposes.<br />" +
"Welcome! You recently created an account at " + portalUrl + ". Your password is not sent by email for security purposes.<br />" +
"<br />" + "Sincerely,<br />" +
gatewayName + "<br />" +
emailSender + "<br />" + portalUrl;
String subject = "http://" + portalUrl + ": Your New Account was created successfully!";
logger.debug("Body is " + body);
logger.debug("Subject is " + subject);
String subject = portalUrl + ": Your New Account was created successfully!";
mailMessage.setBody(body);
mailMessage.setSubject(subject);
@ -365,7 +376,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
if (!isWithinPortal()) {
logger.debug("In dev mode.");
toReturn.add(new VreUserBean("Dylan", "Dog", "ISTI-CNR", "dylan.dog@gmail.com", false, System.currentTimeMillis(), true));
toReturn.add(new VreUserBean("Dylan", "Dog", "ISTI-CNR", "dylan.dog@gmail.com", true, System.currentTimeMillis(), true));
toReturn.add(new VreUserBean("Costantino", "Perciante", "ISTI-CNR", "costantino8@gmail.com", false, System.currentTimeMillis(), true));
return toReturn;
@ -451,7 +462,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
try{
logger.debug("Going to delete user with email " + email);
logger.debug("Going to delete user with email " + email + " from the table of registered users");
String remove = "DELETE FROM " + REGISTERED_USERS_TABLE + " WHERE " + FIELD_EMAIL + "= ?";
PreparedStatement statementDelete = con.prepareStatement(remove);
@ -518,4 +529,23 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
}
return toReturn;
}
public static Company getCompany() throws PortalException, SystemException {
return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId());
}
/**
*
* @return the default company web-id (e.g. iMarine.eu)
*/
public static String getDefaultCompanyWebId() {
String defaultWebId = "";
try {
defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
}
catch (NullPointerException e) {
logger.error("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
return DEFAULT_COMPANY_WEB_ID;
}
return defaultWebId;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB