Commit 5644e5b4 authored by Tristan Cavelier's avatar Tristan Cavelier

Add jio.getJobArray method to JIO.

parent c9ec180f
...@@ -1049,7 +1049,7 @@ var jobManager = (function(spec, my) { ...@@ -1049,7 +1049,7 @@ var jobManager = (function(spec, my) {
priv.id = spec.id; priv.id = spec.id;
priv.interval_id = null; priv.interval_id = null;
priv.interval = 200; priv.interval = 200;
priv.job_a = []; priv.job_array = [];
my.jobManager = that; my.jobManager = that;
my.jobIdHandler = jobIdHandler; my.jobIdHandler = jobIdHandler;
...@@ -1079,8 +1079,8 @@ var jobManager = (function(spec, my) { ...@@ -1079,8 +1079,8 @@ var jobManager = (function(spec, my) {
*/ */
priv.copyJobArrayToLocal = function() { priv.copyJobArrayToLocal = function() {
var new_a = [], i; var new_a = [], i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
new_a.push(priv.job_a[i].serialized()); new_a.push(priv.job_array[i].serialized());
} }
LocalOrCookieStorage.setItem(priv.getJobArrayName(),new_a); LocalOrCookieStorage.setItem(priv.getJobArrayName(),new_a);
}; };
...@@ -1091,13 +1091,13 @@ var jobManager = (function(spec, my) { ...@@ -1091,13 +1091,13 @@ var jobManager = (function(spec, my) {
* @param {object} job The job object. * @param {object} job The job object.
*/ */
priv.removeJob = function(job) { priv.removeJob = function(job) {
var i, tmp_job_a = []; var i, tmp_job_array = [];
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
if (priv.job_a[i] !== job) { if (priv.job_array[i] !== job) {
tmp_job_a.push(priv.job_a[i]); tmp_job_array.push(priv.job_array[i]);
} }
} }
priv.job_a = tmp_job_a; priv.job_array = tmp_job_array;
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
}; };
...@@ -1119,8 +1119,8 @@ var jobManager = (function(spec, my) { ...@@ -1119,8 +1119,8 @@ var jobManager = (function(spec, my) {
if (priv.interval_id === null) { if (priv.interval_id === null) {
priv.interval_id = setInterval (function() { priv.interval_id = setInterval (function() {
priv.restoreOldJio(); priv.restoreOldJio();
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
that.execute(priv.job_a[i]); that.execute(priv.job_array[i]);
} }
},priv.interval); },priv.interval);
} }
...@@ -1134,7 +1134,7 @@ var jobManager = (function(spec, my) { ...@@ -1134,7 +1134,7 @@ var jobManager = (function(spec, my) {
if (priv.interval_id !== null) { if (priv.interval_id !== null) {
clearInterval(priv.interval_id); clearInterval(priv.interval_id);
priv.interval_id = null; priv.interval_id = null;
if (priv.job_a.length === 0) { if (priv.job_array.length === 0) {
LocalOrCookieStorage.deleteItem(priv.getJobArrayName()); LocalOrCookieStorage.deleteItem(priv.getJobArrayName());
} }
} }
...@@ -1242,8 +1242,8 @@ var jobManager = (function(spec, my) { ...@@ -1242,8 +1242,8 @@ var jobManager = (function(spec, my) {
*/ */
that.jobIdExists = function(id) { that.jobIdExists = function(id) {
var i; var i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
if (priv.job_a[i].getId() === id) { if (priv.job_array[i].getId() === id) {
return true; return true;
} }
} }
...@@ -1265,21 +1265,21 @@ var jobManager = (function(spec, my) { ...@@ -1265,21 +1265,21 @@ var jobManager = (function(spec, my) {
* @param {object} job The new job. * @param {object} job The new job.
*/ */
that.addJob = function(job) { that.addJob = function(job) {
var result_a = that.validateJobAccordingToJobList (priv.job_a,job); var result_a = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_a); priv.appendJob (job,result_a);
}; };
/** /**
* Generate a result array containing action string to do with the good job. * Generate a result array containing action string to do with the good job.
* @method validateJobAccordingToJobList * @method validateJobAccordingToJobList
* @param {array} job_a A job array. * @param {array} job_array A job array.
* @param {object} job The new job to compare with. * @param {object} job The new job to compare with.
* @return {array} A result array. * @return {array} A result array.
*/ */
that.validateJobAccordingToJobList = function(job_a,job) { that.validateJobAccordingToJobList = function(job_array,job) {
var i, result_a = []; var i, result_a = [];
for (i = 0; i < job_a.length; i+= 1) { for (i = 0; i < job_array.length; i+= 1) {
result_a.push(jobRules.validateJobAccordingToJob (job_a[i],job)); result_a.push(jobRules.validateJobAccordingToJob (job_array[i],job));
} }
return result_a; return result_a;
}; };
...@@ -1295,7 +1295,7 @@ var jobManager = (function(spec, my) { ...@@ -1295,7 +1295,7 @@ var jobManager = (function(spec, my) {
*/ */
priv.appendJob = function(job,result_a) { priv.appendJob = function(job,result_a) {
var i; var i;
if (priv.job_a.length !== result_a.length) { if (priv.job_array.length !== result_a.length) {
throw new RangeError("Array out of bound"); throw new RangeError("Array out of bound");
} }
for (i = 0; i < result_a.length; i+= 1) { for (i = 0; i < result_a.length; i+= 1) {
...@@ -1318,10 +1318,18 @@ var jobManager = (function(spec, my) { ...@@ -1318,10 +1318,18 @@ var jobManager = (function(spec, my) {
default: break; default: break;
} }
} }
priv.job_a.push(job); priv.job_array.push(job);
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
}; };
that.serialized = function () {
var a = [], i, job_array = priv.job_array || [];
for (i = 0; i < job_array.length; i+= 1) {
a.push(job_array[i].serialized());
}
return a;
};
return that; return that;
}()); }());
...@@ -1590,6 +1598,10 @@ var jobRules = (function(spec, my) { ...@@ -1590,6 +1598,10 @@ var jobRules = (function(spec, my) {
return jioNamespace.storage(description, my).isValid(); return jioNamespace.storage(description, my).isValid();
}; };
that.getJobArray = function () {
return jobManager.serialized();
};
/** /**
* Save a document. * Save a document.
* @method saveDocument * @method saveDocument
......
This diff is collapsed.
...@@ -74,6 +74,10 @@ ...@@ -74,6 +74,10 @@
return jioNamespace.storage(description, my).isValid(); return jioNamespace.storage(description, my).isValid();
}; };
that.getJobArray = function () {
return jobManager.serialized();
};
/** /**
* Save a document. * Save a document.
* @method saveDocument * @method saveDocument
......
...@@ -8,7 +8,7 @@ var jobManager = (function(spec, my) { ...@@ -8,7 +8,7 @@ var jobManager = (function(spec, my) {
priv.id = spec.id; priv.id = spec.id;
priv.interval_id = null; priv.interval_id = null;
priv.interval = 200; priv.interval = 200;
priv.job_a = []; priv.job_array = [];
my.jobManager = that; my.jobManager = that;
my.jobIdHandler = jobIdHandler; my.jobIdHandler = jobIdHandler;
...@@ -38,8 +38,8 @@ var jobManager = (function(spec, my) { ...@@ -38,8 +38,8 @@ var jobManager = (function(spec, my) {
*/ */
priv.copyJobArrayToLocal = function() { priv.copyJobArrayToLocal = function() {
var new_a = [], i; var new_a = [], i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
new_a.push(priv.job_a[i].serialized()); new_a.push(priv.job_array[i].serialized());
} }
LocalOrCookieStorage.setItem(priv.getJobArrayName(),new_a); LocalOrCookieStorage.setItem(priv.getJobArrayName(),new_a);
}; };
...@@ -50,13 +50,13 @@ var jobManager = (function(spec, my) { ...@@ -50,13 +50,13 @@ var jobManager = (function(spec, my) {
* @param {object} job The job object. * @param {object} job The job object.
*/ */
priv.removeJob = function(job) { priv.removeJob = function(job) {
var i, tmp_job_a = []; var i, tmp_job_array = [];
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
if (priv.job_a[i] !== job) { if (priv.job_array[i] !== job) {
tmp_job_a.push(priv.job_a[i]); tmp_job_array.push(priv.job_array[i]);
} }
} }
priv.job_a = tmp_job_a; priv.job_array = tmp_job_array;
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
}; };
...@@ -78,8 +78,8 @@ var jobManager = (function(spec, my) { ...@@ -78,8 +78,8 @@ var jobManager = (function(spec, my) {
if (priv.interval_id === null) { if (priv.interval_id === null) {
priv.interval_id = setInterval (function() { priv.interval_id = setInterval (function() {
priv.restoreOldJio(); priv.restoreOldJio();
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
that.execute(priv.job_a[i]); that.execute(priv.job_array[i]);
} }
},priv.interval); },priv.interval);
} }
...@@ -93,7 +93,7 @@ var jobManager = (function(spec, my) { ...@@ -93,7 +93,7 @@ var jobManager = (function(spec, my) {
if (priv.interval_id !== null) { if (priv.interval_id !== null) {
clearInterval(priv.interval_id); clearInterval(priv.interval_id);
priv.interval_id = null; priv.interval_id = null;
if (priv.job_a.length === 0) { if (priv.job_array.length === 0) {
LocalOrCookieStorage.deleteItem(priv.getJobArrayName()); LocalOrCookieStorage.deleteItem(priv.getJobArrayName());
} }
} }
...@@ -201,8 +201,8 @@ var jobManager = (function(spec, my) { ...@@ -201,8 +201,8 @@ var jobManager = (function(spec, my) {
*/ */
that.jobIdExists = function(id) { that.jobIdExists = function(id) {
var i; var i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_array.length; i+= 1) {
if (priv.job_a[i].getId() === id) { if (priv.job_array[i].getId() === id) {
return true; return true;
} }
} }
...@@ -224,21 +224,21 @@ var jobManager = (function(spec, my) { ...@@ -224,21 +224,21 @@ var jobManager = (function(spec, my) {
* @param {object} job The new job. * @param {object} job The new job.
*/ */
that.addJob = function(job) { that.addJob = function(job) {
var result_a = that.validateJobAccordingToJobList (priv.job_a,job); var result_a = that.validateJobAccordingToJobList (priv.job_array,job);
priv.appendJob (job,result_a); priv.appendJob (job,result_a);
}; };
/** /**
* Generate a result array containing action string to do with the good job. * Generate a result array containing action string to do with the good job.
* @method validateJobAccordingToJobList * @method validateJobAccordingToJobList
* @param {array} job_a A job array. * @param {array} job_array A job array.
* @param {object} job The new job to compare with. * @param {object} job The new job to compare with.
* @return {array} A result array. * @return {array} A result array.
*/ */
that.validateJobAccordingToJobList = function(job_a,job) { that.validateJobAccordingToJobList = function(job_array,job) {
var i, result_a = []; var i, result_a = [];
for (i = 0; i < job_a.length; i+= 1) { for (i = 0; i < job_array.length; i+= 1) {
result_a.push(jobRules.validateJobAccordingToJob (job_a[i],job)); result_a.push(jobRules.validateJobAccordingToJob (job_array[i],job));
} }
return result_a; return result_a;
}; };
...@@ -254,7 +254,7 @@ var jobManager = (function(spec, my) { ...@@ -254,7 +254,7 @@ var jobManager = (function(spec, my) {
*/ */
priv.appendJob = function(job,result_a) { priv.appendJob = function(job,result_a) {
var i; var i;
if (priv.job_a.length !== result_a.length) { if (priv.job_array.length !== result_a.length) {
throw new RangeError("Array out of bound"); throw new RangeError("Array out of bound");
} }
for (i = 0; i < result_a.length; i+= 1) { for (i = 0; i < result_a.length; i+= 1) {
...@@ -277,9 +277,17 @@ var jobManager = (function(spec, my) { ...@@ -277,9 +277,17 @@ var jobManager = (function(spec, my) {
default: break; default: break;
} }
} }
priv.job_a.push(job); priv.job_array.push(job);
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
}; };
that.serialized = function () {
var a = [], i, job_array = priv.job_array || [];
for (i = 0; i < job_array.length; i+= 1) {
a.push(job_array[i].serialized());
}
return a;
};
return that; return that;
}()); }());
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment