2 * Basic IView implementation for displaying the test results list, by collection.
4 * This component creates a Table object and feed it with the results. It adds a collection chooser to its viewPane header.
6 * It creates the following commands : "loadtestlist", "polllistloading", "opentest", "download", "copytocollection", "deletetest".
8 qx
.Class
.define("org.argeo.slc.web.TestList",
10 extend
: qx
.ui
.container
.Composite
,
11 implement
: [org
.argeo
.ria
.components
.IView
],
12 include
: [org
.argeo
.ria
.session
.MPrefHolder
],
16 "slc.web.TestList.DefaultAction" : {
17 label
: "Test List : Double Click default action",
19 list
: ["Open","Download Xls"],
25 construct : function(){
26 this.base(arguments
, new qx
.ui
.layout
.VBox());
27 var model
= new qx
.ui
.table
.model
.Simple();
28 model
.setColumns(["Test Case", "Date"]);
29 this.table
= new qx
.ui
.table
.Table(model
, {
30 tableColumnModel: function(obj
){
31 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
39 * The viewPane containing this applet.
46 check
:"org.argeo.ria.components.ViewSelection"
48 instanceId
: {init
:""},
49 instanceLabel
: {init
:""},
51 * The load list of available collection (Map of ids => labels)
58 * The current collection id selected.
61 init
: 'My Collection',
64 currentOpenInstanceId
: {
69 * The applet commands.
74 label
: "Load Collection",
75 icon
: "org/argeo/slc/ria/view-refresh.png",
76 shortcut
: "Control+l",
79 toolbar
: "collection",
80 callback : function(e
){
87 icon
: "org/argeo/slc/ria/document-open-recent.png",
88 shortcut
: "Control+l",
92 toolbar
: "collection",
93 callback : function(event
){
94 this.pollListLoading(event
.getTarget().getUserData("slc.command.toggleState"));
99 "copyfullcollection" : {
100 label : "Copy to...",
101 icon : "org/argeo/slc/ria/edit-copy.png",
105 toolbar : "collection",
106 callback : function(e){
107 // Call service to copy
110 submenuCallback : function(commandId){
111 this.copySelectionToCollection(commandId, "current_collection");
114 // Call at command creation
115 org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){
116 if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){
117 var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent();
118 testList.collectionListToMenu(this);
127 icon
: "org/argeo/slc/ria/media-playback-start.png",
128 shortcut
: "Control+o",
131 toolbar
: "selection",
132 callback : function(e
){
133 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
134 var classObj
= org
.argeo
.slc
.ria
.Applet
;
135 var xmlNodes
= viewsManager
.getViewPaneSelection("list").getNodes();
136 var iView
= viewsManager
.initIViewClass(classObj
, "applet", xmlNodes
[0]);
137 this.setCurrentOpenInstanceId(iView
.getInstanceId());
138 iView
.load(xmlNodes
[0]);
140 selectionChange : function(viewId
, xmlNodes
){
141 if(viewId
!= "list") return;
142 this.setEnabled(false);
143 if(xmlNodes
== null || !xmlNodes
.length
) return;
144 this.setEnabled(true);
149 label
: "Download as...",
150 icon
: "org/argeo/slc/ria/go-down.png",
154 toolbar
: "selection",
155 callback : function(e
){ },
158 {'label':"Xsl", 'icon':'org/argeo/slc/ria/mime-xsl.png', 'commandId':'xsl'},
159 {'label':"Xml", 'icon':'org/argeo/slc/ria/mime-xml.png', 'commandId':'xml'},
160 {'label':"Excel", 'icon':'org/argeo/slc/ria/mime-xls.png', 'commandId':'xls'},
161 {'label':"Pdf", 'icon':'org/argeo/slc/ria/mime-pdf.png', 'commandId':'pdf'}
163 submenuCallback : function(commandId
){
164 var uuid
= this.extractTestUuid();
166 xsl
: "resultView.xslt",
167 xml
: "resultViewXml.xslt",
168 xls
: "resultView.xls",
169 pdf
: "resultView.pdf"
171 var url
= org
.argeo
.slc
.ria
.SlcApi
.DEFAULT_CONTEXT
+ "/"+urls
[commandId
]+"?uuid="+uuid
;
172 if(commandId
== "xls" || commandId
== "pdf"){
173 document
.location
.href
= url
;
175 var win
= window
.open(url
);
178 selectionChange : function(viewId
, xmlNodes
){
179 if(viewId
!="list")return;
181 this.setEnabled(false);
182 if(xmlNodes
== null || !xmlNodes
.length
) return;
183 this.setEnabled(true);
187 label
: "Attachments",
188 icon
: "org/argeo/slc/ria/document-save-as.png",
192 toolbar
: "selection",
193 callback : function(e
){ },
196 submenuCallback : function(commandId
){
197 var split
= commandId
.split("__commandseparator__");
199 var contentType
= split
[1];
201 var url
= org
.argeo
.slc
.ria
.SlcApi
.buildGetAttachmentUrl(uuid
, contentType
, name
);
202 var win
= window
.open(url
);
204 selectionChange : function(viewId
, xmlNodes
){
205 if(viewId
!="list")return;
207 this.setEnabled(false);
208 if(xmlNodes
== null || !xmlNodes
.length
|| xmlNodes
.length
!= 1) return;
209 // Check slc:simple-attachment tags
210 var attachs
= org
.argeo
.ria
.util
.Element
.selectNodes(xmlNodes
[0], "slc:attachments/slc:simple-attachment");
211 if(attachs
&& attachs
.length
){
213 for(var i
=0;i
<attachs
.length
;i
++){
214 var uuid
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:uuid");
215 var contentType
= (org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:content-type")||'');
216 var name
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(attachs
[i
], "slc:name");
219 icon
: 'org.argeo.slc.ria/mime-text-plain.png',
220 commandId
:uuid
+'__commandseparator__'+contentType
+'__commandseparator__'+name
223 this.setMenuDef(submenus
);
224 this.setEnabled(true);
228 "copytocollection" : {
229 label
: "Copy to...",
230 icon
: "org/argeo/slc/ria/edit-copy.png",
231 shortcut
: "Control+c",
234 toolbar
: "selection",
235 callback : function(e
){
236 // Call service to copy
239 submenuCallback : function(commandId
){
240 this.copySelectionToCollection(commandId
, "current_selection");
243 // Call at command creation
244 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
245 if(event
.getDataType() == "collection" || event
.getDataType() == "test_cases"){
246 var testList
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("list").getContent();
247 testList
.collectionListToMenu(this, true);
251 selectionChange : function(viewId
, xmlNodes
){
252 if(viewId
!= "list") return;
253 this.setEnabled(false);
254 if(xmlNodes
== null || !xmlNodes
.length
) return;
255 this.setEnabled(true);
261 icon
: "org/argeo/slc/ria/edit-delete.png",
262 shortcut
: "Control+d",
265 toolbar
: "selection",
266 callback : function(e
){
267 var modal
= new org
.argeo
.ria
.components
.Modal("Confirm", null);
268 var testUuid
= this.extractTestUuid();
269 modal
.addConfirm("Are you sure you want to delete<br> test " + testUuid
+ "?");
270 modal
.addListener("ok", function(){
271 var request
= org
.argeo
.slc
.ria
.SlcApi
.getRemoveResultService(this.getCollectionId(), this.extractTestUuid());
272 request
.addListener("completed", function(response
){
273 if(this.getCurrentOpenInstanceId() == "test:"+testUuid
){
274 var appletView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("applet");
275 if(appletView
.contentExists(this.getCurrentOpenInstanceId())){
276 appletView
.closeCurrent();
278 this.setCurrentOpenInstanceId(null);
280 this.loadCollections();
282 this.info("Test was successfully deleted");
286 modal
.attachAndShow();
288 selectionChange : function(viewId
, xmlNodes
){
289 if(viewId
!= "list") return;
290 this.setEnabled(false);
291 if(xmlNodes
== null || !xmlNodes
.length
) return;
292 this.setEnabled(true);
301 init : function(viewPane
, data
){
302 this.setView(viewPane
);
303 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
307 statusBarVisible
: false,
308 showCellFocusIndicator
:false,
309 columnVisibilityButtonVisible
:false,
310 contextMenu
: org
.argeo
.ria
.event
.CommandsManager
.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]),
311 decorator
: new qx
.ui
.decoration
.Background("#fff")
313 var viewPane
= this.getView();
314 this.table
.addListener("dblclick", function(e
){
315 var pref
= this.getRiaPreferenceValue("slc.web.TestList.DefaultAction");
317 org
.argeo
.ria
.event
.CommandsManager
.getInstance().executeCommand("opentest");
319 var uuid
= this.extractTestUuid();
320 var url
= "../resultView.xslt?uuid="+uuid
;
321 alert('Should download : '+url
);
324 var columnModel
= this.table
.getTableColumnModel();
325 columnModel
.getBehavior().setWidth(0, "60%");
326 var renderer
= new org
.argeo
.slc
.web
.XmlRenderer();
327 columnModel
.setDataCellRenderer(0, renderer
);
328 columnModel
.setDataCellRenderer(1, renderer
);
330 this.table
.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e
){
331 var viewSelection
= this.getViewSelection();
332 viewSelection
.clear();
333 var selectionModel
= this.table
.getSelectionManager().getSelectionModel();
334 if(!selectionModel
.getSelectedCount()){
337 var ranges
= this.table
.getSelectionManager().getSelectionModel().getSelectedRanges();
338 var xmlNode
= this.table
.getTableModel().getRowData(ranges
[0].minIndex
);
339 viewSelection
.addNode(xmlNode
);
340 //viewPane.setViewSelection(viewSelection);
343 var select
= new qx
.ui
.form
.SelectBox();
344 this.getView().addHeaderComponent(select
);
345 this.getView().setViewTitle("");
346 this.add(this.table
, {flex
:1});
348 select
.addListener("changeSelection", this.collectionSelectorListener
, this);
350 org
.argeo
.ria
.remote
.RequestManager
.getInstance().addListener("reload", function(event
){
351 if(event
.getDataType()!="collection") return;
352 select
.removeListener("changeSelection", this.collectionSelectorListener
, this);
353 var collectionList
= event
.getContent();
355 for(key
in collectionList
){
356 var item
= new qx
.ui
.form
.ListItem(collectionList
[key
], "org/argeo/slc/ria/folder.png", key
);
358 if(key
== this.getCollectionId()){
359 select
.setSelection([item
]);
362 if(qx
.lang
.Object
.getLength(collectionList
)){
363 var selection
= select
.getSelection();
364 var value
= selection
[0].getModel();
365 this.setCollectionId(value
);
367 select
.addListener("changeSelection", this.collectionSelectorListener
, this);
373 * Use SlcApi to load the available collections.
375 loadCollections : function(){
376 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListCollectionsService();
377 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
378 request
.addListener("completed", function(response
){
379 var xml
= response
.getContent();
380 var collections
= {};
381 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:ref", NSMap
);
382 for(var i
=0;i
<nodes
.length
;i
++){
383 var collId
= qx
.xml
.Element
.getSingleNodeText(nodes
[i
], ".");
384 collections
[collId
] = collId
;
386 this.setCollectionList(collections
);
387 org
.argeo
.ria
.remote
.RequestManager
.getInstance().fireReloadEvent("collection", this.getCollectionList());
389 request
.setAsynchronous(false);
394 * Load the results of the currently selected collection.
396 loadList : function(){
397 var model
= this.table
.getTableModel();
398 model
.removeRows(0, model
.getRowCount());
399 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
400 var request
= org
.argeo
.slc
.ria
.SlcApi
.getListResultsService(this.getCollectionId(), null, [commandManager
.getCommandById("loadtestlist"), this.getView()]);
401 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
402 request
.addListener("completed", function(response
){
403 var xml
= response
.getContent();
404 this.debug("Successfully loaded XML");
405 var nodes
= org
.argeo
.ria
.util
.Element
.selectNodes(xml
, "//slc:result-attributes", NSMap
);
406 //model.addRows(nodes);
408 for(var i
=0; i
<nodes
.length
;i
++){
409 model
.addRows([nodes
[i
]]);
416 * Enable/disable the automatic reloading of the list.
417 * @param state {Boolean} Whether the automatic reloading must be started or stopped.
419 pollListLoading : function(state
){
421 this.timer
= new qx
.event
.Timer(5000);
422 this.timer
.addListener("interval", this.loadList
, this);
433 * Creates a menu gui component from the currently loaded collectionList.
434 * @param command {qx.ui.core.Command} The command on which to attach the created menu.
435 * @param checkSelection {Boolean} Whether at the end, we must check the current viewSelection to enable/disable the command accordingly.
437 collectionListToMenu : function(command
, checkSelection
){
438 command
.setEnabled(false);
439 command
.clearMenus();
440 var collectionList
= this.getCollectionList();
441 if(!collectionList
) return;
443 for(var key
in collectionList
){
444 if(this.getCollectionId() && key
== this.getCollectionId()) continue;
446 "label":collectionList
[key
],
447 "icon":"org/argeo/slc/ria/folder.png",
451 submenus
.push({'separator':true});
452 submenus
.push({"label":"New...", "icon":"org/argeo/slc/ria/folder-new.png", "commandId":"slc.client.create"});
453 command
.setMenuDef(submenus
);
455 var viewSelection
= this.getView().getViewSelection();
456 if(viewSelection
.getCount()) command
.setEnabled(true);
458 command
.setEnabled(true);
462 * Use SlcApi "addResult" service to add selected results to a given collection.
463 * If collectionId is "slc.client.create", first triggers a modal dialog to enter a new collection name, then retrigger itself with the new id.
464 * @param collectionId {String} The id of the destination collection, or "slc.client.create".
465 * @param selectionType {String} "current_collection"|"current_selection". The first adds the whole collection content to the destination, the second only selected results.
467 copySelectionToCollection:function(collectionId
, selectionType
){
468 if(collectionId
== "slc.client.create"){
469 var modal
= new org
.argeo
.ria
.components
.Modal("Create collection", "org/argeo/slc/ria/folder-new.png");
470 modal
.makePromptForm("Enter the new collection name", function(value
){
472 alert("Please enter a name for the new collection!");
476 // Create the collection now, then recall the callback with the new name.
477 this.copySelectionToCollection(value
, selectionType
);
481 modal
.attachAndShow();
485 var currentFocus
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getCurrentFocus();
486 if(currentFocus
.getViewId() == "applet"){
487 alert("Should copy data from the applet - command was " + collectionId
);
491 if(selectionType
== "current_collection"){
492 this.error("Not implemented yet!");
493 }else if(selectionType
== "current_selection"){
495 var request
= org
.argeo
.slc
.ria
.SlcApi
.getAddResultService(collectionId
,this.extractTestUuid());
496 request
.addListener("completed", function(response
){
497 this.info("Result successfully copied to collection!");
498 this.loadCollections();
505 * Utilitary function to extract test unique id from the currently selected node.
506 * @return {String} The test unique id.
508 extractTestUuid: function(){
509 var NSMap
= {slc
:"http://argeo.org/projects/slc/schemas"};
510 var xmlNodes
= this.getView().getViewSelection().getNodes();
511 var uuid
= qx
.dom
.Node
.getText(org
.argeo
.ria
.util
.Element
.selectSingleNode(xmlNodes
[0], "slc:uuid"));
516 * Listener of the collection selector (select box added to the viewpane header).
517 * @param event {qx.event.type.Event} The event.
519 collectionSelectorListener : function(event
){
520 var selection
= event
.getData();
521 this.setCollectionId(selection
[0].getModel());
525 addScroll : function(){
531 this.pollListLoading(false);