Subversion Repositories eFlore/Applications.coel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 1
package org.tela_botanica.client.composants;
2
 
3
/*
4
 * Ext GWT - Ext for GWT
5
 * Copyright(c) 2007, 2008, Ext JS, LLC.
6
 * licensing@extjs.com
7
 *
8
 * http://extjs.com/license
9
 */
61 jpm 10
import org.tela_botanica.client.Mediateur;
11
import org.tela_botanica.client.RegistreId;
12
import org.tela_botanica.client.modeles.Utilisateur;
13
 
14
import com.extjs.gxt.ui.client.Registry;
60 jpm 15
import com.extjs.gxt.ui.client.event.ButtonEvent;
16
import com.extjs.gxt.ui.client.event.ComponentEvent;
17
import com.extjs.gxt.ui.client.event.KeyListener;
18
import com.extjs.gxt.ui.client.event.SelectionListener;
61 jpm 19
import com.extjs.gxt.ui.client.fx.FxConfig;
60 jpm 20
import com.extjs.gxt.ui.client.widget.Dialog;
21
import com.extjs.gxt.ui.client.widget.button.Button;
22
import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;
23
import com.extjs.gxt.ui.client.widget.form.TextField;
24
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
25
import com.google.gwt.user.client.Timer;
26
 
27
public class IdentificationFenetre extends Dialog {
28
 
61 jpm 29
	protected StatusButtonBar buttonBar;
30
	protected TextField<String> userName;
31
	protected TextField<String> password;
32
	protected Button reset;
33
	protected Button login;
60 jpm 34
 
61 jpm 35
	public IdentificationFenetre() {
36
		FormLayout layout = new FormLayout();
37
		layout.setLabelWidth(90);
38
		layout.setDefaultWidth(155);
39
		setLayout(layout);
60 jpm 40
 
61 jpm 41
		setButtons("");
42
		setIconStyle("user");
43
		setHeading("Collections en ligne - Identification");
44
		setModal(true);
45
		setBodyBorder(true);
46
		setBodyStyle("padding: 10px;background: none");
64 jpm 47
		setWidth(310);
61 jpm 48
		setResizable(false);
64 jpm 49
		setAutoWidth(false);
50
 
61 jpm 51
		KeyListener keyListener = new KeyListener() {
52
			public void componentKeyUp(ComponentEvent event) {
53
				validate();
54
			}
60 jpm 55
 
61 jpm 56
		};
60 jpm 57
 
61 jpm 58
		userName = new TextField<String>();
59
		userName.setMinLength(4);
60
		userName.setFieldLabel("Courriel");
61
		userName.addKeyListener(keyListener);
62
		add(userName);
60 jpm 63
 
61 jpm 64
		password = new TextField<String>();
65
		password.setMinLength(4);
66
		password.setPassword(true);
67
		password.setFieldLabel("Mot de passe");
68
		password.addKeyListener(keyListener);
69
		add(password);
60 jpm 70
 
61 jpm 71
		setFocusWidget(userName);
60 jpm 72
 
61 jpm 73
		buttonBar = new StatusButtonBar();
74
		setButtonBar(buttonBar);
75
 
76
	}
60 jpm 77
 
61 jpm 78
	@Override
79
	protected void createButtons() {
80
		reset = new Button("Réinitialiser");
81
		reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
82
			public void componentSelected(ButtonEvent ce) {
83
				userName.reset();
84
				password.reset();
85
				validate();
86
				userName.focus();
87
			}
60 jpm 88
 
61 jpm 89
		});
60 jpm 90
 
61 jpm 91
		login = new Button("Valider");
92
		//login.disable(); // Par défaut : dois être en mode disable
93
		login.addSelectionListener(new SelectionListener<ButtonEvent>() {
94
			public void componentSelected(ButtonEvent ce) {
95
				onSubmit();
96
			}
97
		});
60 jpm 98
 
61 jpm 99
		buttonBar.add(reset);
100
		buttonBar.add(login);
101
	}
60 jpm 102
 
61 jpm 103
	protected void onSubmit() {
104
		buttonBar.getStatusBar().showBusy("Chargement en cours ...");
105
		buttonBar.disable();
106
		Timer t = new Timer() {
60 jpm 107
 
61 jpm 108
			@Override
109
			public void run() {
110
				IdentificationFenetre.this.hide();
65 jpm 111
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).connecterUtilisateur(userName.getValue(), password.getValue());
61 jpm 112
			}
60 jpm 113
 
61 jpm 114
		};
115
		t.schedule(2);// Par défaut : 2000
116
	}
60 jpm 117
 
61 jpm 118
	protected boolean hasValue(TextField<String> field) {
119
		return field.getValue() != null && field.getValue().length() > 0;
120
	}
60 jpm 121
 
61 jpm 122
	protected void validate() {
123
		login.setEnabled(hasValue(userName) && hasValue(password) && password.getValue().length() > 3);
124
	}
125
 
60 jpm 126
}