| 60 |
jpm |
1 |
package org.tela_botanica.client.composants;
|
|
|
2 |
|
| 358 |
jp_milcent |
3 |
import org.tela_botanica.client.ComposantId;
|
| 61 |
jpm |
4 |
import org.tela_botanica.client.Mediateur;
|
|
|
5 |
import org.tela_botanica.client.RegistreId;
|
| 358 |
jp_milcent |
6 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
7 |
import org.tela_botanica.client.modeles.Information;
|
|
|
8 |
import org.tela_botanica.client.modeles.Utilisateur;
|
| 61 |
jpm |
9 |
|
|
|
10 |
import com.extjs.gxt.ui.client.Registry;
|
| 60 |
jpm |
11 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
12 |
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
|
13 |
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
|
14 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
| 358 |
jp_milcent |
15 |
import com.extjs.gxt.ui.client.util.Format;
|
|
|
16 |
import com.extjs.gxt.ui.client.util.Params;
|
| 60 |
jpm |
17 |
import com.extjs.gxt.ui.client.widget.Dialog;
|
| 358 |
jp_milcent |
18 |
import com.extjs.gxt.ui.client.widget.HtmlContainer;
|
| 60 |
jpm |
19 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
20 |
import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;
|
|
|
21 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
22 |
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
| 358 |
jp_milcent |
23 |
import com.google.gwt.core.client.GWT;
|
| 60 |
jpm |
24 |
|
| 358 |
jp_milcent |
25 |
public class IdentificationFenetre extends Dialog implements Rafraichissable {
|
| 60 |
jpm |
26 |
|
| 66 |
jpm |
27 |
protected StatusButtonBar barreDeBoutons;
|
|
|
28 |
protected TextField<String> login;
|
|
|
29 |
protected TextField<String> motDePasse;
|
|
|
30 |
protected Button reinitialiserBouton;
|
|
|
31 |
protected Button validerBouton;
|
| 358 |
jp_milcent |
32 |
private Button annulerBouton;
|
|
|
33 |
private String zoneInfoTpl;
|
|
|
34 |
private HtmlContainer zoneInfoHtml;
|
| 60 |
jpm |
35 |
|
| 61 |
jpm |
36 |
public IdentificationFenetre() {
|
|
|
37 |
FormLayout layout = new FormLayout();
|
| 358 |
jp_milcent |
38 |
layout.setLabelWidth(110);
|
|
|
39 |
layout.setDefaultWidth(220);
|
| 61 |
jpm |
40 |
setLayout(layout);
|
| 60 |
jpm |
41 |
|
| 61 |
jpm |
42 |
setButtons("");
|
| 69 |
jpm |
43 |
setIconStyle("icone-utilisateur");
|
| 61 |
jpm |
44 |
setHeading("Collections en ligne - Identification");
|
|
|
45 |
setModal(true);
|
|
|
46 |
setBodyBorder(true);
|
|
|
47 |
setBodyStyle("padding: 10px;background: none");
|
| 358 |
jp_milcent |
48 |
setWidth(450);
|
| 61 |
jpm |
49 |
setResizable(false);
|
| 64 |
jpm |
50 |
setAutoWidth(false);
|
|
|
51 |
|
| 61 |
jpm |
52 |
KeyListener keyListener = new KeyListener() {
|
|
|
53 |
public void componentKeyUp(ComponentEvent event) {
|
|
|
54 |
validate();
|
|
|
55 |
}
|
| 60 |
jpm |
56 |
|
| 61 |
jpm |
57 |
};
|
| 60 |
jpm |
58 |
|
| 358 |
jp_milcent |
59 |
zoneInfoHtml = new HtmlContainer();
|
|
|
60 |
zoneInfoTpl = "<div id='"+ComposantId.DIV_IDENTIFICATION_MSG+"'>{0}</div>";
|
|
|
61 |
//zoneInfoHtml.setHtml(Format.substitute(zoneInfoTpl, (new Params()).add("")));
|
|
|
62 |
zoneInfoHtml.hide();
|
|
|
63 |
add(zoneInfoHtml);
|
|
|
64 |
|
| 66 |
jpm |
65 |
login = new TextField<String>();
|
|
|
66 |
login.setMinLength(4);
|
|
|
67 |
login.setFieldLabel("Courriel");
|
|
|
68 |
login.addKeyListener(keyListener);
|
|
|
69 |
add(login);
|
| 60 |
jpm |
70 |
|
| 66 |
jpm |
71 |
motDePasse = new TextField<String>();
|
|
|
72 |
motDePasse.setMinLength(4);
|
|
|
73 |
motDePasse.setPassword(true);
|
|
|
74 |
motDePasse.setFieldLabel("Mot de passe");
|
|
|
75 |
motDePasse.addKeyListener(keyListener);
|
|
|
76 |
add(motDePasse);
|
| 60 |
jpm |
77 |
|
| 66 |
jpm |
78 |
setFocusWidget(login);
|
| 60 |
jpm |
79 |
|
| 66 |
jpm |
80 |
barreDeBoutons = new StatusButtonBar();
|
|
|
81 |
setButtonBar(barreDeBoutons);
|
| 61 |
jpm |
82 |
|
|
|
83 |
}
|
| 277 |
jp_milcent |
84 |
|
| 61 |
jpm |
85 |
@Override
|
|
|
86 |
protected void createButtons() {
|
| 66 |
jpm |
87 |
reinitialiserBouton = new Button("Réinitialiser");
|
|
|
88 |
reinitialiserBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
| 61 |
jpm |
89 |
public void componentSelected(ButtonEvent ce) {
|
| 66 |
jpm |
90 |
login.reset();
|
|
|
91 |
motDePasse.reset();
|
| 61 |
jpm |
92 |
validate();
|
| 66 |
jpm |
93 |
login.focus();
|
| 61 |
jpm |
94 |
}
|
| 60 |
jpm |
95 |
|
| 61 |
jpm |
96 |
});
|
| 60 |
jpm |
97 |
|
| 66 |
jpm |
98 |
validerBouton = new Button("Valider");
|
| 358 |
jp_milcent |
99 |
validerBouton.disable(); // Par défaut : dois être en mode disable
|
| 66 |
jpm |
100 |
validerBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
| 61 |
jpm |
101 |
public void componentSelected(ButtonEvent ce) {
|
|
|
102 |
onSubmit();
|
|
|
103 |
}
|
|
|
104 |
});
|
| 358 |
jp_milcent |
105 |
|
|
|
106 |
annulerBouton = new Button("Annuler");
|
|
|
107 |
annulerBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
108 |
public void componentSelected(ButtonEvent ce) {
|
|
|
109 |
close();
|
|
|
110 |
}
|
|
|
111 |
});
|
| 60 |
jpm |
112 |
|
| 358 |
jp_milcent |
113 |
|
| 66 |
jpm |
114 |
barreDeBoutons.add(reinitialiserBouton);
|
| 358 |
jp_milcent |
115 |
barreDeBoutons.add(annulerBouton);
|
| 66 |
jpm |
116 |
barreDeBoutons.add(validerBouton);
|
| 61 |
jpm |
117 |
}
|
| 60 |
jpm |
118 |
|
| 61 |
jpm |
119 |
protected void onSubmit() {
|
| 358 |
jp_milcent |
120 |
barreDeBoutons.getStatusBar().showBusy("Vérification...");
|
| 66 |
jpm |
121 |
barreDeBoutons.disable();
|
| 358 |
jp_milcent |
122 |
//IdentificationFenetre.this.hide();
|
|
|
123 |
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).connecterUtilisateur(login.getValue(), motDePasse.getValue());
|
| 61 |
jpm |
124 |
}
|
| 60 |
jpm |
125 |
|
| 61 |
jpm |
126 |
protected boolean hasValue(TextField<String> field) {
|
|
|
127 |
return field.getValue() != null && field.getValue().length() > 0;
|
|
|
128 |
}
|
| 60 |
jpm |
129 |
|
| 61 |
jpm |
130 |
protected void validate() {
|
| 66 |
jpm |
131 |
validerBouton.setEnabled(hasValue(login) && hasValue(motDePasse) && motDePasse.getValue().length() > 3);
|
| 61 |
jpm |
132 |
}
|
| 277 |
jp_milcent |
133 |
|
| 358 |
jp_milcent |
134 |
public void rafraichir(Object nouvelleDonnees) {
|
|
|
135 |
if (nouvelleDonnees instanceof Information) {
|
|
|
136 |
Information info = (Information) nouvelleDonnees;
|
|
|
137 |
if (info.getType().equals("maj_utilisateur")) {
|
|
|
138 |
Utilisateur utilisateurCourant = ((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT));
|
|
|
139 |
if (utilisateurCourant.isIdentifie() == false) {
|
|
|
140 |
barreDeBoutons.getStatusBar().clear();
|
|
|
141 |
barreDeBoutons.enable();
|
|
|
142 |
validate();
|
|
|
143 |
zoneInfoHtml.setHtml(Format.substitute(zoneInfoTpl, (new Params()).add("Mauvais login ou mot de passe")));
|
|
|
144 |
zoneInfoHtml.show();
|
|
|
145 |
layout();
|
|
|
146 |
} else {
|
|
|
147 |
hide();
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
} else {
|
|
|
151 |
GWT.log("Ce type d'objet n'est pas pris en compte par la méthode rafraichir de la classe "+getClass(), null);
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
|
| 60 |
jpm |
156 |
}
|