Subversion Repositories eFlore/Applications.coel

Rev

Rev 60 | Rev 64 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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