f5069240e97ca3fbe0b863de5790d42e59788e21
[samba.git] / swat / apps / swat / source / class / swat / main / Gui.js
1 /**
2  * The graphical user interface for the main menu
3  */
4 qx.OO.defineClass("swat.main.Gui");
5
6
7 qx.Class.buildGui = function(modules)
8 {
9   var o;
10
11   // Header colors
12   var topColor = new qx.renderer.color.Color("#ffff64");
13   var bottomColor = new qx.renderer.color.Color("#3878cd");
14
15   // Create the yellow bar at the top
16   o = new qx.ui.basic.Terminator();
17   o.set({
18             top: 0,
19             left: 0,
20             right: 0,
21             height: 40,
22         });
23   o.setBackgroundColor(topColor);
24   o.addToDocument();
25
26   // Create the tag line
27   var title = new qx.ui.basic.Label("Samba Web Administration Tool");
28   title.set({
29             top: 12,
30             left: 20
31         });
32   title.setBackgroundColor(topColor);
33   title.setFont("bold");
34   title.addToDocument();
35
36   // Create a small black separator between the yellow and blue bars
37   o = new qx.ui.basic.Terminator();
38   o.set({
39             top: 40,
40             left: 0,
41             right: 0,
42             height: 1
43         });
44   o.setBackgroundColor("black");
45   o.addToDocument();
46
47   // Create the yellow bar at the top
48   o = new qx.ui.basic.Terminator();
49   o.set({
50             top: 41,
51             left: 0,
52             right: 0,
53             height: 60
54         });
55   o.setBackgroundColor(bottomColor);
56   o.addToDocument();
57
58   // Create the "Samba" image
59   o = new qx.ui.basic.Image("../../../images/logo.png");
60   o.set({
61             top: 16,
62             right: 20
63         });
64   o.setZIndex(100000000);
65   o.addToDocument();
66
67   // Create a menu bar
68   var menubar = new qx.ui.toolbar.ToolBar();
69   menubar.set({
70                   top: 100,
71                   height: 20,
72                   left: 0,
73                   right: 0
74               });
75   menubar.addToDocument();
76       
77   // Create a menu item for selecting the requested module 
78   var menubutton = new qx.ui.toolbar.MenuButton("Modules");
79   menubar.add(menubutton);
80
81   // Create a Command to be executed upon any menu selection
82   var command = new qx.client.Command();
83   //  command.addEventListener("execute", fsm.eventListener, fsm);
84       
85   // Create a radio manager for selecting one of the modules
86   var moduleManager = new qx.manager.selection.RadioManager("main.gui.Module");
87
88   // Create a menu containing the subitems
89   var menu = new qx.ui.menu.Menu();
90
91   // We'll also track the current module's canvas in the modules object
92   modules.currentCanvas = null;
93
94   // For each menu item...
95   for (moduleName in modules.list)
96   {
97     // create a radio button menu item
98     o = new qx.ui.menu.RadioButton(moduleName, null, command);
99
100     // Associate this button menu item with the module list
101     o.moduleName = moduleName;
102
103     // Associate the menu item with the radio manager
104     moduleManager.add(o);
105
106     // Create this module's canvas
107     var canvas = new qx.ui.layout.CanvasLayout();
108     canvas.set({
109                    top: 120,
110                    bottom: 0,
111                    left: 0,
112                    right: 0
113                });
114     canvas.setBackgroundColor("white");
115     canvas.setDisplay(false); // initially not displayed
116
117     var fsm = modules.list[moduleName].fsm;
118     fsm.addObject("swat.module.canvas", canvas);
119     canvas.addEventListener("appear", fsm.eventListener, fsm);
120     canvas.addEventListener("disappear", fsm.eventListener, fsm);
121
122     // Save the canvas
123     modules.list[moduleName].canvas = canvas;
124
125     // Add the canvas to the document
126     canvas.addToDocument();
127
128     // When a Module menu item is selected:
129     o.addEventListener("changeChecked", function(e)
130                        {
131                          // If there's a current canvas, ...
132                          if (modules.currentCanvas)
133                          {
134                            // ... then remove display of it.
135                            modules.currentCanvas.setDisplay(false);
136                            
137                            // Dispatch an event on the canvas to notify old
138                            // module it's coming into disuse.
139                            canvas.createDispatchEvent("disappear");
140                          }
141
142                          // If we are being selected...
143                          if (e.getData())
144                          {
145                            // then display our canvas
146                            var canvas = modules.list[this.moduleName].canvas;
147                            canvas.setDisplay(true);
148
149                            // Track the current canvas (now ours)
150                            modules.currentCanvas = canvas;
151
152                            // Set the application title
153                            title.setHtml("<span>" +
154                                          "Samba Web Administration Tool" +
155                                          " &raquo; " +
156                                          this.moduleName +
157                                          "</span>");
158                            
159                            // Dispatch an event on the canvas to notify new
160                            // module it's coming into use.
161                            canvas.createDispatchEvent("appear");
162                          }
163                        });
164
165     // Add the menu item to the menu
166     menu.add(o);
167   }
168
169   // We've built a complete menu.  Add it to the document.
170   menu.addToDocument();
171
172   // Specify that the menu is to be displayed upon menu button selection
173   menubutton.setMenu(menu);
174
175   // Create a menu item for selecting debug options
176   var menubutton = new qx.ui.toolbar.MenuButton("Debug");
177   menubar.add(menubutton);
178
179   // Create a menu containing the subitems
180   var menu = new qx.ui.menu.Menu;
181   var menu_01 = new qx.ui.menu.Button("Show Debug Window", null, command);
182   menu.add(menu_01);
183   menu.addToDocument();
184
185   // Specify that the menu is to be displayed upon menu button selection
186   menubutton.setMenu(menu);
187
188 };