]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/BatchView.js
qx 0.8.3 deprecation
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / BatchView.js
index 8769751bb82f4559a4d369ce5f6a38ad709d4f12..5f68b2cf6eeca1f9a525e554eb999193d8d288dd 100644 (file)
@@ -5,7 +5,21 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
 {\r
        extend : qx.ui.container.Composite,\r
        implement : [org.argeo.ria.components.IView], \r
-\r
+       include : [org.argeo.ria.session.MPrefHolder],\r
+       statics : {\r
+               riaPreferences : {\r
+                       "slc.batch.delete.confirm" : {\r
+                               label : "Confirm on batch deletion",\r
+                               type  : "boolean",\r
+                               defaultValue  : true\r
+                       },\r
+                       "slc.batch.autoclear" : {\r
+                               label : "Autoclear batch on execution",\r
+                               type : "boolean",\r
+                               defaultValue : false\r
+                       }\r
+               }\r
+       },\r
        properties : \r
        {\r
                /**\r
@@ -16,21 +30,40 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                        init : {\r
                                "submitform" : {\r
                                        label : "Execute Batch",\r
-                                       icon : "resource/slc/media-playback-start.png",\r
+                                       icon : "org.argeo.slc.ria/media-playback-start.png",\r
                                        shortcut : null,\r
                                        enabled : false,\r
                                        menu : "Launcher",\r
                                        toolbar : "batch",\r
                                        callback : function(e) {\r
-                                               if (this.getBatchAgentId()) {\r
-                                                       this.executeBatchOnAgent(this.getBatchAgentId());\r
+                                               var batchAgentId = this.getBatchAgentId();\r
+                                               if (!batchAgentId) {\r
+                                                       return;                                                 \r
                                                }\r
+                                               var prefName = "slc.batch.autoclear";\r
+                                               var prefValue = this.getRiaPreferenceValue(prefName);\r
+                                               if(prefValue !== null && prefValue === true){\r
+                                                       this.executeBatchOnAgent(batchAgentId, true);                                                   \r
+                                               }else{\r
+                                                       this.executeBatchOnAgent(batchAgentId, false);\r
+                                               }\r
+                                               return;\r
+                                               var modal = new org.argeo.ria.components.Modal("Clear?", null);\r
+                                               modal.addYesNoReminder("Do you want to clear the batch automatically after execution?", prefName);\r
+                                               modal.addListener("cancel", function(e){\r
+                                                       this.executeBatchOnAgent(batchAgentId, false);\r
+                                               }, this);\r
+                                               modal.addListener("ok", function(e){\r
+                                                       this.executeBatchOnAgent(batchAgentId, true);\r
+                                               }, this);\r
+                                               modal.attachAndShow();                                          \r
                                        },\r
                                        command : null\r
                                },\r
+                               /*\r
                                "toggleopenonadd" : {\r
                                        label : "Auto edit on Add",\r
-                                       icon : "resource/slc/document-open.png",\r
+                                       icon : "org.argeo.slc.ria/document-open.png",\r
                                        shortcut : null,\r
                                        enabled : true,\r
                                        toggle : true,\r
@@ -45,7 +78,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                },\r
                                "editexecutionspecs" : {\r
                                        label : "Edit Execution Specs",\r
-                                       icon : "resource/slc/document-open.png",\r
+                                       icon : "org.argeo.slc.ria/document-open.png",\r
                                        shortcut : null,\r
                                        enabled : false,\r
                                        menu : "Launcher",\r
@@ -59,7 +92,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                                }\r
                                        },\r
                                        selectionChange : function(viewId, selection) {\r
-                                               if (viewId != "form:list")\r
+                                               if (viewId != "batch:list")\r
                                                        return;\r
                                                this.setEnabled(false);\r
                                                if ((selection && selection.length == 1)) {\r
@@ -71,38 +104,62 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                        },\r
                                        command : null\r
                                },\r
+                               */\r
                                "removefrombatch" : {\r
                                        label : "Remove from batch",\r
-                                       icon : "resource/slc/edit-delete.png",\r
+                                       icon : "org.argeo.slc.ria/edit-delete.png",\r
                                        shortcut : null,\r
                                        enabled : false,\r
                                        menu : "Launcher",\r
                                        toolbar : "batch",\r
                                        callback : function(e) {\r
                                                var sel = this.list.getSortedSelection();\r
-                                               var modal = new org.argeo.ria.components.Modal("Confirm", null);\r
-                                               modal.addConfirm("Are you sure you want to remove<br> the selected test"\r
-                                                                               + (sel.length > 1 ? "s" : "")\r
-                                                                               + " from the Batch?");\r
-                                               modal.addListener("ok", function() {\r
-                                                                       for (var i = 0; i < sel.length; i++) {\r
-                                                                               this.list.remove(sel[i]);\r
-                                                                       }\r
-                                                                       if (!this.list.hasChildren()) {\r
-                                                                               this.setBatchAgentId(null);\r
-                                                                       }\r
-                                                               }, this);\r
-                                               modal.attachAndShow();\r
+                                               var confirmPref = this.getRiaPreferenceValue("slc.batch.delete.confirm");                                               \r
+                                               var execution = function() {\r
+                                                       for (var i = 0; i < sel.length; i++) {\r
+                                                               this.list.remove(sel[i]);\r
+                                                       }\r
+                                                       if (!this.list.hasChildren()) {\r
+                                                               this.setBatchAgentId(null);\r
+                                                       }\r
+                                               }\r
+                                               if(confirmPref){\r
+                                                       var modal = new org.argeo.ria.components.Modal("Confirm", null);\r
+                                                       modal.addConfirm("Are you sure you want to remove<br> the selected test"\r
+                                                                                       + (sel.length > 1 ? "s" : "")\r
+                                                                                       + " from the Batch?");\r
+                                                       modal.addListener("ok", execution, this);\r
+                                                       modal.attachAndShow();\r
+                                               }else{\r
+                                                       execution = qx.lang.Function.bind(execution, this);\r
+                                                       execution();\r
+                                               }\r
                                        },\r
                                        selectionChange : function(viewId, selection) {\r
-                                               if (viewId != "form:list")\r
+                                               if (viewId != "batch:list")\r
                                                        return;\r
                                                this.setEnabled(false);\r
                                                if ((selection && selection.length > 0))\r
                                                        this.setEnabled(true);\r
                                        },\r
                                        command : null\r
-                               }                               \r
+                               },\r
+                               "clearbatch" : {\r
+                                       label : "Clear batch",\r
+                                       icon : "org.argeo.slc.ria/user-trash-full.png",\r
+                                       shortcut : null,\r
+                                       enabled : true,\r
+                                       menu : "Launcher",\r
+                                       toolbar : "batch",\r
+                                       callback : function(e) {\r
+                                               if(!this.list.hasChildren()) return;\r
+                                               this.list.selectAll();\r
+                                               this.getCommands()["removefrombatch"].command.execute();\r
+                                       },\r
+                                       selectionChange : function(viewId, selection) {\r
+                                       },\r
+                                       command : null\r
+                               }                                                               \r
                        }\r
                },\r
                view : {\r
@@ -198,8 +255,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                        this.list.setDroppable(true);\r
                        this.list.setDraggable(true);\r
                        this.list.setContextMenu(org.argeo.ria.event.CommandsManager\r
-                                       .getInstance().createMenuFromIds(["editexecutionspecs",\r
-                                                       "removefrombatch"]));\r
+                                       .getInstance().createMenuFromIds(["removefrombatch"]));\r
 \r
                        this.list.addListener("dragstart", function(e) {\r
                                                e.addType(["items"]);\r
@@ -242,7 +298,7 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
 \r
                        this.list.addListener("changeSelection", function(e) {\r
                                                var viewSelection = this.getViewSelection();\r
-                                               viewSelection.setViewId("form:list");\r
+                                               viewSelection.setViewId("batch:list");\r
                                                viewSelection.clear();\r
                                                var listSel = this.list.getSortedSelection();\r
                                                for (var i = 0; i < listSel.length; i++) {\r
@@ -250,15 +306,27 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                                }\r
                                        }, this);\r
 \r
+                       this.dropDecorator = new qx.ui.decoration.Background();                 \r
+                       this.dropDecorator.set({\r
+                               backgroundImage : "org.argeo.slc.ria/drophere.gif",\r
+                               backgroundRepeat : "no-repeat"\r
+                       });\r
+\r
+                                       \r
                        listChangeListener = function() {\r
                                var command = org.argeo.ria.event.CommandsManager.getInstance()\r
                                                .getCommandById("submitform");\r
                                command.setEnabled(this.list.hasChildren());\r
+                               var command2 = org.argeo.ria.event.CommandsManager.getInstance()\r
+                                               .getCommandById("clearbatch");\r
+                               command2.setEnabled(this.list.hasChildren());\r
+                               this.list.setDecorator((this.list.hasChildren()?null:this.dropDecorator));\r
                        };\r
                        this.list.addListener("addItem", listChangeListener, this);\r
                        this.list.addListener("removeItem", listChangeListener, this);\r
-\r
-                       \r
+                               \r
+                       this.list.setDecorator(this.dropDecorator);\r
+                                               \r
                        this.add(this.listPane);\r
                },              \r
                \r
@@ -316,14 +384,14 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                        var executionFlow = target.getUserData("executionFlow");\r
                        var batchEntry = new org.argeo.slc.ria.execution.BatchEntrySpec(\r
                                        executionModule, executionFlow);\r
-                       var label = batchEntry.getLabel();\r
-                       var icon = target.getIcon() || "resource/slc/office-document.png";\r
-                       var item = new qx.ui.form.ListItem(label, icon);\r
-                       item.addListener("dblclick", function(e) {\r
-                                               this.getCommands()["editexecutionspecs"].command\r
-                                                               .execute();\r
-                                       }, this);\r
-                       item.setUserData("batchEntrySpec", batchEntry);\r
+\r
+                       this.appendBatchEntrySpec(batchEntry, target.getIcon(), after);         \r
+               },\r
+               \r
+               appendBatchEntrySpec: function(batchEntrySpec, icon, after){\r
+                                               \r
+                       var item = new qx.ui.form.ListItem(batchEntrySpec.getLabel(), icon || "org.argeo.slc.ria/system.png");\r
+                       item.setUserData("batchEntrySpec", batchEntrySpec);\r
                        item.setPaddingTop(1);\r
                        item.setPaddingBottom(2);\r
                        if (after) {\r
@@ -334,10 +402,8 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                        } else {\r
                                this.list.add(item);\r
                        }\r
-                       this.list.select(item);\r
-                       if (this.getAutoOpen() && !skipAutoOpen) {\r
-                               this.getCommands()["editexecutionspecs"].command.execute();\r
-                       }\r
+                       this.list.setSelection([item]);\r
+                       \r
                },\r
 \r
                /**\r
@@ -346,26 +412,45 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                 * @param agentUuid\r
                 *            {String} The id of the target agent\r
                 */\r
-               executeBatchOnAgent : function(agentUuid) {\r
+               executeBatchOnAgent : function(agentUuid, clearBatch) {\r
                        var selection = this.list.getChildren();\r
                        if (!selection.length)\r
                                return;\r
+                       // Get Host\r
+                       var agentsMap = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("selector").getContent().getAgentsMap();\r
+                       var host = agentsMap[agentUuid];\r
                        var slcExecMessage = new org.argeo.slc.ria.execution.Message();\r
+                       slcExecMessage.setHost(host);\r
                        for (var i = 0; i < selection.length; i++) {\r
                                var batchEntrySpec = selection[i].getUserData("batchEntrySpec");\r
                                slcExecMessage.addBatchEntrySpec(batchEntrySpec);\r
                        }\r
-                       var req = org.argeo.slc.ria.SlcApi.getNewSlcExecutionService(\r
-                                       agentUuid, slcExecMessage.toXml());\r
-                       req.send();\r
-                       // Force logs refresh right now!\r
-                       qx.event.Timer.once(function() {\r
-                                               var command = org.argeo.ria.event.CommandsManager\r
-                                                               .getInstance().getCommandById("reloadlogs");\r
-                                               if (command) {\r
-                                                       command.execute();\r
-                                               }\r
-                                       }, this, 2000);\r
+                       try{\r
+                               var xmlMessage = slcExecMessage.toXml();\r
+                               if(!window.xmlExecStub){\r
+                                       window.xmlExecStub = {};\r
+                               }\r
+                               window.xmlExecStub[slcExecMessage.getUuid()] = qx.xml.Document.fromString(xmlMessage);\r
+                               var req = org.argeo.slc.ria.SlcApi.getNewSlcExecutionService(\r
+                                               agentUuid, xmlMessage);\r
+                               req.send();\r
+                               // Force logs refresh right now!\r
+                               qx.event.Timer.once(function() {\r
+                                                       var command = org.argeo.ria.event.CommandsManager\r
+                                                                       .getInstance().getCommandById("reloadlogs");\r
+                                                       if (command) {\r
+                                                               command.execute();\r
+                                                       }\r
+                                               }, this, 2000);\r
+                               if(clearBatch){\r
+                                       req.addListener("completed", function(e){\r
+                                               this.list.removeAll();\r
+                                               this.setBatchAgentId(null);\r
+                                       }, this);\r
+                               }                                               \r
+                       }catch(e){\r
+                               this.error(e);                          \r
+                       }\r
                },\r
                \r
                clearBatchForAgentId : function(agentId){\r