Commit 27646bab authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Redesigning classes and var names.

parent 806c6e95
/*! JIO - v0.1.0 - 2012-05-23
/*! JIO - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
var JIO =
(function () { var jio_loader_function = function ( LocalOrCookieStorage, $ ) {
(function () { var jio_loader_function = function ( localOrCookieStorage, $ ) {
////////////////////////////////////////////////////////////////////////////
// constants
var jioConstObj = {
'jobMethodObject': {
'checkNameAvailability': {
'start_event':'start_checkingNameAvailability',
'stop_event':'stop_checkingNameAvailability',
'retvalue':'isAvailable' }, // returns 'boolean'
'saveDocument': {
'start_event':'start_saving',
'stop_event':'stop_saving',
'retvalue':'isSaved' }, // returns 'boolean'
'loadDocument': {
'start_event':'start_loading',
'stop_event':'stop_loading',
'retvalue':'fileContent' }, // returns the file content 'string'
'getDocumentList': {
'start_event':'start_gettingList',
'stop_event':'stop_gettingList',
'retvalue':'list' }, // returns the document list 'array'
'removeDocument': {
'start_event':'start_removing',
'stop_event':'stop_removing',
'retvalue':'isRemoved' } // returns 'boolean'
var jio_const_obj = {
job_method_object: {
checkNameAvailability:{},
saveDocument:{},
loadDocument:{},
getDocumentList:{},
removeDocument:{}
}
},
// end constants
////////////////////////////////////////////////////////////////////////////
// jio globals
jioGlobalObj = {
'jobManagingMethod':{
jio_global_obj = {
job_managing_method:{
/*
LEGEND:
- s: storage
......@@ -105,7 +90,7 @@ var JIO =
For more information, see documentation
*/
'canSelect':function (job1,job2) {
canSelect:function (job1,job2) {
if (JSON.stringify (job1.storage) ===
JSON.stringify (job2.storage) &&
JSON.stringify (job1.applicant) ===
......@@ -115,14 +100,14 @@ var JIO =
}
return false;
},
'canRemoveFailOrDone':function (job1,job2) {
canRemoveFailOrDone:function (job1,job2) {
if (job1.status === 'fail' ||
job1.status === 'done') {
return true;
}
return false;
},
'canEliminate':function (job1,job2) {
canEliminate:function (job1,job2) {
if (job1.status !== 'ongoing' &&
(job1.method === 'removeDocument' &&
job2.method === 'saveDocument' ||
......@@ -132,7 +117,7 @@ var JIO =
}
return false;
},
'canReplace':function (job1,job2) {
canReplace:function (job1,job2) {
if (job1.status !== 'ongoing' &&
job1.method === job2.method &&
job1.date < job2.date) {
......@@ -140,7 +125,7 @@ var JIO =
}
return false;
},
'cannotAccept':function (job1,job2) {
cannotAccept:function (job1,job2) {
if (job1.status !== 'ongoing' ) {
if (job1.method === 'removeDocument' &&
job2.method === 'loadDocument') {
......@@ -165,7 +150,7 @@ var JIO =
}
return false;
},
'mustWait':function (job1,job2) {
mustWait:function (job1,job2) {
if (job1.method === 'getDocumentList' ||
job1.method === 'checkNameAvailability' ||
job2.method === 'getDocumentList' ||
......@@ -175,30 +160,35 @@ var JIO =
return true;
}
},
'localStorage': null, // where the browser stores data
'queueID': 1,
'storageTypeObject': {}, // ex: {'type':'local','creator': fun ...}
'max_wait_time': 10000
queue_id: 1,
storage_type_object: {}, // ex: {'type':'local','creator': fun ...}
max_wait_time: 10000
},
// end jio globals
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Tools
extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Classes
PubSub,Job,JobQueue,JobListener,ActivityUpdater,BaseStorage,
JioConstructor,JioCreator;
newPubSub,newJob,newJobQueue,newJobListener,newActivityUpdater,
newBaseStorage,newJioConstructor,newJioCreator;
// end Classes
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Publisher Subcriber
PubSub = function () {
newPubSub = function (spec, my) {
var that = {}, priv = {},
topics = {}, callbacks, topic;
priv.eventAction = function (id) {
......@@ -236,45 +226,47 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// Job & JobQueue
Job = function ( options ) {
newJob = function ( spec, my ) {
// Job constructor
var job = $.extend({},options);
var job = extend({},spec);
job['id']=0;
job['status']='initial';
job['date']=Date.now();
return job;
};
JobQueue = function ( publisher, options ) {
newJobQueue = function ( spec, my ) {
// JobQueue is a queue of jobs. It will regulary copy this queue
// into localStorage to resume undone tasks.
// publisher: the publisher to use to send event
// options.useLocalStorage: if true, save jobs into localStorage,
// spec.publisher: the publisher to use to send event
// spec.options.useLocalStorage: if true, save jobs into localStorage,
// else only save on memory.
var that = {}, priv = {},
jioIdArrayName = 'jio/idArray';
var that = {}, priv = {}, jio_id_array_name = 'jio/idarray';
that.init = function ( options ) {
// initialize the JobQueue
// options.publisher : is the publisher to use to send events
// options.jioID : the jio ID
var k, emptyfun = function (){},
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
if (options.publisher) {
priv.publisher = publisher;
}
priv.jioID = options.jioID;
priv.jobObjectName = 'jio/jobObject/'+options.jioID;
priv.jobObject = {};
jioIdArray.push (priv.jioID);
jioGlobalObj.localStorage.setItem (jioIdArrayName,jioIdArray);
// options.jio_id : the jio ID
var k, emptyfun = function (){}, jio_id_array;
if (priv.use_local_storage) {
jio_id_array = localOrCookieStorage.
getItem (jio_id_array_name)||[];
if (spec.publisher) {
priv.publisher = spec.publisher;
}
priv.jio_id = options.jio_id;
priv.job_object_name = 'jio/jobobject/' + priv.jio_id;
jio_id_array.push (priv.jio_id);
localOrCookieStorage.setItem (jio_id_array_name,jio_id_array);
}
priv.job_object = {};
that.copyJobQueueToLocalStorage();
for (k in priv.recoveredJobObject) {
priv.recoveredJobObject[k].callback = emptyfun;
that.addJob (priv.recoveredJobObject[k]);
for (k in priv.recovered_job_object) {
priv.recovered_job_object[k].callback = emptyfun;
that.addJob (priv.recovered_job_object[k]);
}
};
that.close = function () {
......@@ -282,50 +274,55 @@ var JIO =
// it also deletes from local storage only if the job list is
// empty.
if (JSON.stringify(priv.jobObject) === '{}') {
jioGlobalObj.localStorage.deleteItem(priv.jobObjectName);
if (JSON.stringify(priv.job_object) === '{}') {
localOrCookieStorage.deleteItem(priv.job_object_name);
}
};
that.getNewQueueID = function () {
// Returns a new queueID
var k = null, id = 0,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioIdArray[k] >= jioGlobalObj.queueID) {
jioGlobalObj.queueID = jioIdArray[k] + 1;
jio_id_array = localOrCookieStorage.getItem (jio_id_array_name)||[];
for (k = 0; k < jio_id_array.length; k += 1) {
if (jio_id_array[k] >= jio_global_obj.queue_id) {
jio_global_obj.queue_id = jio_id_array[k] + 1;
}
}
id = jioGlobalObj.queueID;
jioGlobalObj.queueID ++;
id = jio_global_obj.queue_id;
jio_global_obj.queue_id ++;
return id;
};
that.recoverOlderJobObject = function () {
// recover job object from older inactive jio
var k = null, newJioIdArray = [], jioIdArrayChanged = false,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioGlobalObj.localStorage.getItem (
'jio/id/'+jioIdArray[k]) < Date.now () - 10000) {
// remove id from jioIdArray
var k = null, new_jio_id_array = [], jio_id_array_changed = false,
jio_id_array;
if (priv.use_local_storage) {
jio_id_array = localOrCookieStorage.
getItem (jio_id_array_name)||[];
for (k = 0; k < jio_id_array.length; k += 1) {
if (localOrCookieStorage.getItem (
'jio/id/'+jio_id_array[k]) < Date.now () - 10000) {
// remove id from jio_id_array
// 10000 sec ? delete item
jioGlobalObj.localStorage.deleteItem('jio/id/'+
jioIdArray[k]);
localOrCookieStorage.deleteItem('jio/id/'+
jio_id_array[k]);
// job recovery
priv.recoveredJobObject = jioGlobalObj.
localStorage.getItem('jio/jioObject/'+ jioIdArray[k]);
priv.recovered_job_object = localOrCookieStorage.
getItem('jio/jobobject/'+ jio_id_array[k]);
// remove ex job object
jioGlobalObj.localStorage.deleteItem(
'jio/jobObject/'+ jioIdArray[k]);
jioIdArrayChanged = true;
localOrCookieStorage.deleteItem(
'jio/jobobject/'+ jio_id_array[k]);
jio_id_array_changed = true;
} else {
newJioIdArray.push (jioIdArray[k]);
new_jio_id_array.push (jio_id_array[k]);
}
}
if (jio_id_array_changed) {
localOrCookieStorage.setItem(jio_id_array_name,
new_jio_id_array);
}
if (jioIdArrayChanged) {
jioGlobalObj.localStorage.setItem(jioIdArrayName,newJioIdArray);
}
};
that.isThereJobsWhere = function( func ) {
......@@ -334,8 +331,8 @@ var JIO =
var id = 'id';
if (!func) { return true; }
for (id in priv.jobObject) {
if (func(priv.jobObject[id])) {
for (id in priv.job_object) {
if (func(priv.job_object[id])) {
return true;
}
}
......@@ -344,15 +341,15 @@ var JIO =
that.copyJobQueueToLocalStorage = function () {
// Copy job queue into localStorage.
if (priv.useLocalStorage) {
return jioGlobalObj.localStorage.setItem(
priv.jobObjectName,priv.jobObject);
if (priv.use_local_storage) {
return localOrCookieStorage.setItem(
priv.job_object_name,priv.job_object);
} else {
return false;
}
};
that.createJob = function ( options ) {
return that.addJob ( new Job ( options ) );
return that.addJob ( newJob ( options ) );
};
that.addJob = function ( job ) {
// Add a job to the queue, browsing all jobs
......@@ -362,39 +359,39 @@ var JIO =
// It also clean fail or done jobs.
// job = the job object
var res = {'newone':true,'elimArray':[],'waitArray':[],
'removeArray':[]}, basestorage = null, id = 'id';
var newone = true, elim_array = [], wait_array = [],
remove_array = [], basestorage = null, id = 'id';
//// browsing current jobs
for (id in priv.jobObject) {
if (jioGlobalObj.jobManagingMethod.canRemoveFailOrDone(
priv.jobObject[id],job)) {
res.removeArray.push(id);
for (id in priv.job_object) {
if (jio_global_obj.job_managing_method.canRemoveFailOrDone(
priv.job_object[id],job)) {
remove_array.push(id);
continue;
}
if (jioGlobalObj.jobManagingMethod.canSelect(
priv.jobObject[id],job)) {
if (jioGlobalObj.jobManagingMethod.canEliminate(
priv.jobObject[id],job)) {
res.elimArray.push(id);
if (jio_global_obj.job_managing_method.canSelect(
priv.job_object[id],job)) {
if (jio_global_obj.job_managing_method.canEliminate(
priv.job_object[id],job)) {
elim_array.push(id);
continue;
}
if (jioGlobalObj.jobManagingMethod.canReplace(
priv.jobObject[id],job)) {
basestorage = new BaseStorage(
{'queue':that,'job':priv.jobObject[id]});
if (jio_global_obj.job_managing_method.canReplace(
priv.job_object[id],job)) {
basestorage = newBaseStorage(
{'queue':that,'job':priv.job_object[id]});
basestorage.replace(job);
res.newone = false;
newone = false;
break;
}
if (jioGlobalObj.jobManagingMethod.cannotAccept(
priv.jobObject[id],job)) {
if (jio_global_obj.job_managing_method.cannotAccept(
priv.job_object[id],job)) {
// Job not accepted
return false;
}
if (jioGlobalObj.jobManagingMethod.mustWait(
priv.jobObject[id],job)) {
res.waitArray.push(id);
if (jio_global_obj.job_managing_method.mustWait(
priv.job_object[id],job)) {
wait_array.push(id);
continue;
}
// one of the previous tests must be ok.
......@@ -403,32 +400,33 @@ var JIO =
}
//// end browsing current jobs
if (res.newone) {
if (newone) {
// if it is a new job, we can eliminate deprecated jobs and
// set this job dependencies.
for (id = 0; id < res.elimArray.length; id += 1) {
basestorage = new BaseStorage(
{'queue':that,'job':priv.jobObject[res.elimArray[id]]});
for (id = 0; id < elim_array.length; id += 1) {
basestorage = newBaseStorage(
{'queue':that,
'job':priv.job_object[elim_array[id]]});
basestorage.eliminate();
}
if (res.waitArray.length > 0) {
if (wait_array.length > 0) {
job.status = 'wait';
job.waitingFor = {'jobIdArray':res.waitArray};
for (id = 0; id < res.waitArray.length; id += 1) {
if (priv.jobObject[res.waitArray[id]]) {
priv.jobObject[res.waitArray[id]].maxtries = 1;
job.waitingFor = {'jobIdArray':wait_array};
for (id = 0; id < wait_array.length; id += 1) {
if (priv.job_object[wait_array[id]]) {
priv.job_object[wait_array[id]].maxtries = 1;
}
}
}
for (id = 0; id < res.removeArray.length; id += 1) {
that.removeJob(priv.jobObject[res.removeArray[id]]);
for (id = 0; id < remove_array.length; id += 1) {
that.removeJob(priv.job_object[remove_array[id]]);
}
// set job id
job.id = priv.jobid;
job.id = priv.job_id;
job.tries = 0;
priv.jobid ++;
priv.job_id ++;
// save the new job into the queue
priv.jobObject[job.id] = job;
priv.job_object[job.id] = job;
}
// save into localStorage
that.copyJobQueueToLocalStorage();
......@@ -443,26 +441,26 @@ var JIO =
// options.job = the job object containing at least {id:..}.
// options.where = remove values where options.where(job) === true
var settings = $.extend ({'where':function (job) {return true;}},
var settings = extend ({where:function (job) {return true;}},
options),andwhere,found=false,k='key';
//// modify the job list
if (settings.job) {
if (priv.jobObject[settings.job.id] && settings.where(
priv.jobObject[settings.job.id]) ) {
delete priv.jobObject[settings.job.id];
if (priv.job_object[settings.job.id] && settings.where(
priv.job_object[settings.job.id]) ) {
delete priv.job_object[settings.job.id];
found = true;
}
}else {
for (k in priv.jobObject) {
if (settings.where(priv.jobObject[k])) {
delete priv.jobObject[k];
for (k in priv.job_object) {
if (settings.where(priv.job_object[k])) {
delete priv.job_object[k];
found = true;
}
}
}
if (!found) {
$.error ('No jobs was found, when trying to remove some.');
console.error('No jobs was found, when trying to remove some.');
}
//// end modifying
that.copyJobQueueToLocalStorage();
......@@ -473,8 +471,8 @@ var JIO =
// TODO manage jobs ! All jobs are not 'initial'.
var id = 'id';
for (id in priv.jobObject) {
priv.jobObject[id].status = 'initial';
for (id in priv.job_object) {
priv.job_object[id].status = 'initial';
}
that.copyJobQueueToLocalStorage();
};
......@@ -484,22 +482,23 @@ var JIO =
var i = 'id', j, ok;
//// do All jobs
for (i in priv.jobObject) {
for (i in priv.job_object) {
ok = false;
if (priv.jobObject[i].status === 'initial') {
if (priv.job_object[i].status === 'initial') {
// if status initial
// invoke new job
that.invoke(priv.jobObject[i]);
} else if (priv.jobObject[i].status === 'wait') {
that.invoke(priv.job_object[i]);
} else if (priv.job_object[i].status === 'wait') {
ok = true;
// if status wait
if (priv.jobObject[i].waitingFor.jobIdArray) {
if (priv.job_object[i].waitingFor.jobIdArray) {
// wait job
// browsing job id array
for (j = 0;
j < priv.jobObject[i].waitingFor.jobIdArray.length;
j < priv.job_object[i].
waitingFor.jobIdArray.length;
j += 1) {
if (priv.jobObject[priv.jobObject[i].
if (priv.job_object[priv.job_object[i].
waitingFor.jobIdArray[j]]) {
// if a job is still exist, don't invoke
ok = false;
......@@ -507,9 +506,9 @@ var JIO =
}
}
}
if (priv.jobObject[i].waitingFor.time) {
if (priv.job_object[i].waitingFor.time) {
// wait time
if (priv.jobObject[i].waitingFor.time > Date.now()) {
if (priv.job_object[i].waitingFor.time > Date.now()) {
// it is not time to restore the job!
ok = false;
}
......@@ -517,7 +516,7 @@ var JIO =
// else wait nothing
if (ok) {
// invoke waiting job
that.invoke(priv.jobObject[i]);
that.invoke(priv.job_object[i]);
}
}
}
......@@ -532,7 +531,7 @@ var JIO =
//// analysing job method
// if the method does not exist, do nothing
if (!jioConstObj.jobMethodObject[job.method]) {
if (!jio_const_obj.job_method_object[job.method]) {
return false; // suppose never happen
}
// test if a similar job is on going, in order to publish a start
......@@ -542,28 +541,28 @@ var JIO =
testjob.method === 'initial');
})) {
job.status = 'ongoing';
priv.publisher.publish(jioConstObj.jobMethodObject[
job.method].start_event);
priv.publisher.publish(jio_const_obj.job_method_object[
job.method]['start_'+job.method]);
} else {
job.status = 'ongoing';
}
// Create a storage object and use it to save,load,...!
basestorage = new BaseStorage({'queue':this,'job':job});
basestorage = newBaseStorage({'queue':this,'job':job});
basestorage.execute();
//// end method analyse
};
that.ended = function (endedjob) {
// It is a callback function called just before user callback.
// It is called to manage jobObject according to the ended job.
// It is called to manage job_object according to the ended job.
var job = $.extend({},endedjob); // copy
var job = extend({},endedjob); // copy
// This job is supposed terminated, we can remove it from queue.
that.removeJob ({'job':job});
//// ended job analyse
// if the job method does not exists, return false
if (!jioConstObj.jobMethodObject[job.method]) {
if (!jio_const_obj.job_method_object[job.method]) {
return false;
}
// if there isn't some job to do, then send stop event
......@@ -574,8 +573,8 @@ var JIO =
testjob.status === 'initial');
})) {
priv.publisher.publish(
jioConstObj.jobMethodObject[
job.method].stop_event);
jio_const_obj.job_method_object[
job.method]['stop_'+job.method]);
return;
}
//// end returnedJobAnalyse
......@@ -593,13 +592,13 @@ var JIO =
//// end Methods
//// Initialize
priv.useLocalStorage = options.useLocalStorage;
priv.publisher = publisher;
priv.jobid = 1;
priv.jioID = 0;
priv.jobObjectName = '';
priv.jobObject = {};
priv.recoveredJobObject = {};
priv.use_local_storage = spec.options.use_local_storage;
priv.publisher = spec.publisher;
priv.job_id = 1;
priv.jio_id = 0;
priv.job_object_name = '';
priv.job_object = {};
priv.recovered_job_object = {};
//// end Initialize
return that;
......@@ -609,13 +608,13 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// jio job listener
JobListener = function ( queue ) {
newJobListener = function ( spec, my ) {
// A little daemon which will start jobs from the joblist
var that = {}, priv = {};
priv.interval = 200;
priv.id = null;
priv.queue = queue;
priv.queue = spec.queue;
that.setIntervalDelay = function (interval) {
// Set the time between two joblist check in millisec
......@@ -652,7 +651,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// ActivityUpdater
ActivityUpdater = function () {
newActivityUpdater = function () {
// The activity updater is a little thread that proves activity of this
// jio instance.
......@@ -687,8 +686,7 @@ var JIO =
return false;
};
that.touch = function (id) {
jioGlobalObj.localStorage.setItem ('jio/id/' + id,
Date.now() );
localOrCookieStorage.setItem ('jio/id/' + id,Date.now() );
};
//// end methods
return that;
......@@ -698,7 +696,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// BaseStorage
BaseStorage = function ( options ) {
newBaseStorage = function ( options ) {
// The base storage, will call the good method from the good storage,
// and will check and return the associated value.
......@@ -764,8 +762,8 @@ var JIO =
// The listener will invoke this job later.
var time = (priv.job.tries*priv.job.tries*1000);
if (time > jioGlobalObj.max_wait_time) {
time = jioGlobalObj.max_wait_time;
if (time > jio_global_obj.max_wait_time) {
time = jio_global_obj.max_wait_time;
}
priv.job.status = 'wait';
priv.job.waitingFor = {'time':Date.now() + time};
......@@ -774,7 +772,7 @@ var JIO =
//// Getters Setters
that.cloneJob = function () {
return $.extend({},priv.job);
return extend({},priv.job);
};
that.getUserName = function () {
return priv.job.userName || '';
......@@ -801,7 +799,7 @@ var JIO =
return priv.job.fileContent || '';
};
that.cloneOptionObject = function () {
return $.extend({},priv.job.options);
return extend({},priv.job.options);
};
that.getMaxTries = function () {
return priv.job.maxtries;
......@@ -881,27 +879,37 @@ var JIO =
priv.job.tries = that.getTries() + 1;
if ( !jioGlobalObj.storageTypeObject[ priv.job.storage.type ] ) {
if ( !jio_global_obj.storage_type_object[priv.job.storage.type] ) {
return null;
}
return jioGlobalObj.storageTypeObject[ priv.job.storage.type ]({
return jio_global_obj.storage_type_object[ priv.job.storage.type ]({
'job':priv.job,'queue':priv.queue})[priv.job.method]();
};
// These methods must be redefined!
that.checkNameAvailability = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.loadDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.saveDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.getDocumentList = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.removeDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
//// end Public Methods
return that;
......@@ -911,7 +919,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// JIO Constructor
JioConstructor = function ( storage , applicant, options ) {
newJioConstructor = function ( spec, my ) {
// JIO Constructor, create a new JIO object.
// It just initializes values.
// storage : the storage that contains {type:..,[storageinfos]}
......@@ -933,7 +941,7 @@ var JIO =
// set a new jio id
priv.id = priv.queue.getNewQueueID();
// initializing objects
priv.queue.init({'jioID':priv.id});
priv.queue.init({'jio_id':priv.id});
// start activity updater
if (priv.updater){
priv.updater.start(priv.id);
......@@ -1019,7 +1027,7 @@ var JIO =
// } else { } // Error
// }});
var settings = $.extend ({
var settings = extend ({
'userName': priv.storage.userName,
'storage': priv.storage,
'applicant': priv.applicant,
......@@ -1052,7 +1060,7 @@ var JIO =
// } else { } // Error
// }});
var settings = $.extend({
var settings = extend({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'saveDocument',
......@@ -1089,7 +1097,7 @@ var JIO =
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'loadDocument',
......@@ -1123,7 +1131,7 @@ var JIO =
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'getDocumentList',
......@@ -1153,7 +1161,7 @@ var JIO =
// } else { } // Not Removed
// }});
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'removeDocument',
......@@ -1168,33 +1176,36 @@ var JIO =
//// end Methods
//// Initialize
var settings = $.extend({'useLocalStorage':true},options);
var settings = extend({'use_local_storage':true},spec.options);
// objectify storage and applicant
if(typeof storage === 'string') {
storage = JSON.parse(options.storage);
if(typeof spec.storage === 'string') {
spec.storage = JSON.parse(spec.storage);
}
if(typeof applicant === 'string') {
applicant = JSON.parse(options.applicant);
if(typeof spec.applicant === 'string') {
spec.applicant = JSON.parse(spec.applicant);
}
// set init values
priv['storage'] = storage;
priv['applicant'] = applicant;
priv['storage'] = spec.storage;
priv['applicant'] = spec.applicant;
priv['id'] = 0;
priv['pubsub'] = new PubSub(settings);
priv['queue'] = new JobQueue(priv.pubsub,settings);
priv['listener'] = new JobListener(priv.queue,settings);
priv['pubsub'] = newPubSub({options:settings});
priv['queue'] = newJobQueue({publisher:priv.pubsub,
options:settings});
priv['listener'] = newJobListener({queue:priv.queue,
options:settings});
priv['ready'] = false;
if (settings.useLocalStorage) {
priv['updater'] = new ActivityUpdater(settings);
if (settings.use_local_storage) {
priv['updater'] = newActivityUpdater({options:settings});
} else {
priv['updater'] = null;
}
// check storage type
if (priv.storage && !jioGlobalObj.storageTypeObject[priv.storage.type]){
$.error('Unknown storage type "' + priv.storage.type +'"');
if (priv.storage &&
!jio_global_obj.storage_type_object[priv.storage.type]){
console.error('Unknown storage type "' + priv.storage.type +'"');
}
// start jio process
......@@ -1208,7 +1219,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// Jio creator
JioCreator = function () {
newJioCreator = function ( spec, my ) {
var that = {};
// Jio creator object
// this object permit to create jio object
......@@ -1218,18 +1229,16 @@ var JIO =
// applicant: the applicant object or json string
// options.useLocalStorage: if true, save job queue on localStorage.
var settings = $.extend({'useLocalStorage':true},options);
if (jioGlobalObj.localStorage===null) {
jioGlobalObj.localStorage = LocalOrCookieStorage;
}
var settings = extend({'use_local_storage':true},options);
return new JioConstructor(storage,applicant,settings);
return newJioConstructor({storage:storage,
applicant:applicant,
options:settings});
};
that.newBaseStorage = function ( options ) {
that.newBaseStorage = function ( spec, my ) {
// Create a Jio Storage which can be used to design new storage.
return new BaseStorage( options );
return newBaseStorage( spec, my );
};
that.addStorageType = function ( type, constructor ) {
// Add a storage type to jio. Jio must have keys/types which are
......@@ -1240,22 +1249,22 @@ var JIO =
// constructor : the function which returns a new storage object.
if (type && constructor) {
jioGlobalObj.storageTypeObject[type] = constructor;
jio_global_obj.storage_type_object[type] = constructor;
return true;
}
return false;
};
that.getGlobalObject = function () {
// Returns the global jio values
return jioGlobalObj;
return jio_global_obj;
};
that.getConstObject = function () {
// Returns a copy of the constants
return $.extend({},jioConstObj);
return extend({},jio_const_obj);
};
return that;
};
return new JioCreator();
return newJioCreator();
// end Jio Creator
////////////////////////////////////////////////////////////////////////////
};
......
/*! JIO - v0.1.0 - 2012-05-23
/*! JIO - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
var JIO=function(){var a=function(a,b){var c={jobMethodObject:{checkNameAvailability:{start_event:"start_checkingNameAvailability",stop_event:"stop_checkingNameAvailability",retvalue:"isAvailable"},saveDocument:{start_event:"start_saving",stop_event:"stop_saving",retvalue:"isSaved"},loadDocument:{start_event:"start_loading",stop_event:"stop_loading",retvalue:"fileContent"},getDocumentList:{start_event:"start_gettingList",stop_event:"stop_gettingList",retvalue:"list"},removeDocument:{start_event:"start_removing",stop_event:"stop_removing",retvalue:"isRemoved"}}},d={jobManagingMethod:{canSelect:function(a,b){return JSON.stringify(a.storage)===JSON.stringify(b.storage)&&JSON.stringify(a.applicant)===JSON.stringify(b.applicant)&&a.fileName===b.fileName?!0:!1},canRemoveFailOrDone:function(a,b){return a.status==="fail"||a.status==="done"?!0:!1},canEliminate:function(a,b){return a.status!=="ongoing"&&(a.method==="removeDocument"&&b.method==="saveDocument"||a.method==="saveDocument"&&b.method==="removeDocument")?!0:!1},canReplace:function(a,b){return a.status!=="ongoing"&&a.method===b.method&&a.date<b.date?!0:!1},cannotAccept:function(a,b){if(a.status!=="ongoing"){if(a.method==="removeDocument"&&b.method==="loadDocument")return!0}else{if(a.method===b.method==="loadDocument")return!0;if(a.method==="removeDocument"&&(b.method==="loadDocument"||b.method==="removeDocument"))return!0;if(a.method===b.method==="saveDocument"&&a.fileContent===b.fileContent)return!0;if(a.method===b.method==="getDocumentList"||a.method===b.method==="checkNameAvailability")return!0}return!1},mustWait:function(a,b){return a.method==="getDocumentList"||a.method==="checkNameAvailability"||b.method==="getDocumentList"||b.method==="checkNameAvailability"?!1:!0}},localStorage:null,queueID:1,storageTypeObject:{},max_wait_time:1e4},e,f,g,h,i,j,k,l;return e=function(){var a={},c={},d={},e,f;return c.eventAction=function(a){return f=a&&d[a],f||(e=b.Callbacks(),f={publish:e.fire,subscribe:e.add,unsubscribe:e.remove},a&&(d[a]=f)),f},a.publish=function(a,b){c.eventAction(a).publish(b)},a.subscribe=function(a,b){return c.eventAction(a).subscribe(b),b},a.unsubscribe=function(a,b){c.eventAction(a).unsubscribe(b)},a},f=function(a){var c=b.extend({},a);return c.id=0,c.status="initial",c.date=Date.now(),c},g=function(a,e){var g={},h={},i="jio/idArray";return g.init=function(b){var c,e=function(){},f=d.localStorage.getItem(i)||[];b.publisher&&(h.publisher=a),h.jioID=b.jioID,h.jobObjectName="jio/jobObject/"+b.jioID,h.jobObject={},f.push(h.jioID),d.localStorage.setItem(i,f),g.copyJobQueueToLocalStorage();for(c in h.recoveredJobObject)h.recoveredJobObject[c].callback=e,g.addJob(h.recoveredJobObject[c])},g.close=function(){JSON.stringify(h.jobObject)==="{}"&&d.localStorage.deleteItem(h.jobObjectName)},g.getNewQueueID=function(){var a=null,b=0,c=d.localStorage.getItem(i)||[];for(a=0;a<c.length;a+=1)c[a]>=d.queueID&&(d.queueID=c[a]+1);return b=d.queueID,d.queueID++,b},g.recoverOlderJobObject=function(){var a=null,b=[],c=!1,e=d.localStorage.getItem(i)||[];for(a=0;a<e.length;a+=1)d.localStorage.getItem("jio/id/"+e[a])<Date.now()-1e4?(d.localStorage.deleteItem("jio/id/"+e[a]),h.recoveredJobObject=d.localStorage.getItem("jio/jioObject/"+e[a]),d.localStorage.deleteItem("jio/jobObject/"+e[a]),c=!0):b.push(e[a]);c&&d.localStorage.setItem(i,b)},g.isThereJobsWhere=function(a){var b="id";if(!a)return!0;for(b in h.jobObject)if(a(h.jobObject[b]))return!0;return!1},g.copyJobQueueToLocalStorage=function(){return h.useLocalStorage?d.localStorage.setItem(h.jobObjectName,h.jobObject):!1},g.createJob=function(a){return g.addJob(new f(a))},g.addJob=function(a){var b={newone:!0,elimArray:[],waitArray:[],removeArray:[]},c=null,e="id";for(e in h.jobObject){if(d.jobManagingMethod.canRemoveFailOrDone(h.jobObject[e],a)){b.removeArray.push(e);continue}if(d.jobManagingMethod.canSelect(h.jobObject[e],a)){if(d.jobManagingMethod.canEliminate(h.jobObject[e],a)){b.elimArray.push(e);continue}if(d.jobManagingMethod.canReplace(h.jobObject[e],a)){c=new j({queue:g,job:h.jobObject[e]}),c.replace(a),b.newone=!1;break}if(d.jobManagingMethod.cannotAccept(h.jobObject[e],a))return!1;if(d.jobManagingMethod.mustWait(h.jobObject[e],a)){b.waitArray.push(e);continue}}}if(b.newone){for(e=0;e<b.elimArray.length;e+=1)c=new j({queue:g,job:h.jobObject[b.elimArray[e]]}),c.eliminate();if(b.waitArray.length>0){a.status="wait",a.waitingFor={jobIdArray:b.waitArray};for(e=0;e<b.waitArray.length;e+=1)h.jobObject[b.waitArray[e]]&&(h.jobObject[b.waitArray[e]].maxtries=1)}for(e=0;e<b.removeArray.length;e+=1)g.removeJob(h.jobObject[b.removeArray[e]]);a.id=h.jobid,a.tries=0,h.jobid++,h.jobObject[a.id]=a}return g.copyJobQueueToLocalStorage(),!0},g.removeJob=function(a){var c=b.extend({where:function(a){return!0}},a),d,e=!1,f="key";if(c.job)h.jobObject[c.job.id]&&c.where(h.jobObject[c.job.id])&&(delete h.jobObject[c.job.id],e=!0);else for(f in h.jobObject)c.where(h.jobObject[f])&&(delete h.jobObject[f],e=!0);e||b.error("No jobs was found, when trying to remove some."),g.copyJobQueueToLocalStorage()},g.resetAll=function(){var a="id";for(a in h.jobObject)h.jobObject[a].status="initial";g.copyJobQueueToLocalStorage()},g.invokeAll=function(){var a="id",b,c;for(a in h.jobObject){c=!1;if(h.jobObject[a].status==="initial")g.invoke(h.jobObject[a]);else if(h.jobObject[a].status==="wait"){c=!0;if(h.jobObject[a].waitingFor.jobIdArray)for(b=0;b<h.jobObject[a].waitingFor.jobIdArray.length;b+=1)if(h.jobObject[h.jobObject[a].waitingFor.jobIdArray[b]]){c=!1;break}h.jobObject[a].waitingFor.time&&h.jobObject[a].waitingFor.time>Date.now()&&(c=!1),c&&g.invoke(h.jobObject[a])}}this.copyJobQueueToLocalStorage()},g.invoke=function(a){var b;if(!c.jobMethodObject[a.method])return!1;g.isThereJobsWhere(function(b){return b.method===a.method&&b.method==="initial"})?a.status="ongoing":(a.status="ongoing",h.publisher.publish(c.jobMethodObject[a.method].start_event)),b=new j({queue:this,job:a}),b.execute()},g.ended=function(a){var d=b.extend({},a);g.removeJob({job:d});if(!c.jobMethodObject[d.method])return!1;if(!g.isThereJobsWhere(function(a){return a.method===d.method&&a.status==="ongoing"||a.status==="initial"})){h.publisher.publish(c.jobMethodObject[d.method].stop_event);return}},g.clean=function(){g.removeJob(undefined,{where:function(a){return a.status==="fail"}})},h.useLocalStorage=e.useLocalStorage,h.publisher=a,h.jobid=1,h.jioID=0,h.jobObjectName="",h.jobObject={},h.recoveredJobObject={},g},h=function(a){var b={},c={};return c.interval=200,c.id=null,c.queue=a,b.setIntervalDelay=function(a){c.interval=a},b.start=function(){return c.id?!1:(c.id=setInterval(function(){c.queue.recoverOlderJobObject(),c.queue.invokeAll()},c.interval),!0)},b.stop=function(){return c.id?(clearInterval(c.id),c.id=null,!0):!1},b},i=function(){var a={},b={};return b.interval=400,b.id=null,a.start=function(c){return b.id?!1:(a.touch(c),b.id=setInterval(function(){a.touch(c)},b.interval),!0)},a.stop=function(){return b.id?(clearInterval(b.id),b.id=null,!0):!1},a.touch=function(a){d.localStorage.setItem("jio/id/"+a,Date.now())},a},j=function(a){var c={},e={};return e.job=a.job,e.callback=a.job.callback,e.queue=a.queue,e.res={status:"done",message:""},e.fail_checkNameAvailability=function(){e.res.message="Unable to check name availability."},e.done_checkNameAvailability=function(a){e.res.message=e.job.userName+" is "+(a?"":"not ")+"available.",e.res.return_value=a},e.fail_loadDocument=function(){e.res.message="Unable to load document."},e.done_loadDocument=function(a){e.res.message="Document loaded.",e.res.return_value=a,e.res.return_value.lastModified=(new Date(e.res.return_value.lastModified)).getTime(),e.res.return_value.creationDate=(new Date(e.res.return_value.creationDate)).getTime()},e.fail_saveDocument=function(){e.res.message="Unable to save document."},e.done_saveDocument=function(){e.res.message="Document saved."},e.fail_getDocumentList=function(){e.res.message="Unable to retrieve document list."},e.done_getDocumentList=function(a){var b;e.res.message="Document list received.",e.res.return_value=a;for(b=0;b<e.res.return_value.length;b+=1)e.res.return_value[b].lastModified=(new Date(e.res.return_value[b].lastModified)).getTime(),e.res.return_value[b].creationDate=(new Date(e.res.return_value[b].creationDate)).getTime()},e.fail_removeDocument=function(){e.res.message="Unable to removed document."},e.done_removeDocument=function(){e.res.message="Document removed."},e.retryLater=function(){var a=e.job.tries*e.job.tries*1e3;a>d.max_wait_time&&(a=d.max_wait_time),e.job.status="wait",e.job.waitingFor={time:Date.now()+a}},c.cloneJob=function(){return b.extend({},e.job)},c.getUserName=function(){return e.job.userName||""},c.getApplicantID=function(){return e.job.applicant.ID||""},c.getStorageUserName=function(){return e.job.storage.userName||""},c.getStoragePassword=function(){return e.job.storage.password||""},c.getStorageLocation=function(){return e.job.storage.location||""},c.getStorageArray=function(){return e.job.storage.storageArray||[]},c.getFileName=function(){return e.job.fileName||""},c.getFileContent=function(){return e.job.fileContent||""},c.cloneOptionObject=function(){return b.extend({},e.job.options)},c.getMaxTries=function(){return e.job.maxtries},c.getTries=function(){return e.job.tries||0},c.setMaxTries=function(a){e.job.maxtries=a},c.addJob=function(a){return e.queue.createJob(a)},c.eliminate=function(){e.job.maxtries=1,e.job.tries=1,c.fail("Job Stopped!",0)},c.replace=function(a){e.job.tries=0,e.job.date=a.date,e.job.callback=a.callback,e.res.status="fail",e.res.message="Job Stopped!",e.res.error={},e.res.error.status=0,e.res.error.statusText="Replaced",e.res.error.message="The job was replaced by a newer one.",e["fail_"+e.job.method](),e.callback(e.res)},c.fail=function(a){e.res.status="fail",e.res.error=a,e.res.error.status=e.res.error.status||0,e.res.error.statusText=e.res.error.statusText||"Unknown Error",e.res.error.array=e.res.error.array||[],e.res.error.message=e.res.error.message||"",!e.job.maxtries||e.job.tries<e.job.maxtries?e.retryLater():(e.job.status="fail",e["fail_"+e.job.method](),e.queue.ended(e.job),e.callback(e.res))},c.done=function(a){e.job.status="done",e["done_"+e.job.method](a),e.queue.ended(e.job),e.callback(e.res)},c.execute=function(){return e.job.tries=c.getTries()+1,d.storageTypeObject[e.job.storage.type]?d.storageTypeObject[e.job.storage.type]({job:e.job,queue:e.queue})[e.job.method]():null},c.checkNameAvailability=function(){c.fail("This method must be redefined!",0)},c.loadDocument=function(){c.fail("This method must be redefined!",0)},c.saveDocument=function(){c.fail("This method must be redefined!",0)},c.getDocumentList=function(){c.fail("This method must be redefined!",0)},c.removeDocument=function(){c.fail("This method must be redefined!",0)},c},k=function(a,c,f){var j={},k={};j.getID=function(){return k.id},j.start=function(){return k.id!==0?!1:(k.id=k.queue.getNewQueueID(),k.queue.init({jioID:k.id}),k.updater&&k.updater.start(k.id),k.listener.start(),k.ready=!0,j.isReady())},j.stop=function(){return k.queue.close(),k.listener.stop(),k.updater&&k.updater.stop(),k.ready=!1,k.id=0,!0},j.kill=function(){return k.queue.close(),k.listener.stop(),k.updater&&k.updater.stop(),k.ready=!1,!0},j.isReady=function(){return k.ready},j.publish=function(a,b){if(!j.isReady())return;return k.pubsub.publish(a,b)},j.subscribe=function(a,b){return k.pubsub.subscribe(a,b)},j.unsubscribe=function(a,b){return k.pubsub.unsubscribe(a,b)},j.checkNameAvailability=function(a){var c=b.extend({userName:k.storage.userName,storage:k.storage,applicant:k.applicant,method:"checkNameAvailability",callback:function(){}},a);return j.isReady()&&c.userName&&c.storage&&c.applicant?k.queue.createJob(c):null},j.saveDocument=function(a){var c=b.extend({storage:k.storage,applicant:k.applicant,method:"saveDocument",callback:function(){}},a);return j.isReady()&&c.fileName&&c.fileContent&&c.storage&&c.applicant?k.queue.createJob(c):null},j.loadDocument=function(a){var c=b.extend({storage:k.storage,applicant:k.applicant,method:"loadDocument",callback:function(){}},a);return j.isReady()&&c.fileName&&c.storage&&c.applicant?k.queue.createJob(c):null},j.getDocumentList=function(a){var c=b.extend({storage:k.storage,applicant:k.applicant,method:"getDocumentList",callback:function(){}},a);return j.isReady()&&c.storage&&c.applicant?k.queue.createJob(c):null},j.removeDocument=function(a){var c=b.extend({storage:k.storage,applicant:k.applicant,method:"removeDocument",callback:function(){}},a);return j.isReady()&&c.fileName&&c.storage&&c.applicant?k.queue.createJob(c):null};var l=b.extend({useLocalStorage:!0},f);return typeof a=="string"&&(a=JSON.parse(f.storage)),typeof c=="string"&&(c=JSON.parse(f.applicant)),k.storage=a,k.applicant=c,k.id=0,k.pubsub=new e(l),k.queue=new g(k.pubsub,l),k.listener=new h(k.queue,l),k.ready=!1,l.useLocalStorage?k.updater=new i(l):k.updater=null,k.storage&&!d.storageTypeObject[k.storage.type]&&b.error('Unknown storage type "'+k.storage.type+'"'),j.start(),j},l=function(){var e={};return e.createNew=function(c,e,f){var g=b.extend({useLocalStorage:!0},f);return d.localStorage===null&&(d.localStorage=a),new k(c,e,g)},e.newBaseStorage=function(a){return new j(a)},e.addStorageType=function(a,b){return a&&b?(d.storageTypeObject[a]=b,!0):!1},e.getGlobalObject=function(){return d},e.getConstObject=function(){return b.extend({},c)},e},new l};return window.requirejs?(define("JIO",["LocalOrCookieStorage","jQuery"],a),undefined):a(LocalOrCookieStorage,jQuery)}();
\ No newline at end of file
var JIO=function(){var a=function(a,b){var c={job_method_object:{checkNameAvailability:{},saveDocument:{},loadDocument:{},getDocumentList:{},removeDocument:{}}},d={job_managing_method:{canSelect:function(a,b){return JSON.stringify(a.storage)===JSON.stringify(b.storage)&&JSON.stringify(a.applicant)===JSON.stringify(b.applicant)&&a.fileName===b.fileName?!0:!1},canRemoveFailOrDone:function(a,b){return a.status==="fail"||a.status==="done"?!0:!1},canEliminate:function(a,b){return a.status!=="ongoing"&&(a.method==="removeDocument"&&b.method==="saveDocument"||a.method==="saveDocument"&&b.method==="removeDocument")?!0:!1},canReplace:function(a,b){return a.status!=="ongoing"&&a.method===b.method&&a.date<b.date?!0:!1},cannotAccept:function(a,b){if(a.status!=="ongoing"){if(a.method==="removeDocument"&&b.method==="loadDocument")return!0}else{if(a.method===b.method==="loadDocument")return!0;if(a.method==="removeDocument"&&(b.method==="loadDocument"||b.method==="removeDocument"))return!0;if(a.method===b.method==="saveDocument"&&a.fileContent===b.fileContent)return!0;if(a.method===b.method==="getDocumentList"||a.method===b.method==="checkNameAvailability")return!0}return!1},mustWait:function(a,b){return a.method==="getDocumentList"||a.method==="checkNameAvailability"||b.method==="getDocumentList"||b.method==="checkNameAvailability"?!1:!0}},queue_id:1,storage_type_object:{},max_wait_time:1e4},e=function(a,b){var c;for(c in b)a[c]=b[c];return a},f,g,h,i,j,k,l,m;return f=function(a,c){var d={},e={},f={},g,h;return e.eventAction=function(a){return h=a&&f[a],h||(g=b.Callbacks(),h={publish:g.fire,subscribe:g.add,unsubscribe:g.remove},a&&(f[a]=h)),h},d.publish=function(a,b){e.eventAction(a).publish(b)},d.subscribe=function(a,b){return e.eventAction(a).subscribe(b),b},d.unsubscribe=function(a,b){e.eventAction(a).unsubscribe(b)},d},g=function(a,b){var c=e({},a);return c.id=0,c.status="initial",c.date=Date.now(),c},h=function(b,f){var h={},i={},j="jio/idarray";return h.init=function(c){var d,e=function(){},f;i.use_local_storage&&(f=a.getItem(j)||[],b.publisher&&(i.publisher=b.publisher),i.jio_id=c.jio_id,i.job_object_name="jio/jobobject/"+i.jio_id,f.push(i.jio_id),a.setItem(j,f)),i.job_object={},h.copyJobQueueToLocalStorage();for(d in i.recovered_job_object)i.recovered_job_object[d].callback=e,h.addJob(i.recovered_job_object[d])},h.close=function(){JSON.stringify(i.job_object)==="{}"&&a.deleteItem(i.job_object_name)},h.getNewQueueID=function(){var b=null,c=0,e=a.getItem(j)||[];for(b=0;b<e.length;b+=1)e[b]>=d.queue_id&&(d.queue_id=e[b]+1);return c=d.queue_id,d.queue_id++,c},h.recoverOlderJobObject=function(){var b=null,c=[],d=!1,e;if(i.use_local_storage){e=a.getItem(j)||[];for(b=0;b<e.length;b+=1)a.getItem("jio/id/"+e[b])<Date.now()-1e4?(a.deleteItem("jio/id/"+e[b]),i.recovered_job_object=a.getItem("jio/jobobject/"+e[b]),a.deleteItem("jio/jobobject/"+e[b]),d=!0):c.push(e[b]);d&&a.setItem(j,c)}},h.isThereJobsWhere=function(a){var b="id";if(!a)return!0;for(b in i.job_object)if(a(i.job_object[b]))return!0;return!1},h.copyJobQueueToLocalStorage=function(){return i.use_local_storage?a.setItem(i.job_object_name,i.job_object):!1},h.createJob=function(a){return h.addJob(g(a))},h.addJob=function(a){var b=!0,c=[],e=[],f=[],g=null,j="id";for(j in i.job_object){if(d.job_managing_method.canRemoveFailOrDone(i.job_object[j],a)){f.push(j);continue}if(d.job_managing_method.canSelect(i.job_object[j],a)){if(d.job_managing_method.canEliminate(i.job_object[j],a)){c.push(j);continue}if(d.job_managing_method.canReplace(i.job_object[j],a)){g=k({queue:h,job:i.job_object[j]}),g.replace(a),b=!1;break}if(d.job_managing_method.cannotAccept(i.job_object[j],a))return!1;if(d.job_managing_method.mustWait(i.job_object[j],a)){e.push(j);continue}}}if(b){for(j=0;j<c.length;j+=1)g=k({queue:h,job:i.job_object[c[j]]}),g.eliminate();if(e.length>0){a.status="wait",a.waitingFor={jobIdArray:e};for(j=0;j<e.length;j+=1)i.job_object[e[j]]&&(i.job_object[e[j]].maxtries=1)}for(j=0;j<f.length;j+=1)h.removeJob(i.job_object[f[j]]);a.id=i.job_id,a.tries=0,i.job_id++,i.job_object[a.id]=a}return h.copyJobQueueToLocalStorage(),!0},h.removeJob=function(a){var b=e({where:function(a){return!0}},a),c,d=!1,f="key";if(b.job)i.job_object[b.job.id]&&b.where(i.job_object[b.job.id])&&(delete i.job_object[b.job.id],d=!0);else for(f in i.job_object)b.where(i.job_object[f])&&(delete i.job_object[f],d=!0);d||console.error("No jobs was found, when trying to remove some."),h.copyJobQueueToLocalStorage()},h.resetAll=function(){var a="id";for(a in i.job_object)i.job_object[a].status="initial";h.copyJobQueueToLocalStorage()},h.invokeAll=function(){var a="id",b,c;for(a in i.job_object){c=!1;if(i.job_object[a].status==="initial")h.invoke(i.job_object[a]);else if(i.job_object[a].status==="wait"){c=!0;if(i.job_object[a].waitingFor.jobIdArray)for(b=0;b<i.job_object[a].waitingFor.jobIdArray.length;b+=1)if(i.job_object[i.job_object[a].waitingFor.jobIdArray[b]]){c=!1;break}i.job_object[a].waitingFor.time&&i.job_object[a].waitingFor.time>Date.now()&&(c=!1),c&&h.invoke(i.job_object[a])}}this.copyJobQueueToLocalStorage()},h.invoke=function(a){var b;if(!c.job_method_object[a.method])return!1;h.isThereJobsWhere(function(b){return b.method===a.method&&b.method==="initial"})?a.status="ongoing":(a.status="ongoing",i.publisher.publish(c.job_method_object[a.method]["start_"+a.method])),b=k({queue:this,job:a}),b.execute()},h.ended=function(a){var b=e({},a);h.removeJob({job:b});if(!c.job_method_object[b.method])return!1;if(!h.isThereJobsWhere(function(a){return a.method===b.method&&a.status==="ongoing"||a.status==="initial"})){i.publisher.publish(c.job_method_object[b.method]["stop_"+b.method]);return}},h.clean=function(){h.removeJob(undefined,{where:function(a){return a.status==="fail"}})},i.use_local_storage=b.options.use_local_storage,i.publisher=b.publisher,i.job_id=1,i.jio_id=0,i.job_object_name="",i.job_object={},i.recovered_job_object={},h},i=function(a,b){var c={},d={};return d.interval=200,d.id=null,d.queue=a.queue,c.setIntervalDelay=function(a){d.interval=a},c.start=function(){return d.id?!1:(d.id=setInterval(function(){d.queue.recoverOlderJobObject(),d.queue.invokeAll()},d.interval),!0)},c.stop=function(){return d.id?(clearInterval(d.id),d.id=null,!0):!1},c},j=function(){var b={},c={};return c.interval=400,c.id=null,b.start=function(a){return c.id?!1:(b.touch(a),c.id=setInterval(function(){b.touch(a)},c.interval),!0)},b.stop=function(){return c.id?(clearInterval(c.id),c.id=null,!0):!1},b.touch=function(b){a.setItem("jio/id/"+b,Date.now())},b},k=function(a){var b={},c={};return c.job=a.job,c.callback=a.job.callback,c.queue=a.queue,c.res={status:"done",message:""},c.fail_checkNameAvailability=function(){c.res.message="Unable to check name availability."},c.done_checkNameAvailability=function(a){c.res.message=c.job.userName+" is "+(a?"":"not ")+"available.",c.res.return_value=a},c.fail_loadDocument=function(){c.res.message="Unable to load document."},c.done_loadDocument=function(a){c.res.message="Document loaded.",c.res.return_value=a,c.res.return_value.lastModified=(new Date(c.res.return_value.lastModified)).getTime(),c.res.return_value.creationDate=(new Date(c.res.return_value.creationDate)).getTime()},c.fail_saveDocument=function(){c.res.message="Unable to save document."},c.done_saveDocument=function(){c.res.message="Document saved."},c.fail_getDocumentList=function(){c.res.message="Unable to retrieve document list."},c.done_getDocumentList=function(a){var b;c.res.message="Document list received.",c.res.return_value=a;for(b=0;b<c.res.return_value.length;b+=1)c.res.return_value[b].lastModified=(new Date(c.res.return_value[b].lastModified)).getTime(),c.res.return_value[b].creationDate=(new Date(c.res.return_value[b].creationDate)).getTime()},c.fail_removeDocument=function(){c.res.message="Unable to removed document."},c.done_removeDocument=function(){c.res.message="Document removed."},c.retryLater=function(){var a=c.job.tries*c.job.tries*1e3;a>d.max_wait_time&&(a=d.max_wait_time),c.job.status="wait",c.job.waitingFor={time:Date.now()+a}},b.cloneJob=function(){return e({},c.job)},b.getUserName=function(){return c.job.userName||""},b.getApplicantID=function(){return c.job.applicant.ID||""},b.getStorageUserName=function(){return c.job.storage.userName||""},b.getStoragePassword=function(){return c.job.storage.password||""},b.getStorageLocation=function(){return c.job.storage.location||""},b.getStorageArray=function(){return c.job.storage.storageArray||[]},b.getFileName=function(){return c.job.fileName||""},b.getFileContent=function(){return c.job.fileContent||""},b.cloneOptionObject=function(){return e({},c.job.options)},b.getMaxTries=function(){return c.job.maxtries},b.getTries=function(){return c.job.tries||0},b.setMaxTries=function(a){c.job.maxtries=a},b.addJob=function(a){return c.queue.createJob(a)},b.eliminate=function(){c.job.maxtries=1,c.job.tries=1,b.fail("Job Stopped!",0)},b.replace=function(a){c.job.tries=0,c.job.date=a.date,c.job.callback=a.callback,c.res.status="fail",c.res.message="Job Stopped!",c.res.error={},c.res.error.status=0,c.res.error.statusText="Replaced",c.res.error.message="The job was replaced by a newer one.",c["fail_"+c.job.method](),c.callback(c.res)},b.fail=function(a){c.res.status="fail",c.res.error=a,c.res.error.status=c.res.error.status||0,c.res.error.statusText=c.res.error.statusText||"Unknown Error",c.res.error.array=c.res.error.array||[],c.res.error.message=c.res.error.message||"",!c.job.maxtries||c.job.tries<c.job.maxtries?c.retryLater():(c.job.status="fail",c["fail_"+c.job.method](),c.queue.ended(c.job),c.callback(c.res))},b.done=function(a){c.job.status="done",c["done_"+c.job.method](a),c.queue.ended(c.job),c.callback(c.res)},b.execute=function(){return c.job.tries=b.getTries()+1,d.storage_type_object[c.job.storage.type]?d.storage_type_object[c.job.storage.type]({job:c.job,queue:c.queue})[c.job.method]():null},b.checkNameAvailability=function(){b.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},b.loadDocument=function(){b.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},b.saveDocument=function(){b.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},b.getDocumentList=function(){b.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},b.removeDocument=function(){b.fail({status:0,statusText:"Undefined Method",message:"This method must be redefined!"})},b},l=function(a,b){var c={},g={};c.getID=function(){return g.id},c.start=function(){return g.id!==0?!1:(g.id=g.queue.getNewQueueID(),g.queue.init({jio_id:g.id}),g.updater&&g.updater.start(g.id),g.listener.start(),g.ready=!0,c.isReady())},c.stop=function(){return g.queue.close(),g.listener.stop(),g.updater&&g.updater.stop(),g.ready=!1,g.id=0,!0},c.kill=function(){return g.queue.close(),g.listener.stop(),g.updater&&g.updater.stop(),g.ready=!1,!0},c.isReady=function(){return g.ready},c.publish=function(a,b){if(!c.isReady())return;return g.pubsub.publish(a,b)},c.subscribe=function(a,b){return g.pubsub.subscribe(a,b)},c.unsubscribe=function(a,b){return g.pubsub.unsubscribe(a,b)},c.checkNameAvailability=function(a){var b=e({userName:g.storage.userName,storage:g.storage,applicant:g.applicant,method:"checkNameAvailability",callback:function(){}},a);return c.isReady()&&b.userName&&b.storage&&b.applicant?g.queue.createJob(b):null},c.saveDocument=function(a){var b=e({storage:g.storage,applicant:g.applicant,method:"saveDocument",callback:function(){}},a);return c.isReady()&&b.fileName&&b.fileContent&&b.storage&&b.applicant?g.queue.createJob(b):null},c.loadDocument=function(a){var b=e({storage:g.storage,applicant:g.applicant,method:"loadDocument",callback:function(){}},a);return c.isReady()&&b.fileName&&b.storage&&b.applicant?g.queue.createJob(b):null},c.getDocumentList=function(a){var b=e({storage:g.storage,applicant:g.applicant,method:"getDocumentList",callback:function(){}},a);return c.isReady()&&b.storage&&b.applicant?g.queue.createJob(b):null},c.removeDocument=function(a){var b=e({storage:g.storage,applicant:g.applicant,method:"removeDocument",callback:function(){}},a);return c.isReady()&&b.fileName&&b.storage&&b.applicant?g.queue.createJob(b):null};var k=e({use_local_storage:!0},a.options);return typeof a.storage=="string"&&(a.storage=JSON.parse(a.storage)),typeof a.applicant=="string"&&(a.applicant=JSON.parse(a.applicant)),g.storage=a.storage,g.applicant=a.applicant,g.id=0,g.pubsub=f({options:k}),g.queue=h({publisher:g.pubsub,options:k}),g.listener=i({queue:g.queue,options:k}),g.ready=!1,k.use_local_storage?g.updater=j({options:k}):g.updater=null,g.storage&&!d.storage_type_object[g.storage.type]&&console.error('Unknown storage type "'+g.storage.type+'"'),c.start(),c},m=function(a,b){var f={};return f.createNew=function(a,b,c){var d=e({use_local_storage:!0},c);return l({storage:a,applicant:b,options:d})},f.newBaseStorage=function(a,b){return k(a,b)},f.addStorageType=function(a,b){return a&&b?(d.storage_type_object[a]=b,!0):!1},f.getGlobalObject=function(){return d},f.getConstObject=function(){return e({},c)},f},m()};return window.requirejs?(define("JIO",["LocalOrCookieStorage","jQuery"],a),undefined):a(LocalOrCookieStorage,jQuery)}();
\ No newline at end of file
/*! JIO Storage - v0.1.0 - 2012-05-23
/*! JIO Storage - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -12,21 +12,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// Tools
var extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Classes
var LocalStorage,DAVStorage,ReplicateStorage;
newLocalStorage,newDAVStorage,newReplicateStorage;
// end Classes
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Local Storage
LocalStorage = function ( args ) {
newLocalStorage = function ( spec, my ) {
// LocalStorage constructor
var that = Jio.newBaseStorage( args ), priv = {};
var that = Jio.newBaseStorage( spec, my ), priv = {};
that.checkNameAvailability = function () {
// checks the availability of the [job.userName].
......@@ -99,7 +106,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
var doc = null, settings = $.extend(
var doc = null, settings = extend(
{'getContent':true},that.cloneOptionObject());
doc = LocalOrCookieStorage.getItem(
......@@ -174,8 +181,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// DAVStorage
DAVStorage = function ( args ) {
var that = Jio.newBaseStorage( args );
newDAVStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my );
that.mkcol = function ( options ) {
// create folders in dav storage, synchronously
......@@ -188,7 +195,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO this method is not working !!!
var settings = $.extend ({
var settings = extend ({
'success':function(){},'error':function(){}},options),
splitpath = ['splitedpath'], tmppath = 'temp/path';
......@@ -321,7 +328,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'creationDate':date,'lastModified':date}
var doc = {},
settings = $.extend({'getContent':true},that.cloneOptionObject()),
settings = extend({'getContent':true},that.cloneOptionObject()),
// TODO check if job's features are good
getContent = function () {
......@@ -476,12 +483,10 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.getStorageUserName() + ':' +
that.getStoragePassword() )},
// xhrFields: {withCredentials: 'true'}, // cross domain
success: function (a) {
console.log (a);
success: function () {
that.done();
},
error: function (type) {
console.log (type);
if (type.status === 404) {
that.done();
} else {
......@@ -499,8 +504,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// ReplicateStorage
ReplicateStorage = function ( args ) {
var that = Jio.newBaseStorage( args ), priv = {};
newReplicateStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storageArray = that.getStorageArray();
// TODO Add a tests that check if there is no duplicate storages.
......@@ -706,13 +711,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// add key to storageObjectType of global jio
Jio.addStorageType('local', function (options) {
return new LocalStorage(options);
return newLocalStorage(options);
});
Jio.addStorageType('dav', function (options) {
return new DAVStorage(options);
return newDAVStorage(options);
});
Jio.addStorageType('replicate', function (options) {
return new ReplicateStorage(options);
return newReplicateStorage(options);
});
};
......
/*! JIO Storage - v0.1.0 - 2012-05-23
/*! JIO Storage - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
(function(){var a=function(a,b,c,d){var e,f,g;e=function(b){var e=c.newBaseStorage(b),f={};return e.checkNameAvailability=function(){setTimeout(function(){var b=null,c,d;b=a.getAll();for(c in b){d=c.split("/");if(d[0]==="jio"&&d[1]==="local"&&d[2]===e.getUserName())return e.done(!1)}return e.done(!0)},100)},e.saveDocument=function(){setTimeout(function(){var b=null;return b=a.getItem("jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName()),b?(b.lastModified=Date.now(),b.fileContent=e.getFileContent()):b={fileName:e.getFileName(),fileContent:e.getFileContent(),creationDate:Date.now(),lastModified:Date.now()},a.setItem("jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName(),b),e.done()},100)},e.loadDocument=function(){setTimeout(function(){var b=null,c=d.extend({getContent:!0},e.cloneOptionObject());b=a.getItem("jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName()),b?(c.getContent||delete b.fileContent,e.done(b)):e.fail({status:404,statusText:"Not Found.",message:'Document "'+e.getFileName()+'" not found in localStorage.'})},100)},e.getDocumentList=function(){setTimeout(function(){var b=[],c=null,d="key",f=["splitedkey"],g={};c=a.getAll();for(d in c)f=d.split("/"),f[0]==="jio"&&f[1]==="local"&&f[2]===e.getStorageUserName()&&f[3]===e.getApplicantID()&&(g=JSON.parse(c[d]),b.push({fileName:g.fileName,creationDate:g.creationDate,lastModified:g.lastModified}));e.done(b)},100)},e.removeDocument=function(){setTimeout(function(){return a.deleteItem("jio/local/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName()),e.done()},100)},e},f=function(a){var e=c.newBaseStorage(a);return e.mkcol=function(a){var c=d.extend({success:function(){},error:function(){}},a),f=["splitedpath"],g="temp/path";if(!c.pathsteps)c.pathsteps=1,e.mkcol(c);else{f=c.path.split("/");if(c.pathsteps>=f.length-1)return c.success();f.length=c.pathsteps+1,c.pathsteps++,g=f.join("/"),d.ajax({url:c.location+g,type:"MKCOL",async:!0,headers:{Authorization:"Basic "+b.encode(c.userName+":"+c.password),Depth:"1"},success:function(){e.mkcol(c)},error:function(a){c.error()}})}},e.checkNameAvailability=function(){d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword()),Depth:"1"},success:function(a){e.done(!1)},error:function(a){a.status===404?e.done(!0):(a.message='Cannot check availability of "'+e.getUserName()+'" into DAVStorage.',e.fail(a))}})},e.saveDocument=function(){d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName(),type:"PUT",data:e.getFileContent(),async:!0,dataType:"text",headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword())},success:function(){e.done()},error:function(a){a.message='Cannot save "'+e.getFileName()+'" into DAVStorage.',e.fail(a)}})},e.loadDocument=function(){var a={},c=d.extend({getContent:!0},e.cloneOptionObject()),f=function(){d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName(),type:"GET",async:!0,dataType:"text",headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword())},success:function(b){a.fileContent=b,e.done(a)},error:function(a){a.status===404?a.message='Document "'+e.getFileName()+'" not found in localStorage.':a.message='Cannot load "'+e.getFileName()+'" from DAVStorage.',e.fail(a)}})};d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName(),type:"PROPFIND",async:!0,dataType:"xml",headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword())},success:function(b){d(b).find("lp1\\:getlastmodified, getlastmodified").each(function(){a.lastModified=d(this).text()}),d(b).find("lp1\\:creationdate, creationdate").each(function(){a.creationDate=d(this).text()}),a.fileName=e.getFileName(),c.getContent?f():e.done(a)},error:function(a){a.message='Cannot load "'+e.getFileName()+'" informations from DAVStorage.',e.fail(a)}})},e.getDocumentList=function(){var a=[],c={},f=[];d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword()),Depth:"1"},success:function(b){d(b).find("D\\:response, response").each(function(b,e){if(b>0){c={},d(e).find("D\\:href, href").each(function(){f=d(this).text().split("/"),c.fileName=f[f.length-1]?f[f.length-1]:f[f.length-2]+"/"});if(c.fileName===".htaccess"||c.fileName===".htpasswd")return;d(e).find("lp1\\:getlastmodified, getlastmodified").each(function(){c.lastModified=d(this).text()}),d(e).find("lp1\\:creationdate, creationdate").each(function(){c.creationDate=d(this).text()}),a.push(c)}}),e.done(a)},error:function(a){a.message="Cannot get a document list from DAVStorage.",e.fail(a)}})},e.removeDocument=function(){d.ajax({url:e.getStorageLocation()+"/dav/"+e.getStorageUserName()+"/"+e.getApplicantID()+"/"+e.getFileName(),type:"DELETE",async:!0,headers:{Authorization:"Basic "+b.encode(e.getStorageUserName()+":"+e.getStoragePassword())},success:function(a){console.log(a),e.done()},error:function(a){console.log(a),a.status===404?e.done():(a.message='Cannot remove "'+e.getFileName()+'" from DAVStorage.',e.fail(a))}})},e},g=function(a){var b=c.newBaseStorage(a),d={};return d.storageArray=b.getStorageArray(),d.length=d.storageArray.length,d.returnsValuesArray=[],d.maxtries=b.getMaxTries(),b.setMaxTries(1),d.execJobsFromStorageArray=function(a){var c={},e;for(e=0;e<d.storageArray.length;e+=1)c=b.cloneJob(),c.maxtries=d.maxtries,c.storage=d.storageArray[e],c.callback=a,b.addJob(c)},b.checkNameAvailability=function(){var a={},c="id",e=!1,f=[],g={status:"done"},h=function(a){d.returnsValuesArray.push(a);if(!e){if(a.status==="fail")g.status="fail",f.push(a.error);else if(a.return_value===!1){b.done(!1),e=!0;return}if(d.returnsValuesArray.length===d.length){g.status==="fail"?b.fail({status:207,statusText:"Multi-Status",message:'Some check availability of "'+b.getUserName()+'" requests have failed.',array:f}):b.done(!0),e=!0;return}}};d.execJobsFromStorageArray(h)},b.saveDocument=function(){var a={},c={status:"done"},e="id",f=!1,g=[],h=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):(g.push(a.error),d.returnsValuesArray.length===d.length&&b.fail({status:207,statusText:"Multi-Status",message:'All save "'+b.getFileName()+'" requests have failed.',array:g})))};d.execJobsFromStorageArray(h)},b.loadDocument=function(){var a={},c=!1,e={},f="id",g=!1,h=[],i={status:"done"},j=function(a){d.returnsValuesArray.push(a),g||(a.status!=="fail"?(b.done(a.return_value),g=!0):(h.push(a.error),d.returnsValuesArray.length===d.length&&b.fail({status:207,statusText:"Multi-Status",message:'All load "'+b.getFileName()+'" requests have failed.',array:h})))};d.execJobsFromStorageArray(j)},b.getDocumentList=function(){var a={},c={status:"done"},e="id",f=!1,g=[],h=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(a.return_value),f=!0):(g.push(a.error),d.returnsValuesArray.length===d.length&&b.fail({status:207,statusText:"Multi-Status",message:"All get document list requests have failed",array:g})))};d.execJobsFromStorageArray(h)},b.removeDocument=function(){var a={},c={status:"done"},e="key",f=!1,g=[],h=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):(g.push(a.error),d.returnsValuesArray.length===d.length&&b.fail({status:207,statusText:"Multi-Status",message:'All remove "'+b.getFileName()+'" requests have failed.',array:g})))};d.execJobsFromStorageArray(h)},b},c.addStorageType("local",function(a){return new e(a)}),c.addStorageType("dav",function(a){return new f(a)}),c.addStorageType("replicate",function(a){return new g(a)})};window.requirejs?define("JIOStorages",["LocalOrCookieStorage","Base64","JIO","jQuery"],a):a(LocalOrCookieStorage,Base64,JIO,jQuery)})();
\ No newline at end of file
(function(){var a=function(a,b,c,d){var e=function(a,b){var c;for(c in b)a[c]=b[c];return a},f,g,h;f=function(b,d){var f=c.newBaseStorage(b,d),g={};return f.checkNameAvailability=function(){setTimeout(function(){var b=null,c,d;b=a.getAll();for(c in b){d=c.split("/");if(d[0]==="jio"&&d[1]==="local"&&d[2]===f.getUserName())return f.done(!1)}return f.done(!0)},100)},f.saveDocument=function(){setTimeout(function(){var b=null;return b=a.getItem("jio/local/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName()),b?(b.lastModified=Date.now(),b.fileContent=f.getFileContent()):b={fileName:f.getFileName(),fileContent:f.getFileContent(),creationDate:Date.now(),lastModified:Date.now()},a.setItem("jio/local/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName(),b),f.done()},100)},f.loadDocument=function(){setTimeout(function(){var b=null,c=e({getContent:!0},f.cloneOptionObject());b=a.getItem("jio/local/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName()),b?(c.getContent||delete b.fileContent,f.done(b)):f.fail({status:404,statusText:"Not Found.",message:'Document "'+f.getFileName()+'" not found in localStorage.'})},100)},f.getDocumentList=function(){setTimeout(function(){var b=[],c=null,d="key",e=["splitedkey"],g={};c=a.getAll();for(d in c)e=d.split("/"),e[0]==="jio"&&e[1]==="local"&&e[2]===f.getStorageUserName()&&e[3]===f.getApplicantID()&&(g=JSON.parse(c[d]),b.push({fileName:g.fileName,creationDate:g.creationDate,lastModified:g.lastModified}));f.done(b)},100)},f.removeDocument=function(){setTimeout(function(){return a.deleteItem("jio/local/"+f.getStorageUserName()+"/"+f.getApplicantID()+"/"+f.getFileName()),f.done()},100)},f},g=function(a,f){var g=c.newBaseStorage(a,f);return g.mkcol=function(a){var c=e({success:function(){},error:function(){}},a),f=["splitedpath"],h="temp/path";if(!c.pathsteps)c.pathsteps=1,g.mkcol(c);else{f=c.path.split("/");if(c.pathsteps>=f.length-1)return c.success();f.length=c.pathsteps+1,c.pathsteps++,h=f.join("/"),d.ajax({url:c.location+h,type:"MKCOL",async:!0,headers:{Authorization:"Basic "+b.encode(c.userName+":"+c.password),Depth:"1"},success:function(){g.mkcol(c)},error:function(a){c.error()}})}},g.checkNameAvailability=function(){d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword()),Depth:"1"},success:function(a){g.done(!1)},error:function(a){a.status===404?g.done(!0):(a.message='Cannot check availability of "'+g.getUserName()+'" into DAVStorage.',g.fail(a))}})},g.saveDocument=function(){d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/"+g.getApplicantID()+"/"+g.getFileName(),type:"PUT",data:g.getFileContent(),async:!0,dataType:"text",headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword())},success:function(){g.done()},error:function(a){a.message='Cannot save "'+g.getFileName()+'" into DAVStorage.',g.fail(a)}})},g.loadDocument=function(){var a={},c=e({getContent:!0},g.cloneOptionObject()),f=function(){d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/"+g.getApplicantID()+"/"+g.getFileName(),type:"GET",async:!0,dataType:"text",headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword())},success:function(b){a.fileContent=b,g.done(a)},error:function(a){a.status===404?a.message='Document "'+g.getFileName()+'" not found in localStorage.':a.message='Cannot load "'+g.getFileName()+'" from DAVStorage.',g.fail(a)}})};d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/"+g.getApplicantID()+"/"+g.getFileName(),type:"PROPFIND",async:!0,dataType:"xml",headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword())},success:function(b){d(b).find("lp1\\:getlastmodified, getlastmodified").each(function(){a.lastModified=d(this).text()}),d(b).find("lp1\\:creationdate, creationdate").each(function(){a.creationDate=d(this).text()}),a.fileName=g.getFileName(),c.getContent?f():g.done(a)},error:function(a){a.message='Cannot load "'+g.getFileName()+'" informations from DAVStorage.',g.fail(a)}})},g.getDocumentList=function(){var a=[],c={},e=[];d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/"+g.getApplicantID()+"/",async:!0,type:"PROPFIND",dataType:"xml",headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword()),Depth:"1"},success:function(b){d(b).find("D\\:response, response").each(function(b,f){if(b>0){c={},d(f).find("D\\:href, href").each(function(){e=d(this).text().split("/"),c.fileName=e[e.length-1]?e[e.length-1]:e[e.length-2]+"/"});if(c.fileName===".htaccess"||c.fileName===".htpasswd")return;d(f).find("lp1\\:getlastmodified, getlastmodified").each(function(){c.lastModified=d(this).text()}),d(f).find("lp1\\:creationdate, creationdate").each(function(){c.creationDate=d(this).text()}),a.push(c)}}),g.done(a)},error:function(a){a.message="Cannot get a document list from DAVStorage.",g.fail(a)}})},g.removeDocument=function(){d.ajax({url:g.getStorageLocation()+"/dav/"+g.getStorageUserName()+"/"+g.getApplicantID()+"/"+g.getFileName(),type:"DELETE",async:!0,headers:{Authorization:"Basic "+b.encode(g.getStorageUserName()+":"+g.getStoragePassword())},success:function(){g.done()},error:function(a){a.status===404?g.done():(a.message='Cannot remove "'+g.getFileName()+'" from DAVStorage.',g.fail(a))}})},g},h=function(a,b){var d=c.newBaseStorage(a,b),e={};return e.storageArray=d.getStorageArray(),e.length=e.storageArray.length,e.returnsValuesArray=[],e.maxtries=d.getMaxTries(),d.setMaxTries(1),e.execJobsFromStorageArray=function(a){var b={},c;for(c=0;c<e.storageArray.length;c+=1)b=d.cloneJob(),b.maxtries=e.maxtries,b.storage=e.storageArray[c],b.callback=a,d.addJob(b)},d.checkNameAvailability=function(){var a={},b="id",c=!1,f=[],g={status:"done"},h=function(a){e.returnsValuesArray.push(a);if(!c){if(a.status==="fail")g.status="fail",f.push(a.error);else if(a.return_value===!1){d.done(!1),c=!0;return}if(e.returnsValuesArray.length===e.length){g.status==="fail"?d.fail({status:207,statusText:"Multi-Status",message:'Some check availability of "'+d.getUserName()+'" requests have failed.',array:f}):d.done(!0),c=!0;return}}};e.execJobsFromStorageArray(h)},d.saveDocument=function(){var a={},b={status:"done"},c="id",f=!1,g=[],h=function(a){e.returnsValuesArray.push(a),f||(a.status!=="fail"?(d.done(),f=!0):(g.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All save "'+d.getFileName()+'" requests have failed.',array:g})))};e.execJobsFromStorageArray(h)},d.loadDocument=function(){var a={},b=!1,c={},f="id",g=!1,h=[],i={status:"done"},j=function(a){e.returnsValuesArray.push(a),g||(a.status!=="fail"?(d.done(a.return_value),g=!0):(h.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All load "'+d.getFileName()+'" requests have failed.',array:h})))};e.execJobsFromStorageArray(j)},d.getDocumentList=function(){var a={},b={status:"done"},c="id",f=!1,g=[],h=function(a){e.returnsValuesArray.push(a),f||(a.status!=="fail"?(d.done(a.return_value),f=!0):(g.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:"All get document list requests have failed",array:g})))};e.execJobsFromStorageArray(h)},d.removeDocument=function(){var a={},b={status:"done"},c="key",f=!1,g=[],h=function(a){e.returnsValuesArray.push(a),f||(a.status!=="fail"?(d.done(),f=!0):(g.push(a.error),e.returnsValuesArray.length===e.length&&d.fail({status:207,statusText:"Multi-Status",message:'All remove "'+d.getFileName()+'" requests have failed.',array:g})))};e.execJobsFromStorageArray(h)},d},c.addStorageType("local",function(a){return f(a)}),c.addStorageType("dav",function(a){return g(a)}),c.addStorageType("replicate",function(a){return h(a)})};window.requirejs?define("JIOStorages",["LocalOrCookieStorage","Base64","JIO","jQuery"],a):a(LocalOrCookieStorage,Base64,JIO,jQuery)})();
\ No newline at end of file
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage =
......
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";"),c;for(c=0;c<b.length;c+=1){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b,c=document.cookie.split(":");for(b=0;b<c.length;b+=1){var d=c[b].substr(0,c[b].indexOf("=")),e=c[b].substr(c[b].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}();
\ No newline at end of file
......@@ -9,8 +9,8 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok
var DummyStorageAllOk = function ( args ) {
var that = Jio.newBaseStorage( args );
var newDummyStorageAllOk = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () {
// The [job.userName] IS available.
......@@ -81,8 +81,8 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail
DummyStorageAllFail = function ( args ) {
var that = Jio.newBaseStorage( args );
newDummyStorageAllFail = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () {
// Fails to check [job.userName].
......@@ -147,8 +147,8 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found
DummyStorageAllNotFound = function ( args ) {
var that = Jio.newBaseStorage( args );
newDummyStorageAllNotFound = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () {
// [job.userName] not found, so the name is available.
......@@ -211,8 +211,8 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries
DummyStorageAll3Tries = function ( args ) {
var that = Jio.newBaseStorage( args ), priv = {};
newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.doJob = function (ifokreturn) {
// wait a little in order to simulate asynchronous operation
......@@ -270,16 +270,16 @@
// add key to storageObjectType of global jio
Jio.addStorageType('dummyallok', function (options) {
return new DummyStorageAllOk(options);
return newDummyStorageAllOk(options);
});
Jio.addStorageType('dummyallfail', function (options) {
return new DummyStorageAllFail(options);
return newDummyStorageAllFail(options);
});
Jio.addStorageType('dummyallnotfound', function (options) {
return new DummyStorageAllNotFound(options);
return newDummyStorageAllNotFound(options);
});
Jio.addStorageType('dummyall3tries', function (options) {
return new DummyStorageAll3Tries(options);
return newDummyStorageAll3Tries(options);
});
};
......
var JIO =
(function () { var jio_loader_function = function ( LocalOrCookieStorage, $ ) {
(function () { var jio_loader_function = function ( localOrCookieStorage, $ ) {
////////////////////////////////////////////////////////////////////////////
// constants
var jioConstObj = {
'jobMethodObject': {
'checkNameAvailability': {
'start_event':'start_checkingNameAvailability',
'stop_event':'stop_checkingNameAvailability',
'retvalue':'isAvailable' }, // returns 'boolean'
'saveDocument': {
'start_event':'start_saving',
'stop_event':'stop_saving',
'retvalue':'isSaved' }, // returns 'boolean'
'loadDocument': {
'start_event':'start_loading',
'stop_event':'stop_loading',
'retvalue':'fileContent' }, // returns the file content 'string'
'getDocumentList': {
'start_event':'start_gettingList',
'stop_event':'stop_gettingList',
'retvalue':'list' }, // returns the document list 'array'
'removeDocument': {
'start_event':'start_removing',
'stop_event':'stop_removing',
'retvalue':'isRemoved' } // returns 'boolean'
var jio_const_obj = {
job_method_object: {
checkNameAvailability:{},
saveDocument:{},
loadDocument:{},
getDocumentList:{},
removeDocument:{}
}
},
// end constants
////////////////////////////////////////////////////////////////////////////
// jio globals
jioGlobalObj = {
'jobManagingMethod':{
jio_global_obj = {
job_managing_method:{
/*
LEGEND:
- s: storage
......@@ -102,7 +87,7 @@ var JIO =
For more information, see documentation
*/
'canSelect':function (job1,job2) {
canSelect:function (job1,job2) {
if (JSON.stringify (job1.storage) ===
JSON.stringify (job2.storage) &&
JSON.stringify (job1.applicant) ===
......@@ -112,14 +97,14 @@ var JIO =
}
return false;
},
'canRemoveFailOrDone':function (job1,job2) {
canRemoveFailOrDone:function (job1,job2) {
if (job1.status === 'fail' ||
job1.status === 'done') {
return true;
}
return false;
},
'canEliminate':function (job1,job2) {
canEliminate:function (job1,job2) {
if (job1.status !== 'ongoing' &&
(job1.method === 'removeDocument' &&
job2.method === 'saveDocument' ||
......@@ -129,7 +114,7 @@ var JIO =
}
return false;
},
'canReplace':function (job1,job2) {
canReplace:function (job1,job2) {
if (job1.status !== 'ongoing' &&
job1.method === job2.method &&
job1.date < job2.date) {
......@@ -137,7 +122,7 @@ var JIO =
}
return false;
},
'cannotAccept':function (job1,job2) {
cannotAccept:function (job1,job2) {
if (job1.status !== 'ongoing' ) {
if (job1.method === 'removeDocument' &&
job2.method === 'loadDocument') {
......@@ -162,7 +147,7 @@ var JIO =
}
return false;
},
'mustWait':function (job1,job2) {
mustWait:function (job1,job2) {
if (job1.method === 'getDocumentList' ||
job1.method === 'checkNameAvailability' ||
job2.method === 'getDocumentList' ||
......@@ -172,30 +157,35 @@ var JIO =
return true;
}
},
'localStorage': null, // where the browser stores data
'queueID': 1,
'storageTypeObject': {}, // ex: {'type':'local','creator': fun ...}
'max_wait_time': 10000
queue_id: 1,
storage_type_object: {}, // ex: {'type':'local','creator': fun ...}
max_wait_time: 10000
},
// end jio globals
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Tools
extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Classes
PubSub,Job,JobQueue,JobListener,ActivityUpdater,BaseStorage,
JioConstructor,JioCreator;
newPubSub,newJob,newJobQueue,newJobListener,newActivityUpdater,
newBaseStorage,newJioConstructor,newJioCreator;
// end Classes
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Publisher Subcriber
PubSub = function () {
newPubSub = function (spec, my) {
var that = {}, priv = {},
topics = {}, callbacks, topic;
priv.eventAction = function (id) {
......@@ -233,45 +223,47 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// Job & JobQueue
Job = function ( options ) {
newJob = function ( spec, my ) {
// Job constructor
var job = $.extend({},options);
var job = extend({},spec);
job['id']=0;
job['status']='initial';
job['date']=Date.now();
return job;
};
JobQueue = function ( publisher, options ) {
newJobQueue = function ( spec, my ) {
// JobQueue is a queue of jobs. It will regulary copy this queue
// into localStorage to resume undone tasks.
// publisher: the publisher to use to send event
// options.useLocalStorage: if true, save jobs into localStorage,
// spec.publisher: the publisher to use to send event
// spec.options.useLocalStorage: if true, save jobs into localStorage,
// else only save on memory.
var that = {}, priv = {},
jioIdArrayName = 'jio/idArray';
var that = {}, priv = {}, jio_id_array_name = 'jio/idarray';
that.init = function ( options ) {
// initialize the JobQueue
// options.publisher : is the publisher to use to send events
// options.jioID : the jio ID
var k, emptyfun = function (){},
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
if (options.publisher) {
priv.publisher = publisher;
}
priv.jioID = options.jioID;
priv.jobObjectName = 'jio/jobObject/'+options.jioID;
priv.jobObject = {};
jioIdArray.push (priv.jioID);
jioGlobalObj.localStorage.setItem (jioIdArrayName,jioIdArray);
// options.jio_id : the jio ID
var k, emptyfun = function (){}, jio_id_array;
if (priv.use_local_storage) {
jio_id_array = localOrCookieStorage.
getItem (jio_id_array_name)||[];
if (spec.publisher) {
priv.publisher = spec.publisher;
}
priv.jio_id = options.jio_id;
priv.job_object_name = 'jio/jobobject/' + priv.jio_id;
jio_id_array.push (priv.jio_id);
localOrCookieStorage.setItem (jio_id_array_name,jio_id_array);
}
priv.job_object = {};
that.copyJobQueueToLocalStorage();
for (k in priv.recoveredJobObject) {
priv.recoveredJobObject[k].callback = emptyfun;
that.addJob (priv.recoveredJobObject[k]);
for (k in priv.recovered_job_object) {
priv.recovered_job_object[k].callback = emptyfun;
that.addJob (priv.recovered_job_object[k]);
}
};
that.close = function () {
......@@ -279,50 +271,55 @@ var JIO =
// it also deletes from local storage only if the job list is
// empty.
if (JSON.stringify(priv.jobObject) === '{}') {
jioGlobalObj.localStorage.deleteItem(priv.jobObjectName);
if (JSON.stringify(priv.job_object) === '{}') {
localOrCookieStorage.deleteItem(priv.job_object_name);
}
};
that.getNewQueueID = function () {
// Returns a new queueID
var k = null, id = 0,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioIdArray[k] >= jioGlobalObj.queueID) {
jioGlobalObj.queueID = jioIdArray[k] + 1;
jio_id_array = localOrCookieStorage.getItem (jio_id_array_name)||[];
for (k = 0; k < jio_id_array.length; k += 1) {
if (jio_id_array[k] >= jio_global_obj.queue_id) {
jio_global_obj.queue_id = jio_id_array[k] + 1;
}
}
id = jioGlobalObj.queueID;
jioGlobalObj.queueID ++;
id = jio_global_obj.queue_id;
jio_global_obj.queue_id ++;
return id;
};
that.recoverOlderJobObject = function () {
// recover job object from older inactive jio
var k = null, newJioIdArray = [], jioIdArrayChanged = false,
jioIdArray = jioGlobalObj.localStorage.getItem (jioIdArrayName)||[];
for (k = 0; k < jioIdArray.length; k += 1) {
if (jioGlobalObj.localStorage.getItem (
'jio/id/'+jioIdArray[k]) < Date.now () - 10000) {
// remove id from jioIdArray
var k = null, new_jio_id_array = [], jio_id_array_changed = false,
jio_id_array;
if (priv.use_local_storage) {
jio_id_array = localOrCookieStorage.
getItem (jio_id_array_name)||[];
for (k = 0; k < jio_id_array.length; k += 1) {
if (localOrCookieStorage.getItem (
'jio/id/'+jio_id_array[k]) < Date.now () - 10000) {
// remove id from jio_id_array
// 10000 sec ? delete item
jioGlobalObj.localStorage.deleteItem('jio/id/'+
jioIdArray[k]);
localOrCookieStorage.deleteItem('jio/id/'+
jio_id_array[k]);
// job recovery
priv.recoveredJobObject = jioGlobalObj.
localStorage.getItem('jio/jioObject/'+ jioIdArray[k]);
priv.recovered_job_object = localOrCookieStorage.
getItem('jio/jobobject/'+ jio_id_array[k]);
// remove ex job object
jioGlobalObj.localStorage.deleteItem(
'jio/jobObject/'+ jioIdArray[k]);
jioIdArrayChanged = true;
localOrCookieStorage.deleteItem(
'jio/jobobject/'+ jio_id_array[k]);
jio_id_array_changed = true;
} else {
newJioIdArray.push (jioIdArray[k]);
new_jio_id_array.push (jio_id_array[k]);
}
}
if (jio_id_array_changed) {
localOrCookieStorage.setItem(jio_id_array_name,
new_jio_id_array);
}
if (jioIdArrayChanged) {
jioGlobalObj.localStorage.setItem(jioIdArrayName,newJioIdArray);
}
};
that.isThereJobsWhere = function( func ) {
......@@ -331,8 +328,8 @@ var JIO =
var id = 'id';
if (!func) { return true; }
for (id in priv.jobObject) {
if (func(priv.jobObject[id])) {
for (id in priv.job_object) {
if (func(priv.job_object[id])) {
return true;
}
}
......@@ -341,15 +338,15 @@ var JIO =
that.copyJobQueueToLocalStorage = function () {
// Copy job queue into localStorage.
if (priv.useLocalStorage) {
return jioGlobalObj.localStorage.setItem(
priv.jobObjectName,priv.jobObject);
if (priv.use_local_storage) {
return localOrCookieStorage.setItem(
priv.job_object_name,priv.job_object);
} else {
return false;
}
};
that.createJob = function ( options ) {
return that.addJob ( new Job ( options ) );
return that.addJob ( newJob ( options ) );
};
that.addJob = function ( job ) {
// Add a job to the queue, browsing all jobs
......@@ -359,39 +356,39 @@ var JIO =
// It also clean fail or done jobs.
// job = the job object
var res = {'newone':true,'elimArray':[],'waitArray':[],
'removeArray':[]}, basestorage = null, id = 'id';
var newone = true, elim_array = [], wait_array = [],
remove_array = [], basestorage = null, id = 'id';
//// browsing current jobs
for (id in priv.jobObject) {
if (jioGlobalObj.jobManagingMethod.canRemoveFailOrDone(
priv.jobObject[id],job)) {
res.removeArray.push(id);
for (id in priv.job_object) {
if (jio_global_obj.job_managing_method.canRemoveFailOrDone(
priv.job_object[id],job)) {
remove_array.push(id);
continue;
}
if (jioGlobalObj.jobManagingMethod.canSelect(
priv.jobObject[id],job)) {
if (jioGlobalObj.jobManagingMethod.canEliminate(
priv.jobObject[id],job)) {
res.elimArray.push(id);
if (jio_global_obj.job_managing_method.canSelect(
priv.job_object[id],job)) {
if (jio_global_obj.job_managing_method.canEliminate(
priv.job_object[id],job)) {
elim_array.push(id);
continue;
}
if (jioGlobalObj.jobManagingMethod.canReplace(
priv.jobObject[id],job)) {
basestorage = new BaseStorage(
{'queue':that,'job':priv.jobObject[id]});
if (jio_global_obj.job_managing_method.canReplace(
priv.job_object[id],job)) {
basestorage = newBaseStorage(
{'queue':that,'job':priv.job_object[id]});
basestorage.replace(job);
res.newone = false;
newone = false;
break;
}
if (jioGlobalObj.jobManagingMethod.cannotAccept(
priv.jobObject[id],job)) {
if (jio_global_obj.job_managing_method.cannotAccept(
priv.job_object[id],job)) {
// Job not accepted
return false;
}
if (jioGlobalObj.jobManagingMethod.mustWait(
priv.jobObject[id],job)) {
res.waitArray.push(id);
if (jio_global_obj.job_managing_method.mustWait(
priv.job_object[id],job)) {
wait_array.push(id);
continue;
}
// one of the previous tests must be ok.
......@@ -400,32 +397,33 @@ var JIO =
}
//// end browsing current jobs
if (res.newone) {
if (newone) {
// if it is a new job, we can eliminate deprecated jobs and
// set this job dependencies.
for (id = 0; id < res.elimArray.length; id += 1) {
basestorage = new BaseStorage(
{'queue':that,'job':priv.jobObject[res.elimArray[id]]});
for (id = 0; id < elim_array.length; id += 1) {
basestorage = newBaseStorage(
{'queue':that,
'job':priv.job_object[elim_array[id]]});
basestorage.eliminate();
}
if (res.waitArray.length > 0) {
if (wait_array.length > 0) {
job.status = 'wait';
job.waitingFor = {'jobIdArray':res.waitArray};
for (id = 0; id < res.waitArray.length; id += 1) {
if (priv.jobObject[res.waitArray[id]]) {
priv.jobObject[res.waitArray[id]].maxtries = 1;
job.waitingFor = {'jobIdArray':wait_array};
for (id = 0; id < wait_array.length; id += 1) {
if (priv.job_object[wait_array[id]]) {
priv.job_object[wait_array[id]].maxtries = 1;
}
}
}
for (id = 0; id < res.removeArray.length; id += 1) {
that.removeJob(priv.jobObject[res.removeArray[id]]);
for (id = 0; id < remove_array.length; id += 1) {
that.removeJob(priv.job_object[remove_array[id]]);
}
// set job id
job.id = priv.jobid;
job.id = priv.job_id;
job.tries = 0;
priv.jobid ++;
priv.job_id ++;
// save the new job into the queue
priv.jobObject[job.id] = job;
priv.job_object[job.id] = job;
}
// save into localStorage
that.copyJobQueueToLocalStorage();
......@@ -440,26 +438,26 @@ var JIO =
// options.job = the job object containing at least {id:..}.
// options.where = remove values where options.where(job) === true
var settings = $.extend ({'where':function (job) {return true;}},
var settings = extend ({where:function (job) {return true;}},
options),andwhere,found=false,k='key';
//// modify the job list
if (settings.job) {
if (priv.jobObject[settings.job.id] && settings.where(
priv.jobObject[settings.job.id]) ) {
delete priv.jobObject[settings.job.id];
if (priv.job_object[settings.job.id] && settings.where(
priv.job_object[settings.job.id]) ) {
delete priv.job_object[settings.job.id];
found = true;
}
}else {
for (k in priv.jobObject) {
if (settings.where(priv.jobObject[k])) {
delete priv.jobObject[k];
for (k in priv.job_object) {
if (settings.where(priv.job_object[k])) {
delete priv.job_object[k];
found = true;
}
}
}
if (!found) {
$.error ('No jobs was found, when trying to remove some.');
console.error('No jobs was found, when trying to remove some.');
}
//// end modifying
that.copyJobQueueToLocalStorage();
......@@ -470,8 +468,8 @@ var JIO =
// TODO manage jobs ! All jobs are not 'initial'.
var id = 'id';
for (id in priv.jobObject) {
priv.jobObject[id].status = 'initial';
for (id in priv.job_object) {
priv.job_object[id].status = 'initial';
}
that.copyJobQueueToLocalStorage();
};
......@@ -481,22 +479,23 @@ var JIO =
var i = 'id', j, ok;
//// do All jobs
for (i in priv.jobObject) {
for (i in priv.job_object) {
ok = false;
if (priv.jobObject[i].status === 'initial') {
if (priv.job_object[i].status === 'initial') {
// if status initial
// invoke new job
that.invoke(priv.jobObject[i]);
} else if (priv.jobObject[i].status === 'wait') {
that.invoke(priv.job_object[i]);
} else if (priv.job_object[i].status === 'wait') {
ok = true;
// if status wait
if (priv.jobObject[i].waitingFor.jobIdArray) {
if (priv.job_object[i].waitingFor.jobIdArray) {
// wait job
// browsing job id array
for (j = 0;
j < priv.jobObject[i].waitingFor.jobIdArray.length;
j < priv.job_object[i].
waitingFor.jobIdArray.length;
j += 1) {
if (priv.jobObject[priv.jobObject[i].
if (priv.job_object[priv.job_object[i].
waitingFor.jobIdArray[j]]) {
// if a job is still exist, don't invoke
ok = false;
......@@ -504,9 +503,9 @@ var JIO =
}
}
}
if (priv.jobObject[i].waitingFor.time) {
if (priv.job_object[i].waitingFor.time) {
// wait time
if (priv.jobObject[i].waitingFor.time > Date.now()) {
if (priv.job_object[i].waitingFor.time > Date.now()) {
// it is not time to restore the job!
ok = false;
}
......@@ -514,7 +513,7 @@ var JIO =
// else wait nothing
if (ok) {
// invoke waiting job
that.invoke(priv.jobObject[i]);
that.invoke(priv.job_object[i]);
}
}
}
......@@ -529,7 +528,7 @@ var JIO =
//// analysing job method
// if the method does not exist, do nothing
if (!jioConstObj.jobMethodObject[job.method]) {
if (!jio_const_obj.job_method_object[job.method]) {
return false; // suppose never happen
}
// test if a similar job is on going, in order to publish a start
......@@ -539,28 +538,28 @@ var JIO =
testjob.method === 'initial');
})) {
job.status = 'ongoing';
priv.publisher.publish(jioConstObj.jobMethodObject[
job.method].start_event);
priv.publisher.publish(jio_const_obj.job_method_object[
job.method]['start_'+job.method]);
} else {
job.status = 'ongoing';
}
// Create a storage object and use it to save,load,...!
basestorage = new BaseStorage({'queue':this,'job':job});
basestorage = newBaseStorage({'queue':this,'job':job});
basestorage.execute();
//// end method analyse
};
that.ended = function (endedjob) {
// It is a callback function called just before user callback.
// It is called to manage jobObject according to the ended job.
// It is called to manage job_object according to the ended job.
var job = $.extend({},endedjob); // copy
var job = extend({},endedjob); // copy
// This job is supposed terminated, we can remove it from queue.
that.removeJob ({'job':job});
//// ended job analyse
// if the job method does not exists, return false
if (!jioConstObj.jobMethodObject[job.method]) {
if (!jio_const_obj.job_method_object[job.method]) {
return false;
}
// if there isn't some job to do, then send stop event
......@@ -571,8 +570,8 @@ var JIO =
testjob.status === 'initial');
})) {
priv.publisher.publish(
jioConstObj.jobMethodObject[
job.method].stop_event);
jio_const_obj.job_method_object[
job.method]['stop_'+job.method]);
return;
}
//// end returnedJobAnalyse
......@@ -590,13 +589,13 @@ var JIO =
//// end Methods
//// Initialize
priv.useLocalStorage = options.useLocalStorage;
priv.publisher = publisher;
priv.jobid = 1;
priv.jioID = 0;
priv.jobObjectName = '';
priv.jobObject = {};
priv.recoveredJobObject = {};
priv.use_local_storage = spec.options.use_local_storage;
priv.publisher = spec.publisher;
priv.job_id = 1;
priv.jio_id = 0;
priv.job_object_name = '';
priv.job_object = {};
priv.recovered_job_object = {};
//// end Initialize
return that;
......@@ -606,13 +605,13 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// jio job listener
JobListener = function ( queue ) {
newJobListener = function ( spec, my ) {
// A little daemon which will start jobs from the joblist
var that = {}, priv = {};
priv.interval = 200;
priv.id = null;
priv.queue = queue;
priv.queue = spec.queue;
that.setIntervalDelay = function (interval) {
// Set the time between two joblist check in millisec
......@@ -649,7 +648,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// ActivityUpdater
ActivityUpdater = function () {
newActivityUpdater = function () {
// The activity updater is a little thread that proves activity of this
// jio instance.
......@@ -684,8 +683,7 @@ var JIO =
return false;
};
that.touch = function (id) {
jioGlobalObj.localStorage.setItem ('jio/id/' + id,
Date.now() );
localOrCookieStorage.setItem ('jio/id/' + id,Date.now() );
};
//// end methods
return that;
......@@ -695,7 +693,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// BaseStorage
BaseStorage = function ( options ) {
newBaseStorage = function ( options ) {
// The base storage, will call the good method from the good storage,
// and will check and return the associated value.
......@@ -761,8 +759,8 @@ var JIO =
// The listener will invoke this job later.
var time = (priv.job.tries*priv.job.tries*1000);
if (time > jioGlobalObj.max_wait_time) {
time = jioGlobalObj.max_wait_time;
if (time > jio_global_obj.max_wait_time) {
time = jio_global_obj.max_wait_time;
}
priv.job.status = 'wait';
priv.job.waitingFor = {'time':Date.now() + time};
......@@ -771,7 +769,7 @@ var JIO =
//// Getters Setters
that.cloneJob = function () {
return $.extend({},priv.job);
return extend({},priv.job);
};
that.getUserName = function () {
return priv.job.userName || '';
......@@ -798,7 +796,7 @@ var JIO =
return priv.job.fileContent || '';
};
that.cloneOptionObject = function () {
return $.extend({},priv.job.options);
return extend({},priv.job.options);
};
that.getMaxTries = function () {
return priv.job.maxtries;
......@@ -878,27 +876,37 @@ var JIO =
priv.job.tries = that.getTries() + 1;
if ( !jioGlobalObj.storageTypeObject[ priv.job.storage.type ] ) {
if ( !jio_global_obj.storage_type_object[priv.job.storage.type] ) {
return null;
}
return jioGlobalObj.storageTypeObject[ priv.job.storage.type ]({
return jio_global_obj.storage_type_object[ priv.job.storage.type ]({
'job':priv.job,'queue':priv.queue})[priv.job.method]();
};
// These methods must be redefined!
that.checkNameAvailability = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.loadDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.saveDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.getDocumentList = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
that.removeDocument = function () {
that.fail('This method must be redefined!',0);
that.fail({status:0,
statusText:'Undefined Method',
message:'This method must be redefined!'});
};
//// end Public Methods
return that;
......@@ -908,7 +916,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// JIO Constructor
JioConstructor = function ( storage , applicant, options ) {
newJioConstructor = function ( spec, my ) {
// JIO Constructor, create a new JIO object.
// It just initializes values.
// storage : the storage that contains {type:..,[storageinfos]}
......@@ -930,7 +938,7 @@ var JIO =
// set a new jio id
priv.id = priv.queue.getNewQueueID();
// initializing objects
priv.queue.init({'jioID':priv.id});
priv.queue.init({'jio_id':priv.id});
// start activity updater
if (priv.updater){
priv.updater.start(priv.id);
......@@ -1016,7 +1024,7 @@ var JIO =
// } else { } // Error
// }});
var settings = $.extend ({
var settings = extend ({
'userName': priv.storage.userName,
'storage': priv.storage,
'applicant': priv.applicant,
......@@ -1049,7 +1057,7 @@ var JIO =
// } else { } // Error
// }});
var settings = $.extend({
var settings = extend({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'saveDocument',
......@@ -1086,7 +1094,7 @@ var JIO =
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'loadDocument',
......@@ -1120,7 +1128,7 @@ var JIO =
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'getDocumentList',
......@@ -1150,7 +1158,7 @@ var JIO =
// } else { } // Not Removed
// }});
var settings = $.extend ({
var settings = extend ({
'storage': priv.storage,
'applicant': priv.applicant,
'method':'removeDocument',
......@@ -1165,33 +1173,36 @@ var JIO =
//// end Methods
//// Initialize
var settings = $.extend({'useLocalStorage':true},options);
var settings = extend({'use_local_storage':true},spec.options);
// objectify storage and applicant
if(typeof storage === 'string') {
storage = JSON.parse(options.storage);
if(typeof spec.storage === 'string') {
spec.storage = JSON.parse(spec.storage);
}
if(typeof applicant === 'string') {
applicant = JSON.parse(options.applicant);
if(typeof spec.applicant === 'string') {
spec.applicant = JSON.parse(spec.applicant);
}
// set init values
priv['storage'] = storage;
priv['applicant'] = applicant;
priv['storage'] = spec.storage;
priv['applicant'] = spec.applicant;
priv['id'] = 0;
priv['pubsub'] = new PubSub(settings);
priv['queue'] = new JobQueue(priv.pubsub,settings);
priv['listener'] = new JobListener(priv.queue,settings);
priv['pubsub'] = newPubSub({options:settings});
priv['queue'] = newJobQueue({publisher:priv.pubsub,
options:settings});
priv['listener'] = newJobListener({queue:priv.queue,
options:settings});
priv['ready'] = false;
if (settings.useLocalStorage) {
priv['updater'] = new ActivityUpdater(settings);
if (settings.use_local_storage) {
priv['updater'] = newActivityUpdater({options:settings});
} else {
priv['updater'] = null;
}
// check storage type
if (priv.storage && !jioGlobalObj.storageTypeObject[priv.storage.type]){
$.error('Unknown storage type "' + priv.storage.type +'"');
if (priv.storage &&
!jio_global_obj.storage_type_object[priv.storage.type]){
console.error('Unknown storage type "' + priv.storage.type +'"');
}
// start jio process
......@@ -1205,7 +1216,7 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
// Jio creator
JioCreator = function () {
newJioCreator = function ( spec, my ) {
var that = {};
// Jio creator object
// this object permit to create jio object
......@@ -1215,18 +1226,16 @@ var JIO =
// applicant: the applicant object or json string
// options.useLocalStorage: if true, save job queue on localStorage.
var settings = $.extend({'useLocalStorage':true},options);
if (jioGlobalObj.localStorage===null) {
jioGlobalObj.localStorage = LocalOrCookieStorage;
}
var settings = extend({'use_local_storage':true},options);
return new JioConstructor(storage,applicant,settings);
return newJioConstructor({storage:storage,
applicant:applicant,
options:settings});
};
that.newBaseStorage = function ( options ) {
that.newBaseStorage = function ( spec, my ) {
// Create a Jio Storage which can be used to design new storage.
return new BaseStorage( options );
return newBaseStorage( spec, my );
};
that.addStorageType = function ( type, constructor ) {
// Add a storage type to jio. Jio must have keys/types which are
......@@ -1237,22 +1246,22 @@ var JIO =
// constructor : the function which returns a new storage object.
if (type && constructor) {
jioGlobalObj.storageTypeObject[type] = constructor;
jio_global_obj.storage_type_object[type] = constructor;
return true;
}
return false;
};
that.getGlobalObject = function () {
// Returns the global jio values
return jioGlobalObj;
return jio_global_obj;
};
that.getConstObject = function () {
// Returns a copy of the constants
return $.extend({},jioConstObj);
return extend({},jio_const_obj);
};
return that;
};
return new JioCreator();
return newJioCreator();
// end Jio Creator
////////////////////////////////////////////////////////////////////////////
};
......
......@@ -9,21 +9,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// Tools
var extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Classes
var LocalStorage,DAVStorage,ReplicateStorage;
newLocalStorage,newDAVStorage,newReplicateStorage;
// end Classes
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Local Storage
LocalStorage = function ( args ) {
newLocalStorage = function ( spec, my ) {
// LocalStorage constructor
var that = Jio.newBaseStorage( args ), priv = {};
var that = Jio.newBaseStorage( spec, my ), priv = {};
that.checkNameAvailability = function () {
// checks the availability of the [job.userName].
......@@ -96,7 +103,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
var doc = null, settings = $.extend(
var doc = null, settings = extend(
{'getContent':true},that.cloneOptionObject());
doc = LocalOrCookieStorage.getItem(
......@@ -171,8 +178,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// DAVStorage
DAVStorage = function ( args ) {
var that = Jio.newBaseStorage( args );
newDAVStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my );
that.mkcol = function ( options ) {
// create folders in dav storage, synchronously
......@@ -185,7 +192,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO this method is not working !!!
var settings = $.extend ({
var settings = extend ({
'success':function(){},'error':function(){}},options),
splitpath = ['splitedpath'], tmppath = 'temp/path';
......@@ -318,7 +325,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'creationDate':date,'lastModified':date}
var doc = {},
settings = $.extend({'getContent':true},that.cloneOptionObject()),
settings = extend({'getContent':true},that.cloneOptionObject()),
// TODO check if job's features are good
getContent = function () {
......@@ -494,8 +501,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
////////////////////////////////////////////////////////////////////////////
// ReplicateStorage
ReplicateStorage = function ( args ) {
var that = Jio.newBaseStorage( args ), priv = {};
newReplicateStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storageArray = that.getStorageArray();
// TODO Add a tests that check if there is no duplicate storages.
......@@ -701,13 +708,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// add key to storageObjectType of global jio
Jio.addStorageType('local', function (options) {
return new LocalStorage(options);
return newLocalStorage(options);
});
Jio.addStorageType('dav', function (options) {
return new DAVStorage(options);
return newDAVStorage(options);
});
Jio.addStorageType('replicate', function (options) {
return new ReplicateStorage(options);
return newReplicateStorage(options);
});
};
......
......@@ -5,7 +5,7 @@
$ = loader.jQuery;
//// clear jio localstorage
(function () {
(function () {
var k, storageObject = LocalOrCookieStorage.getAll();
for (k in storageObject) {
var splitk = k.split('/');
......@@ -13,7 +13,7 @@
LocalOrCookieStorage.deleteItem(k);
}
}
}());
}());
//// end clear jio localstorage
//// Tools
......@@ -152,12 +152,12 @@ test ('Simple Job Elimination', function () {
id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1,'maxtries':1});
ok(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'],
ok(LocalOrCookieStorage.getItem('jio/jobobject/'+id)['1'],
'job creation');
clock.tick(10);
o.jio.removeDocument({'fileName':'file','fileContent':'content',
'callback':o.f2,'maxtries':1});
o.tmp = LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'];
o.tmp = LocalOrCookieStorage.getItem('jio/jobobject/'+id)['1'];
ok(!o.tmp || o.tmp.status === 'fail','job elimination');
});
......@@ -180,7 +180,7 @@ test ('Simple Job Replacement', function () {
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f2,'maxtries':1});
deepEqual(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['1'].date,10,
'jio/jobobject/'+id)['1'].date,10,
'The first job date have to be equal to the second job date.');
clock.tick(500);
deepEqual([o.f1.calledOnce,o.status],[true,'fail'],
......@@ -205,16 +205,16 @@ test ('Simple Job Waiting', function () {
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f4,'maxtries':1});
ok(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'] &&
'jio/jobobject/'+id)['2'] &&
LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['1'].status === 'ongoing',
'jio/jobobject/'+id)['1'].status === 'ongoing',
'The second job must not overwrite the first ongoing one.');
ok(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].status === 'wait' &&
'jio/jobobject/'+id)['2'].status === 'wait' &&
LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].waitingFor &&
'jio/jobobject/'+id)['2'].waitingFor &&
JSON.stringify (LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].waitingFor.jobIdArray) === '["1"]',
'jio/jobobject/'+id)['2'].waitingFor.jobIdArray) === '["1"]',
'The second job must be waiting for the first to end');
clock.tick(500);
ok(o.f3.calledOnce,'first request passed');
......
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