@ -17,6 +17,7 @@ import com.google.gwt.event.dom.client.ClickHandler;
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.Window.Location ;
import com.google.gwt.user.client.rpc.AsyncCallback ;
import com.google.gwt.user.client.ui.Composite ;
@ -24,11 +25,11 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget ;
public class RequestMembershipDialog extends Composite {
private static final String OPTIONAL_COMMENT_TEXT = "You can add an optional comment here, it will be attached to your request and read by this VRE Moderators.";
private static final String MANDATORY_MOTIVATION_TEXT = "Please state your motivation here, it will be attached to your request and read by this VRE Moderators (Mandatory field) .";
private final JoinServiceAsync joinService = GWT . create ( JoinService . class ) ;
private static RequestAccessModalUiBinder uiBinder = GWT
. create ( RequestAccessModalUiBinder . class ) ;
@ -38,12 +39,12 @@ public class RequestMembershipDialog extends Composite {
@UiField Modal m ;
@UiField Button close ;
@UiField Button confirmRequest ;
@UiField TextArea optionalText ;
@UiField TextArea mandatoryMotivation ;
@UiField HelpBlock helpBlock ;
@UiField Icon loading ;
private VRE myVRE = null ;
private ResponsivePanel responsivePanel ;
@UiField HelpBlock touGatewayBlock ;
@UiField HTML touText ;
@ -51,8 +52,8 @@ public class RequestMembershipDialog extends Composite {
initWidget ( uiBinder . createAndBindUi ( this ) ) ;
this . myVRE = myVRE ;
this . responsivePanel = responsivePanel ;
optionalText . setWidth ( "95%" ) ;
optionalText. setPlaceholder ( OPTIONAL_COMMENT _TEXT) ;
mandatoryMotivation . setWidth ( "95%" ) ;
mandatoryMotivation. setPlaceholder ( MANDATORY_MOTIVATION _TEXT) ;
}
public void show ( ) {
@ -85,12 +86,12 @@ public class RequestMembershipDialog extends Composite {
( ( Element ) m . getElement ( ) . getChildNodes ( ) . getItem ( 1 ) ) . addClassName ( "modal-body-custom" ) ;
touText . setHTML ( result ) ;
}
m . show ( ) ;
}
} ) ;
m . show ( ) ;
}
@ -100,27 +101,32 @@ public class RequestMembershipDialog extends Composite {
}
@UiHandler ( "confirmRequest" )
void confirm ( ClickEvent e ) {
String text = optionalText . getText ( ) ;
confirmRequest . setEnabled ( false ) ;
joinService . addMembershipRequest ( myVRE , text , new AsyncCallback < Void > ( ) {
@Override
public void onSuccess ( Void result ) {
confirmRequest . removeFromParent ( ) ;
optionalText . removeFromParent ( ) ;
m . setTitle ( "Thank you, your request has been sent successfully" ) ;
helpBlock . setText ( "You will receive an email as soon as your request will be processed." ) ;
responsivePanel . setPending ( myVRE ) ;
confirmRequest . setEnabled ( false ) ;
touText . removeFromParent ( ) ;
}
@Override
public void onFailure ( Throwable caught ) {
confirmRequest . removeFromParent ( ) ;
optionalText . removeFromParent ( ) ;
m . setTitle ( "An error occurred! Your request has not been sent" ) ;
helpBlock . setText ( "An email with the cause of the error has been sent to the support team, we'll be back to you shortly." ) ;
touText . removeFromParent ( ) ;
}
} ) ;
String text = mandatoryMotivation . getText ( ) ;
if ( text . isEmpty ( ) | | text . length ( ) < 8 ) {
Window . alert ( "The motivation is mandatory, please state your motivation appropriately." ) ;
}
else {
confirmRequest . setEnabled ( false ) ;
joinService . addMembershipRequest ( myVRE , text , new AsyncCallback < Void > ( ) {
@Override
public void onSuccess ( Void result ) {
confirmRequest . removeFromParent ( ) ;
mandatoryMotivation . removeFromParent ( ) ;
m . setTitle ( "Thank you, your request has been sent successfully" ) ;
helpBlock . setText ( "You will receive an email as soon as your request will be processed." ) ;
responsivePanel . setPending ( myVRE ) ;
confirmRequest . setEnabled ( false ) ;
touText . removeFromParent ( ) ;
}
@Override
public void onFailure ( Throwable caught ) {
confirmRequest . removeFromParent ( ) ;
mandatoryMotivation . removeFromParent ( ) ;
m . setTitle ( "An error occurred! Your request has not been sent" ) ;
helpBlock . setText ( "An email with the cause of the error has been sent to the support team, we'll be back to you shortly." ) ;
touText . removeFromParent ( ) ;
}
} ) ;
}
}
}