]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/slc/web/event/CommandsManager.js
a03a087dd6c9794fb41569b3e702e7bd65b321bf
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / slc / web / event / CommandsManager.js
1 /**
2 * @author Charles
3 *
4 */
5 qx.Class.define("org.argeo.slc.web.event.CommandsManager",
6 {
7 extend : qx.core.Object,
8
9 construct : function(application){
10 this.base(arguments);
11 this.application = application;
12 },
13
14 properties :
15 {
16 definitions : {
17 init : {
18 "loadtestlist" : {
19 label : "Load Tests",
20 icon : "resource/slc/view-refresh.png",
21 shortcut : "Control+l",
22 enabled : true,
23 menu : "File",
24 toolbar : "list",
25 callback : function(e){
26 this.loadTable("/org.argeo.slc.webapp/resultList.web");
27 },
28 command : null
29 },
30 "stop" : {
31 label : "Stop",
32 icon : "resource/slc/edit-delete.png",
33 shortcut : "Control+s",
34 enabled : false,
35 menu : null,
36 toolbar : "list",
37 callback : function(e){},
38 command : null
39 },
40 "quit" : {
41 label : "Quit",
42 icon : "resource/slc/system-shutdown.png",
43 shortcut : "Control+q",
44 enabled : true,
45 menu : "File",
46 toolbar : false,
47 callback : function(e){},
48 command : null
49 },
50 "opentest" : {
51 label : "Open",
52 icon : "resource/slc/document-open.png",
53 shortcut : "Control+o",
54 enabled : false,
55 menu : "Test",
56 toolbar : "test",
57 callback : function(e){
58 var xmlNodes = this.getSelectionForView("list").getNodes();
59 this.createTestApplet(xmlNodes[0]);
60 },
61 selectionChange : function(viewId, xmlNodes){
62 if(viewId != "list") return;
63 this.setEnabled(false);
64 if(xmlNodes == null || !xmlNodes.length) return;
65 var applet = org.argeo.slc.web.util.Element.selectSingleNode(xmlNodes[0],'report[@type="applet"]');
66 if(applet != null && qx.dom.Node.getText(applet) != ""){
67 this.setEnabled(true);
68 }
69 },
70 command : null
71 },
72 "download" : {
73 label : "Download as...",
74 icon : "resource/slc/go-down.png",
75 shortcut : null,
76 enabled : false,
77 menu : "Test",
78 toolbar : "test",
79 callback : function(e){ },
80 command : null,
81 submenu : {},
82 submenuCallback : function(commandId){
83 var xmlNodes = this.getSelectionForView("list").getNodes();
84 // Single selection
85 var uuid = qx.xml.Element.getSingleNodeText(xmlNodes[0], 'param[@name="uuid"]');
86 var urls = {
87 xsl : "resultView.xslt",
88 xml : "resultViewXml.xslt",
89 xls : "resultView.xls",
90 pdf : "resultView.pdf"
91 };
92 var url = "../"+urls[commandId]+"?uuid="+uuid;
93 if(commandId == "xls" || commandId == "pdf"){
94 document.location.href = url;
95 }else{
96 var win = window.open(url);
97 }
98 },
99 selectionChange : function(viewId, xmlNodes){
100 if(viewId!="list")return;
101 this.clearMenus();
102 this.setEnabled(false);
103 if(xmlNodes == null) return;
104
105 var reports = qx.xml.Element.selectNodes(xmlNodes[0],'report[@type="download"]');
106 if(reports == null || !reports.length)return;
107
108 for(var i=0; i<reports.length;i++){
109 var report = reports[i];
110 this.addSubMenuButton(
111 qx.dom.Node.getText(report),
112 qx.dom.Node.getText(org.argeo.slc.web.util.Element.selectSingleNode(report, "@icon")),
113 qx.dom.Node.getText(org.argeo.slc.web.util.Element.selectSingleNode(report, "@commandid"))
114 );
115 }
116 this.setEnabled(true);
117 this.fireDataEvent("changeMenu", this.getMenu());
118 }
119 },
120 "deletetest" : {
121 label : "Delete",
122 icon : "resource/slc/edit-delete.png",
123 shortcut : "Control+d",
124 enabled : false,
125 menu : "Test",
126 toolbar : "test",
127 callback : function(e){
128 // Call service to delete
129 },
130 command : null
131 },
132 "copytocollection" : {
133 label : "Copy to...",
134 icon : "resource/slc/edit-copy.png",
135 shortcut : "Control+c",
136 enabled : false,
137 menu : "Test",
138 toolbar : "test",
139 callback : function(e){
140 // Call service to copy
141 },
142 command : null
143 },
144 "log" : {
145 label : "Toggle Console",
146 icon : "resource/slc/help-contents.png",
147 shortcut : "",
148 enabled : true,
149 menu : "Help",
150 toolbar : false,
151 callback : function(e){
152 qx.log.appender.Console.toggle();
153 },
154 command : null
155 },
156 "help" : {
157 label : "About...",
158 icon : "resource/slc/help-about.png",
159 shortcut : "Control+h",
160 enabled : true,
161 menu : "Help",
162 toolbar : false,
163 callback : function(e){
164 var wm1 = new qx.ui.window.Window("About SLC");
165 wm1.set({
166 showMaximize : false,
167 showMinimize : false,
168 width: 200,
169 height: 150
170 });
171 wm1.setLayout(new qx.ui.layout.Dock());
172 wm1.add(new qx.ui.basic.Label("SLC is a product from Argeo."), {edge:'center', width:'100%'});
173 var closeButton = new qx.ui.form.Button("Close");
174 closeButton.addListener("execute", function(e){
175 this.hide();
176 this.destroy();
177 }, wm1);
178 wm1.add(closeButton, {edge:'south'});
179 wm1.setModal(true);
180 wm1.center();
181 this.getRoot().add(wm1);
182 wm1.show();
183 },
184 command : null
185 }
186 }
187 }
188 },
189
190 /*
191 *****************************************************************************
192 MEMBERS
193 *****************************************************************************
194 */
195
196 members :
197 {
198 createCommands : function(){
199 this.menus = {};
200 this.toolbars = {};
201 var defs = this.getDefinitions();
202 for(var key in defs){
203 var definition = defs[key];
204 var command = new org.argeo.slc.web.event.Command(key, definition.label, definition.icon, definition.shortcut);
205 if(definition.submenu){
206 var menu = new qx.ui.menu.Menu();
207 command.setMenu(menu);
208 if(definition.submenuCallback){
209 command.setMenuCallback(definition.submenuCallback);
210 command.setMenuContext(this.application);
211 }
212 }
213 command.setEnabled(definition.enabled);
214 command.addListener("execute", definition.callback, this.application);
215 definition.command = command;
216 if(definition.menu){
217 if(!this.menus[definition.menu]) this.menus[definition.menu] = [];
218 this.menus[definition.menu].push(command);
219 }
220 if(definition.toolbar){
221 if(!this.toolbars[definition.toolbar]) this.toolbars[definition.toolbar] = [];
222 this.toolbars[definition.toolbar].push(command);
223 }
224 }
225 this.setDefinitions(defs);
226 },
227
228 refreshCommands : function(viewSelection){
229 var defs = this.getDefinitions();
230 var xmlNodes = null;
231 if(viewSelection.getCount() > 0){
232 var xmlNodes = viewSelection.getNodes();
233 }
234 for(var key in defs){
235 var definition = defs[key];
236 if(!definition.selectionChange) continue;
237 var binded = qx.lang.Function.bind(definition.selectionChange, definition.command);
238 binded(viewSelection.getViewId(), xmlNodes);
239 }
240 },
241 createMenuButtons : function(menuBar){
242 for(var key in this.menus){
243 var menu = new qx.ui.menu.Menu();
244 var button = new qx.ui.menubar.Button(key, null, menu);
245 for(var i=0; i<this.menus[key].length;i++){
246 menu.add(this.menus[key][i].getMenuButton());
247 }
248 menuBar.add(button);
249 }
250
251 },
252 createToolbarParts : function(toolbar){
253 for(var key in this.toolbars){
254 var tPart = new qx.ui.toolbar.Part();
255 toolbar.add(tPart);
256 this.toolbars[key].map(function(command){
257 tPart.add(command.getToolbarButton());
258 });
259 }
260 },
261 createMenuFromIds : function(commandIdsArray){
262 var defs = this.getDefinitions();
263 var contextMenu = new qx.ui.menu.Menu();
264 for(var i=0;i<commandIdsArray.length;i++){
265 var definition = defs[commandIdsArray[i]];
266 var command = definition.command;
267 contextMenu.add(command.getMenuButton());
268 }
269 return contextMenu;
270 },
271 executeCommand : function(commandId){
272 var defs = this.getDefinitions();
273 if(defs[commandId] && defs[commandId].command.getEnabled()){
274 defs[commandId].command.execute();
275 }
276 },
277 getCommandById : function(commandId){
278 var defs = this.getDefinitions();
279 if(defs[commandId] && defs[commandId].command){
280 return defs[commandId].command;
281 }
282 },
283 addToolbarContextMenu : function(toolbar){
284 var menu = new qx.ui.menu.Menu();
285 var icon = new qx.ui.menu.RadioButton("Show Icons");
286 icon.setValue("icon");
287 var text = new qx.ui.menu.RadioButton("Show Text");
288 text.setValue("label");
289 var both = new qx.ui.menu.RadioButton("Show Both");
290 both.setValue("both");
291 var mgr = new qx.ui.form.RadioGroup(icon, text, both);
292 menu.add(icon);
293 menu.add(text);
294 menu.add(both);
295 toolbar.setContextMenu(menu);
296 mgr.addListener("changeValue", function(e){
297 this.setShow(e.getData());
298 }, toolbar);
299
300 }
301 }
302 });