]> 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
Rename
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / BatchView.js
index 03f27df4399aa9aa81f40f6eb696b1782fb8ab17..78715de0403652f23aad1095fc6ccf67ba59daa7 100644 (file)
@@ -12,6 +12,11 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                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
@@ -31,9 +36,25 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                        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){\r
+                                                       this.executeBatchOnAgent(batchAgentId, prefValue);\r
+                                                       return;\r
+                                               }\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
@@ -396,7 +417,7 @@ 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
@@ -405,17 +426,27 @@ qx.Class.define("org.argeo.slc.ria.BatchView",
                                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
+                               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);\r
+                               }                                               \r
+                       }catch(e){\r
+                               this.error(e);                          \r
+                       }\r
                },\r
                \r
                clearBatchForAgentId : function(agentId){\r