129 lines
3.9 KiB
Java
129 lines
3.9 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.invitefriends.client.validation;
|
|
|
|
import org.gcube.portlets.user.invitefriends.client.InviteService;
|
|
import org.gcube.portlets.user.invitefriends.client.InviteServiceAsync;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
|
import com.github.gwtbootstrap.client.ui.HelpBlock;
|
|
import com.github.gwtbootstrap.client.ui.Icon;
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
|
import com.github.gwtbootstrap.client.ui.TextBox;
|
|
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
|
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
|
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.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
/**
|
|
*
|
|
* @author Massimiliano Assante, ISTI-CNR
|
|
*
|
|
*/
|
|
public class FormViewImpl extends Composite implements FormView, Editor<FormView.UserDetails> {
|
|
|
|
/**
|
|
* Create a remote service proxy to talk to the server-side service
|
|
*/
|
|
private final InviteServiceAsync service = GWT.create(InviteService.class);
|
|
|
|
interface Binder extends UiBinder<Widget, FormViewImpl> {}
|
|
private static Binder uiBinder = GWT.create(Binder.class);
|
|
|
|
interface Driver extends SimpleBeanEditorDriver<FormView.UserDetails, FormViewImpl> { }
|
|
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 nameErrors;
|
|
@UiField HelpBlock feedback;
|
|
|
|
@UiField
|
|
ControlGroup nameGroup;
|
|
@UiField
|
|
ControlGroup feedbackGroup;
|
|
/**
|
|
*
|
|
*/
|
|
public FormViewImpl(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()) {
|
|
feedback.setText("We will send the invitation email to: "+email.getText() + " and put you in cc, we'll never email your contacts without your say so.");
|
|
modalWindow.show();
|
|
}
|
|
|
|
}
|
|
|
|
@UiHandler("sendInvite")
|
|
void onSendInviteClick(ClickEvent event) {
|
|
if (delegate.onEmailSendInviteClick()) {
|
|
nameGroup.setType(ControlGroupType.ERROR);
|
|
nameErrors.setText("Please fill both name and last name");
|
|
} else {
|
|
nameGroup.setType(ControlGroupType.NONE);
|
|
nameErrors.setText("");
|
|
service.sendInviteEmail(name.getText(), lastName.getText(), email.getText(), new AsyncCallback<Boolean>() {
|
|
|
|
@Override
|
|
public void onSuccess(Boolean result) {
|
|
feedback.setText("Thanks for inviting, we sent the email correctly.");
|
|
feedbackGroup.setType(ControlGroupType.SUCCESS);
|
|
sendInvite.removeFromParent();
|
|
cancelInvite.setText("Close");
|
|
email.setText("");
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
feedback.setText("Sorry, an error occurred and we could not send the invite, please try again later");
|
|
feedbackGroup.setType(ControlGroupType.ERROR);
|
|
sendInvite.removeFromParent();
|
|
email.setText("");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@UiHandler("cancelInvite")
|
|
public void onCancelClick(ClickEvent e) {
|
|
modalWindow.hide();
|
|
email.setText("");
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public EditorDriver<FormView.UserDetails> getEditorDriver() {
|
|
return driver;
|
|
}
|
|
}
|
|
|