Skip to content

Commit

Permalink
gwt: Add support for remember me field. Auto adjust formLabel based o…
Browse files Browse the repository at this point in the history
…n length of strings (for better i18n support).
  • Loading branch information
calin-iorgulescu committed Feb 5, 2015
1 parent a00905d commit 2cf2a90
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface LoginConstants extends Constants {
String formComment();
String usernameLabel();
String passwordLabel();
String extendSessionLabel();
String usernameEmpty();
String passwordEmpty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ loginFormLabel = Authentication form
formComment = Use the same credentials as for curs.cs
usernameLabel = Username
passwordLabel = Password
extendSessionLabel = Remember me on this computer
usernameEmpty = User field empty
passwordEmpty = Password field empty
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ loginFormLabel = Formulaire d'authentification
formComment = Utilisez vos identifiants et password curs.cs
usernameLabel = Nom d'utilisateur
passwordLabel = Mot de passe
extendSessionLabel = Se rappeler de moi sur cet ordinateur
usernameEmpty = Champ du nom d'utilisateur vide
passwordEmpty = Champ du mot de passe vide
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ loginFormLabel = Formular autentificare
formComment = Folosiți utilizatorul și parola de pe curs.cs
usernameLabel = Utilizator
passwordLabel = Parolă
extendSessionLabel = Ține-mă minte pe acest calculator
usernameEmpty = Utilizator necompletat
passwordEmpty = Parola necompletata
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasWidgets;

public class LoginPresenter implements Presenter, KeyPressHandler {
Expand All @@ -28,6 +29,7 @@ public interface Widget {
HasText getPasswordField();
HasText getPasswordCommentLabel();
void setPasswordCommentVisible(boolean visible);
HasValue<Boolean> getExtendSessionField();
HasClickHandlers getLoginButton();
HasText getLoginCommentLabel();
void setLoginCommentVisible(boolean visible);
Expand Down Expand Up @@ -104,7 +106,9 @@ public void onClick(ClickEvent event) {
private void sendAuthenticationRequest() {
widget.setInputsEnabled(false);
service.performAuthentication(this.widget.getUsernameField().getText(),
this.widget.getPasswordField().getText(), new AsyncCallback<AuthenticationResponse>() {
this.widget.getPasswordField().getText(),
this.widget.getExtendSessionField().getValue(),
new AsyncCallback<AuthenticationResponse>() {

@Override
public void onFailure(Throwable caught) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ public void getAllResults(String courseId, final AsyncCallback<StudentInfo[]> ca
delegate.sendRequest(callback, new StatisticsDecoder(), params);
}

public void performAuthentication(String username, String password,
public void performAuthentication(String username, String password, Boolean extendSession,
final AsyncCallback<AuthenticationResponse> callback) {
Delegate<AuthenticationResponse> delegate =
new Delegate<AuthenticationResponse>(eventBus, PERFORM_AUTHENTICATION_URL, false, true);
HashMap<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
params.put("remember_me", extendSession.toString());
delegate.sendRequest(callback, new AuthenticationResponseDecoder(), params);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ro.pub.cs.vmchecker.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.http.client.UrlBuilder;
Expand All @@ -14,8 +15,10 @@
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
Expand Down Expand Up @@ -56,7 +59,10 @@ interface LoginWidgetUiBinder extends UiBinder<Widget, LoginWidget> {

@UiField
PasswordTextBox passwordField;


@UiField
CheckBox extendSessionField;

@UiField
Label passwordComment;

Expand Down Expand Up @@ -94,8 +100,17 @@ public LoginWidget() {
loginDescription.setHTML(constants.loginDescription());
formComment.setText(constants.formComment());
formLabel.setText(constants.loginFormLabel());
formLabel.setWordWrap(false);
/* Dynamically adjust formLabel width based on client rendering width of the string. */
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
formLabel.setWidth(Integer.toString(formLabel.getElement().getOffsetWidth()) + "px");
}
});
usernameLabel.setText(constants.usernameLabel());
passwordLabel.setText(constants.passwordLabel());
extendSessionField.setText(constants.extendSessionLabel());
usernameComment.setVisible(false);
passwordComment.setVisible(false);
loginComment.setVisible(false);
Expand All @@ -107,6 +122,11 @@ public void execute() {
}


@Override
public HasValue<Boolean> getExtendSessionField() {
return extendSessionField;
}

@Override
public HasClickHandlers getLoginButton() {
return loginButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@
padding: 3px 15px 3px 3px;
}

.inputField {
background-color: #E9EEF1;
.inputField, .checkboxField {
font-size: 13px;
}

.checkboxField {
text-align: right;
}

.checkboxLine {
padding: 10px 0px 0px 40px;
}

.inputField {
width: 150px;
background-color: #E9EEF1;
border: 1px solid #CBCBCB;
}

Expand Down Expand Up @@ -103,7 +114,11 @@
</g:HorizontalPanel>
<g:Label ui:field="passwordComment" styleName="{style.fieldComment} {style.errorComment}"></g:Label>
<g:Label ui:field="formComment" styleName="{style.fieldComment} {style.infoComment}"></g:Label>
<g:HorizontalPanel verticalAlignment="ALIGN_MIDDLE" styleName="{style.checkboxLine}">
<g:CheckBox ui:field="extendSessionField" styleName="{style.inputLine} {style.checkboxField}"></g:CheckBox>
</g:HorizontalPanel>
<g:Label ui:field="loginComment" styleName="{style.fieldComment} {style.errorComment}"></g:Label>
<g:HTML><br/></g:HTML>
<g:Button ui:field="loginButton" styleName="{style.loginButton}">Login</g:Button>
</g:FlowPanel>
</g:HorizontalPanel>
Expand Down

0 comments on commit 2cf2a90

Please sign in to comment.