/** * Basic IView implementation for displaying the test results list, by collection. * * This component creates a Table object and feed it with the results. It adds a collection chooser to its viewPane header. * * It creates the following commands : "loadtestlist", "polllistloading", "opentest", "download", "copytocollection", "deletetest". */ qx.Class.define("org.argeo.slc.web.TestList", { extend : qx.ui.container.Composite, implement : [org.argeo.ria.components.IView], include : [org.argeo.ria.session.MPrefHolder], statics : { riaPreferences : { "slc.web.TestList.DefaultAction" : { label : "Test List : Double Click default action", type : "list", list : ["Open","Download Xls"], defaultValue : "Open" } } }, construct : function(){ this.base(arguments, new qx.ui.layout.VBox()); var model = new qx.ui.table.model.Simple(); model.setColumns(["Test Case", "Date"]); this.table = new qx.ui.table.Table(model, { tableColumnModel: function(obj){ return new qx.ui.table.columnmodel.Resize(obj) } }); }, properties : { /** * The viewPane containing this applet. */ view : { init : null }, viewSelection : { nullable:false, check:"org.argeo.ria.components.ViewSelection" }, instanceId : {init:""}, instanceLabel : {init:""}, /** * The load list of available collection (Map of ids => labels) */ collectionList : { init : {}, check : "Map" }, /** * The current collection id selected. */ collectionId:{ init : 'My Collection', check : "String" }, /** * The applet commands. */ commands : { init : { "loadtestlist" : { label : "Load Collection", icon : "org.argeo.slc.ria/view-refresh.png", shortcut : "Control+l", enabled : true, menu : "Collection", toolbar : "collection", callback : function(e){ this.loadList(); }, command : null }, "polllistloading" : { label : "Auto load", icon : "org.argeo.slc.ria/document-open-recent.png", shortcut : "Control+l", enabled : true, toggle : true, menu : "Collection", toolbar : "collection", callback : function(event){ this.pollListLoading(event.getTarget().getUserData("slc.command.toggleState")); }, command : null }, /* "copyfullcollection" : { label : "Copy to...", icon : "org.argeo.slc.ria/edit-copy.png", shortcut : null, enabled : false, menu : "Collection", toolbar : "collection", callback : function(e){ // Call service to copy }, submenu : {}, submenuCallback : function(commandId){ this.copySelectionToCollection(commandId, "current_collection"); }, init : function(){ // Call at command creation org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){ if(event.getDataType() == "collection" || event.getDataType() == "test_cases"){ var testList = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("list").getContent(); testList.collectionListToMenu(this); } }, this); }, command : null }, */ "opentest" : { label : "Open", icon : "org.argeo.slc.ria/media-playback-start.png", shortcut : "Control+o", enabled : false, menu : "Selection", toolbar : "selection", callback : function(e){ var viewsManager = org.argeo.ria.components.ViewsManager.getInstance(); var classObj = org.argeo.slc.ria.Applet; var xmlNodes = viewsManager.getViewPaneSelection("list").getNodes(); var iView = viewsManager.initIViewClass(classObj, "applet", xmlNodes[0]); iView.load(xmlNodes[0]); }, selectionChange : function(viewId, xmlNodes){ if(viewId != "list") return; this.setEnabled(false); if(xmlNodes == null || !xmlNodes.length) return; this.setEnabled(true); }, command : null }, "download" : { label : "Download as...", icon : "org.argeo.slc.ria/go-down.png", shortcut : null, enabled : false, menu : "Selection", toolbar : "selection", callback : function(e){ }, command : null, submenu : [ {'label':"Xsl", 'icon':'org.argeo.slc.ria/mime-xsl.png', 'commandId':'xsl'}, {'label':"Xml", 'icon':'org.argeo.slc.ria/mime-xml.png', 'commandId':'xml'}, {'label':"Excel", 'icon':'org.argeo.slc.ria/mime-xls.png', 'commandId':'xls'}, {'label':"Pdf", 'icon':'org.argeo.slc.ria/mime-pdf.png', 'commandId':'pdf'} ], submenuCallback : function(commandId){ var uuid = this.extractTestUuid(); var urls = { xsl : "resultView.xslt", xml : "resultViewXml.xslt", xls : "resultView.xls", pdf : "resultView.pdf" }; var url = "../"+urls[commandId]+"?uuid="+uuid; if(commandId == "xls" || commandId == "pdf"){ document.location.href = url; }else{ var win = window.open(url); } }, selectionChange : function(viewId, xmlNodes){ if(viewId!="list")return; //this.clearMenus(); this.setEnabled(false); if(xmlNodes == null || !xmlNodes.length) return; this.setEnabled(true); } }, "attachments" : { label : "Attachments", icon : "org.argeo.slc.ria/document-save-as.png", shortcut : null, enabled : false, menu : "Selection", toolbar : "selection", callback : function(e){ }, command : null, submenu : [], submenuCallback : function(commandId){ var split = commandId.split("__commandseparator__"); var uuid = split[0]; var contentType = split[1]; var name = split[2]; var url = org.argeo.slc.ria.SlcApi.buildGetAttachmentUrl(uuid, contentType, name); var win = window.open(url); }, selectionChange : function(viewId, xmlNodes){ if(viewId!="list")return; this.clearMenus(); this.setEnabled(false); if(xmlNodes == null || !xmlNodes.length || xmlNodes.length != 1) return; // Check slc:simple-attachment tags var attachs = org.argeo.ria.util.Element.selectNodes(xmlNodes[0], "slc:attachments/slc:simple-attachment"); if(attachs && attachs.length){ var submenus = []; for(var i=0;i test " + this.extractTestUuid() + "?"); modal.addListener("ok", function(){ var request = org.argeo.slc.ria.SlcApi.getRemoveResultService(this.getCollectionId(), this.extractTestUuid()); request.addListener("completed", function(response){ this.loadCollections(); this.loadList(); this.info("Test was successfully deleted"); }, this); request.send(); }, this); modal.attachAndShow(); }, selectionChange : function(viewId, xmlNodes){ if(viewId != "list") return; this.setEnabled(false); if(xmlNodes == null || !xmlNodes.length) return; this.setEnabled(true); }, command : null } } } }, members : { init : function(viewPane, data){ this.setView(viewPane); this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); }, load : function(){ this.table.set({ statusBarVisible: false, showCellFocusIndicator:false, columnVisibilityButtonVisible:false, contextMenu : org.argeo.ria.event.CommandsManager.getInstance().createMenuFromIds(["opentest", "download", "copytocollection", "deletetest"]), decorator : new qx.ui.decoration.Background("#fff") }); var viewPane = this.getView(); this.table.addListener("dblclick", function(e){ var pref = this.getRiaPreferenceValue("slc.web.TestList.DefaultAction"); if(pref == "Open"){ org.argeo.ria.event.CommandsManager.getInstance().executeCommand("opentest"); }else{ var uuid = this.extractTestUuid(); var url = "../resultView.xslt?uuid="+uuid; alert('Should download : '+url); } }, this); var columnModel = this.table.getTableColumnModel(); columnModel.getBehavior().setWidth(0, "60%"); var renderer = new org.argeo.slc.web.XmlRenderer(); columnModel.setDataCellRenderer(0, renderer); columnModel.setDataCellRenderer(1, renderer); this.table.getSelectionManager().getSelectionModel().addListener("changeSelection", function(e){ var viewSelection = this.getViewSelection(); viewSelection.clear(); var selectionModel = this.table.getSelectionManager().getSelectionModel(); if(!selectionModel.getSelectedCount()){ return; } var ranges = this.table.getSelectionManager().getSelectionModel().getSelectedRanges(); var xmlNode = this.table.getTableModel().getRowData(ranges[0].minIndex); viewSelection.addNode(xmlNode); //viewPane.setViewSelection(viewSelection); }, this); var select = new qx.ui.form.SelectBox(); this.getView().addHeaderComponent(select); this.getView().setViewTitle(""); this.add(this.table, {flex:1}); select.addListener("changeValue", this.collectionSelectorListener, this); org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(event){ if(event.getDataType()!="collection") return; select.removeListener("changeValue", this.collectionSelectorListener, this); var collectionList = event.getContent(); select.removeAll(); for(key in collectionList){ var item = new qx.ui.form.ListItem(collectionList[key], "org.argeo.slc.ria/folder.png", key); select.add(item); if(key == this.getCollectionId()){ select.setSelected(item); } } if(qx.lang.Object.getLength(collectionList)){ this.setCollectionId(select.getSelected().getValue()); } select.addListener("changeValue", this.collectionSelectorListener, this); }, this); }, /** * Use SlcApi to load the available collections. */ loadCollections : function(){ var request = org.argeo.slc.ria.SlcApi.getListCollectionsService(); var NSMap = {slc:"http://argeo.org/projects/slc/schemas"}; request.addListener("completed", function(response){ var xml = response.getContent(); var collections = {}; var nodes = org.argeo.ria.util.Element.selectNodes(xml, "//slc:ref", NSMap); for(var i=0;i