[Kimchi-devel] [PATCH 2/5] Add common function to track Task
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Sep 8 03:07:33 UTC 2014
Track a task is a common funtionality used on UI to idenitfy if the operation
has finished or not.
So create a common function to do it and reuse whenever is needed.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
ui/js/src/kimchi.api.js | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 6f12455..681f573 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -21,6 +21,8 @@ var kimchi = {
widget: {},
+ trackingTasks: [],
+
/**
* A wrapper of jQuery.ajax function to allow custom bindings.
*
@@ -681,19 +683,15 @@ var kimchi = {
});
},
- createReport: function(settings, suc, err, progress) {
- var taskID = -1;
+ trackTask : function(taskID, suc, err, progress) {
var onTaskResponse = function(result) {
var taskStatus = result['status'];
switch(taskStatus) {
case 'running':
- if(kimchi.stopTrackingReport === true) {
- return;
- }
progress && progress(result);
setTimeout(function() {
- trackTask();
- }, 200);
+ kimchi.trackTask(taskID, suc, err, progress);
+ }, 2000);
break;
case 'finished':
suc(result);
@@ -706,13 +704,15 @@ var kimchi = {
}
};
- var trackTask = function() {
- kimchi.getTask(taskID, onTaskResponse, err);
- };
+ kimchi.getTask(taskID, onTaskResponse, err);
+ if(kimchi.trackingTasks.indexOf(taskID) < 0)
+ kimchi.trackingTasks.push(taskID);
+ },
+ createReport: function(settings, suc, err, progress) {
var onResponse = function(data) {
taskID = data['id'];
- trackTask();
+ kimchi.trackTask(taskID, suc, err, progress);
};
kimchi.requestJSON({
--
1.9.3
More information about the Kimchi-devel
mailing list