r20600: Web Application Framework
[ira/wip.git] / webapps / swat / source / class / swat / main / Authenticate.js
1 /*
2  * Copyright:
3  *   (C) 2007 by Derrell Lipman
4  *       All rights reserved
5  *
6  * License:
7  *   LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
8  */
9
10 /**
11  * Swat authentication window class
12  */
13 qx.OO.defineClass("swat.main.Authenticate", qx.ui.window.Window,
14 function(module)
15 {
16   var o;
17   var fsm = module.fsm;
18
19   qx.ui.window.Window.call(this);
20
21   var addCaptionedWidget = function(caption, dest, addWidget)
22   {
23     // Add a row to the destination grid
24     dest.addRow();
25     var row = dest.getRowCount() - 1;
26     dest.setRowHeight(row, 24);
27
28     // Add the caption
29     var o = new qx.ui.basic.Label(caption);
30     dest.add(o, 0, row);
31
32     // Add the widget
33     o = addWidget();
34     o.setHeight(24);
35     dest.add(o, 1, row);
36
37     // Give 'em the varying data label
38     return o;
39   };
40
41
42   // Set characteristics of this window
43   this.set({
44              width         : 380,
45              height        : 200,
46              modal         : true,
47              centered      : true,
48              showClose     : false,
49              showMaximize  : false,
50              showMinimize  : false,
51              showStatusbar : false,
52              allowClose    : false,
53              allowMaximize : false,
54              allowMinimize : false,
55              resizeable    : false,
56              moveable      : false,
57              zIndex        : 10000
58            });
59
60
61   // Create a grid layout
62   var grid = new qx.ui.layout.GridLayout();
63   grid.setLocation(14, 14);
64   grid.setDimension("90%", "90%");
65   grid.setVerticalSpacing(14);
66   grid.setPadding(14, 14);
67   grid.setRowCount(0);
68   grid.setColumnCount(2);
69   grid.setColumnWidth(0, 100);
70   grid.setColumnWidth(1, 200);
71
72
73   // Add an input box for the user name
74   this.userName = addCaptionedWidget("User Name", grid,
75                                      function()
76                                      {
77                                        return new qx.ui.form.TextField();
78                                      });
79
80   // Add an input box for the password
81   this.password = addCaptionedWidget("Password", grid,
82                                      function()
83                                      {
84                                        return new qx.ui.form.PasswordField();
85                                      });
86
87   // Add an input box for the password
88   this.domain = addCaptionedWidget("Domain", grid,
89                                    function()
90                                    {
91                                      // Create a combo box for for the domain
92                                      var combo = new qx.ui.form.ComboBox();
93                                      combo.setEditable(false);
94                                      return combo;
95                                    });
96
97   // Add a login button
98   this.login = addCaptionedWidget("", grid,
99                                   function()
100                                   {
101                                     return new qx.ui.form.Button("Login");
102                                   });
103
104   // Save this login button since we receive events on it
105   fsm.addObject("login_button", this.login);
106
107   // We want to receive "execute" events on this button
108   this.login.addEventListener("execute", fsm.eventListener, fsm);
109
110   // Add the grid to the window
111   this.add(grid);
112
113   // Add this window to the document
114   this.addToDocument();
115
116   // Save this window object
117   fsm.addObject("login_window", this);
118
119   // We want to receive "complete" events on this button (which we generate)
120   this.addEventListener("complete", fsm.eventListener, fsm);
121 });
122
123
124
125 qx.Proto.setInfo = function(info)
126 {
127   this.debug(info);
128
129   // Remove everythingn from the domain list
130   this.domain.removeAll();
131
132   // Add the available domains
133   for (var i = 0; i < info.length; i++)
134   {
135     var item = new qx.ui.form.ListItem(info[i]);
136     this.domain.add(item);
137   }
138 };
139
140
141 /**
142  * Singleton Instance Getter
143  */
144 qx.Class.getInstance = function(module)
145 {
146   if (! this._instance)
147   {
148     this._instance = new this(module);
149   }
150
151   return this._instance;
152 };