validation email finished
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/invite-friends-vre@114416 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2e52ed2606
commit
050d77e3a8
|
@ -5,9 +5,6 @@
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
<dependent-module archiveName="session-checker-0.3.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
|
|
||||||
<dependency-type>uses</dependency-type>
|
|
||||||
</dependent-module>
|
|
||||||
<property name="context-root" value="invite-friends-vre"/>
|
<property name="context-root" value="invite-friends-vre"/>
|
||||||
<property name="java-output-path" value="/invite-friends-vre/target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes"/>
|
<property name="java-output-path" value="/invite-friends-vre/target/invite-friends-vre-0.0.1-SNAPSHOT/WEB-INF/classes"/>
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.portlets.user.invitefriends.client.ui;
|
package org.gcube.portlets.user.invitefriends.client.ui;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.invitefriends.client.validation.ValidationErrorsActivity;
|
||||||
|
|
||||||
import com.github.gwtbootstrap.client.ui.Button;
|
import com.github.gwtbootstrap.client.ui.Button;
|
||||||
import com.github.gwtbootstrap.client.ui.Form;
|
import com.github.gwtbootstrap.client.ui.Form;
|
||||||
import com.github.gwtbootstrap.client.ui.HelpBlock;
|
import com.github.gwtbootstrap.client.ui.HelpBlock;
|
||||||
|
@ -12,13 +14,14 @@ import com.google.gwt.uibinder.client.UiField;
|
||||||
import com.google.gwt.uibinder.client.UiHandler;
|
import com.google.gwt.uibinder.client.UiHandler;
|
||||||
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.SimplePanel;
|
||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Massimiliano Assante, ISTI-CNR
|
* @author Massimiliano Assante, ISTI-CNR
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class InviteWidget extends Composite {
|
public class InviteWidget extends Composite{
|
||||||
|
|
||||||
public static final String DISPLAY_NAME = "Invite people to this VRE";
|
public static final String DISPLAY_NAME = "Invite people to this VRE";
|
||||||
|
|
||||||
|
@ -29,29 +32,26 @@ public class InviteWidget extends Composite {
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiField HTML header;
|
@UiField HTML header;
|
||||||
@UiField TextBox emailAddress;
|
|
||||||
@UiField Button openModal;
|
@UiField SimplePanel validationErrorsFormPanel;
|
||||||
@UiField Button cancelInvite;
|
|
||||||
@UiField Button sendInvite;
|
|
||||||
@UiField Modal modalWindow;
|
|
||||||
@UiField Form mainForm;
|
|
||||||
@UiField HelpBlock helpBlock;
|
|
||||||
|
|
||||||
public InviteWidget() {
|
public InviteWidget() {
|
||||||
|
super();
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
header.setText(DISPLAY_NAME);
|
header.setText(DISPLAY_NAME);
|
||||||
|
|
||||||
|
new ValidationErrorsActivity().start(validationErrorsFormPanel, null);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
@UiHandler("openModal")
|
// @UiHandler("openModal")
|
||||||
public void onClick(ClickEvent e) {
|
// public void onClick(ClickEvent e) {
|
||||||
helpBlock.setText("We will send the invitation email to: "+emailAddress.getText());
|
// helpBlock.setText("We will send the invitation email to: "+emailAddress.getText());
|
||||||
modalWindow.show();
|
// modalWindow.show();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@UiHandler("cancelInvite")
|
// @UiHandler("cancelInvite")
|
||||||
public void onCancelClick(ClickEvent e) {
|
// public void onCancelClick(ClickEvent e) {
|
||||||
modalWindow.hide();
|
// modalWindow.hide();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,33 +3,6 @@
|
||||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||||
<g:HTMLPanel styleName="invites-frame">
|
<g:HTMLPanel styleName="invites-frame">
|
||||||
<g:HTML ui:field="header" styleName="invites-title"></g:HTML>
|
<g:HTML ui:field="header" styleName="invites-title"></g:HTML>
|
||||||
<b:Form type="VERTICAL">
|
<g:SimplePanel ui:field="validationErrorsFormPanel" />
|
||||||
<b:Fieldset>
|
|
||||||
<b:ControlGroup>
|
|
||||||
<b:TextBox placeholder="e-mail address" ui:field="emailAddress"></b:TextBox>
|
|
||||||
</b:ControlGroup>
|
|
||||||
<b:Button ui:field="openModal">Send Invite</b:Button>
|
|
||||||
</b:Fieldset>
|
|
||||||
</b:Form>
|
|
||||||
<b:Modal ui:field="modalWindow" title="Invite Friend"
|
|
||||||
backdrop="STATIC" keyboard="true" animation="true">
|
|
||||||
<b:Form type="VERTICAL" ui:field="mainForm">
|
|
||||||
<b:Fieldset>
|
|
||||||
<b:ControlGroup>
|
|
||||||
<b:HelpBlock styleName="helpFontSize">Please, enter name and lastname of the friend you
|
|
||||||
wish to invite:</b:HelpBlock>
|
|
||||||
|
|
||||||
<b:TextBox placeholder="name"></b:TextBox>
|
|
||||||
<b:TextBox placeholder="last name"></b:TextBox>
|
|
||||||
|
|
||||||
<b:HelpBlock ui:field="helpBlock" styleName="helpFontSize"></b:HelpBlock>
|
|
||||||
</b:ControlGroup>
|
|
||||||
</b:Fieldset>
|
|
||||||
</b:Form>
|
|
||||||
<b:ModalFooter>
|
|
||||||
<b:Button ui:field="cancelInvite">Cancel</b:Button>
|
|
||||||
<b:Button ui:field="sendInvite" type="PRIMARY">Send Invite</b:Button>
|
|
||||||
</b:ModalFooter>
|
|
||||||
</b:Modal>
|
|
||||||
</g:HTMLPanel>
|
</g:HTMLPanel>
|
||||||
</ui:UiBinder>
|
</ui:UiBinder>
|
|
@ -0,0 +1,161 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.invitefriends.client.validation;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.Path;
|
||||||
|
import javax.validation.metadata.ConstraintDescriptor;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.invitefriends.client.validation.ValidationErrorsView.UserDetails;
|
||||||
|
|
||||||
|
import com.google.gwt.activity.shared.AbstractActivity;
|
||||||
|
import com.google.gwt.editor.client.EditorDriver;
|
||||||
|
import com.google.gwt.event.shared.EventBus;
|
||||||
|
import com.google.gwt.user.client.ui.AcceptsOneWidget;
|
||||||
|
import com.google.gwt.validation.client.impl.PathImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Showcase for <code>ErrorEditor</code>s validation decoration of <code>TextBox</code>es.
|
||||||
|
*
|
||||||
|
* @author ivangsa
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ValidationErrorsActivity extends AbstractActivity implements ValidationErrorsView.Delegate {
|
||||||
|
|
||||||
|
private ValidationErrorsView view;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void start(AcceptsOneWidget panel, EventBus eventBus) {
|
||||||
|
view = new ValidationErrorsViewImpl(this);
|
||||||
|
panel.setWidget(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
@Override
|
||||||
|
public boolean onSendClick() {
|
||||||
|
EditorDriver<UserDetails> editorDriver = view.getEditorDriver();
|
||||||
|
UserDetails login = editorDriver.flush();
|
||||||
|
Set<ConstraintViolation<UserDetails>> violations = validate(login);
|
||||||
|
/* This will decorate widgets implementing HasEditorErrors with validation messages */
|
||||||
|
return editorDriver.setConstraintViolations( (Set) violations);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<ConstraintViolation<UserDetails>> validate(UserDetails user2InviteBean){
|
||||||
|
Set<ConstraintViolation<UserDetails>> violations = new HashSet<ConstraintViolation<UserDetails>>();
|
||||||
|
if(user2InviteBean.getEmail() == null || "".equals(user2InviteBean.getEmail().trim())) {
|
||||||
|
violations.add(buildNotNullConstraintViolation(user2InviteBean, "email"));
|
||||||
|
}
|
||||||
|
else if (!isValidEmailAddress(user2InviteBean.getEmail())) {
|
||||||
|
violations.add(buildInvalidEmailAddressConstraintViolation(user2InviteBean, "email"));
|
||||||
|
}
|
||||||
|
return violations;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ConstraintViolation<UserDetails> buildNotNullConstraintViolation(final UserDetails bean, final String path) {
|
||||||
|
return new ConstraintViolation<UserDetails>() {
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return "must not be empty";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getMessageTemplate() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public UserDetails getRootBean() {
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Class<UserDetails> getRootBeanClass() {
|
||||||
|
return UserDetails.class;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getLeafBean() {
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getPropertyPath() {
|
||||||
|
return new PathImpl().append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getInvalidValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ConstraintDescriptor<?> getConstraintDescriptor() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConstraintViolation<UserDetails> buildInvalidEmailAddressConstraintViolation(final UserDetails bean, final String path) {
|
||||||
|
return new ConstraintViolation<UserDetails>() {
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return "email address must be valid";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getMessageTemplate() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public UserDetails getRootBean() {
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Class<UserDetails> getRootBeanClass() {
|
||||||
|
return UserDetails.class;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getLeafBean() {
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getPropertyPath() {
|
||||||
|
return new PathImpl().append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getInvalidValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ConstraintDescriptor<?> getConstraintDescriptor() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param emailValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isValidEmailAddress(String emailValue) {
|
||||||
|
if(emailValue == null) return true;
|
||||||
|
|
||||||
|
String emailPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.(?:[a-zA-Z]{2,6})$";
|
||||||
|
|
||||||
|
boolean valid = false;
|
||||||
|
|
||||||
|
if(emailValue.getClass().toString().equals(String.class.toString())) {
|
||||||
|
valid = ((String)emailValue).matches(emailPattern);
|
||||||
|
} else {
|
||||||
|
valid = ((Object)emailValue).toString().matches(emailPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.invitefriends.client.validation;
|
||||||
|
|
||||||
|
import com.google.gwt.editor.client.EditorDriver;
|
||||||
|
import com.google.gwt.user.client.ui.IsWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ivangsa
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ValidationErrorsView extends IsWidget {
|
||||||
|
|
||||||
|
public static class UserDetails {
|
||||||
|
String email;
|
||||||
|
String name;
|
||||||
|
String lastName;
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "UserDetails [email=" + email + ", name=" + name
|
||||||
|
+ ", lastName=" + lastName + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Delegate {
|
||||||
|
boolean onSendClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorDriver<UserDetails> getEditorDriver();
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.invitefriends.client.validation;
|
||||||
|
|
||||||
|
import com.github.gwtbootstrap.client.ui.Button;
|
||||||
|
import com.github.gwtbootstrap.client.ui.HelpBlock;
|
||||||
|
import com.github.gwtbootstrap.client.ui.Modal;
|
||||||
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.editor.client.Editor;
|
||||||
|
import com.google.gwt.editor.client.EditorDriver;
|
||||||
|
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
|
||||||
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
|
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.ui.Composite;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ivangsa
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ValidationErrorsViewImpl extends Composite implements ValidationErrorsView, Editor<ValidationErrorsView.UserDetails> {
|
||||||
|
|
||||||
|
interface Binder extends UiBinder<Widget, ValidationErrorsViewImpl> {}
|
||||||
|
private static Binder uiBinder = GWT.create(Binder.class);
|
||||||
|
|
||||||
|
interface Driver extends SimpleBeanEditorDriver<ValidationErrorsView.UserDetails, ValidationErrorsViewImpl> { }
|
||||||
|
private Driver driver = GWT.create(Driver.class);
|
||||||
|
|
||||||
|
private final Delegate delegate;
|
||||||
|
|
||||||
|
@UiField TextBox email;
|
||||||
|
@UiField TextBox name;
|
||||||
|
@UiField TextBox lastName;
|
||||||
|
//
|
||||||
|
@UiField Button openModal;
|
||||||
|
@UiField Button cancelInvite;
|
||||||
|
@UiField Button sendInvite;
|
||||||
|
@UiField Modal modalWindow;
|
||||||
|
@UiField HelpBlock helpBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ValidationErrorsViewImpl(Delegate delegate) {
|
||||||
|
super();
|
||||||
|
this.delegate = delegate;
|
||||||
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
|
driver.initialize(this);
|
||||||
|
driver.edit(new UserDetails());
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiHandler("openModal")
|
||||||
|
void onUserClick(ClickEvent event) {
|
||||||
|
if (!delegate.onSendClick()) {
|
||||||
|
helpBlock.setText("We will send the invitation email to: "+email.getText());
|
||||||
|
modalWindow.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiHandler("cancelInvite")
|
||||||
|
public void onCancelClick(ClickEvent e) {
|
||||||
|
modalWindow.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EditorDriver<ValidationErrorsView.UserDetails> getEditorDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||||
|
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||||
|
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||||
|
<b:Form type="VERTICAL">
|
||||||
|
<b:Fieldset ui:field="controlFieldset">
|
||||||
|
|
||||||
|
<b:ControlGroup ui:field="emailGroup">
|
||||||
|
<b:TextBox placeholder="e-mail address" ui:field="email"
|
||||||
|
controlGroup="{emailGroup}" errorLabel="{emailErrors}" />
|
||||||
|
<b:HelpBlock ui:field="emailErrors"></b:HelpBlock>
|
||||||
|
</b:ControlGroup>
|
||||||
|
<b:Button ui:field="openModal">Send Invite</b:Button>
|
||||||
|
|
||||||
|
<b:Modal ui:field="modalWindow" title="Invite Friend"
|
||||||
|
backdrop="STATIC" keyboard="true" animation="true">
|
||||||
|
<b:Form type="VERTICAL" ui:field="mainForm">
|
||||||
|
<b:Fieldset>
|
||||||
|
<b:ControlGroup>
|
||||||
|
<b:HelpBlock styleName="helpFontSize">Please, enter Name and
|
||||||
|
Last name
|
||||||
|
of the friend you
|
||||||
|
wish to invite:</b:HelpBlock>
|
||||||
|
|
||||||
|
<b:TextBox placeholder="name" ui:field="name"></b:TextBox>
|
||||||
|
<b:TextBox placeholder="last name" ui:field="lastName"></b:TextBox>
|
||||||
|
|
||||||
|
<b:HelpBlock ui:field="helpBlock" styleName="helpFontSize"></b:HelpBlock>
|
||||||
|
</b:ControlGroup>
|
||||||
|
</b:Fieldset>
|
||||||
|
</b:Form>
|
||||||
|
<b:ModalFooter>
|
||||||
|
<b:Button ui:field="cancelInvite">Cancel</b:Button>
|
||||||
|
<b:Button ui:field="sendInvite" type="PRIMARY">Send Invite</b:Button>
|
||||||
|
</b:ModalFooter>
|
||||||
|
</b:Modal>
|
||||||
|
</b:Fieldset>
|
||||||
|
</b:Form>
|
||||||
|
</ui:UiBinder>
|
|
@ -2,6 +2,7 @@
|
||||||
<module rename-to='invitefriends'>
|
<module rename-to='invitefriends'>
|
||||||
<!-- Inherit the core Web Toolkit stuff. -->
|
<!-- Inherit the core Web Toolkit stuff. -->
|
||||||
<inherits name='com.google.gwt.user.User' />
|
<inherits name='com.google.gwt.user.User' />
|
||||||
|
<inherits name='com.google.gwt.activity.Activity' />
|
||||||
<inherits name="com.github.gwtbootstrap.Bootstrap" />
|
<inherits name="com.github.gwtbootstrap.Bootstrap" />
|
||||||
|
|
||||||
<!-- Other module inherits -->
|
<!-- Other module inherits -->
|
||||||
|
|
Loading…
Reference in New Issue