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