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