Subversion Repositories eFlore/Applications.coel

Rev

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