Commit 89c6789c authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Change return value var name from jobs + grunt tests.

parent fe1379fb
......@@ -225,9 +225,9 @@ require(['OfficeJS'],function (OJS) {
priv.jio.loadDocument({
'fileName':filename,
'callback':function (result){
if (result.document.fileName) {
if (result.return_value.fileName) {
getCurrentEditor().setHTML(
result.document.fileContent);
result.return_value.fileContent);
} else {
console.error ('Error: ' + result.message);
}
......@@ -264,17 +264,17 @@ require(['OfficeJS'],function (OJS) {
'maxtries':3,
'callback':function (result) {
var htmlString = '', i, document_array = [];
for (i = 0; i < result.list.length; i += 1) {
for (i = 0; i < result.return_value.length; i += 1) {
htmlString += '<li><a href="#/texteditor:fileName='+
result.list[i].fileName + '">\n' +
result.list[i].fileName;
result.list[i].creationDate =
(new Date(result.list[i].creationDate)).
result.return_value[i].fileName + '">\n' +
result.return_value[i].fileName;
result.return_value[i].creationDate =
(new Date(result.return_value[i].creationDate)).
toLocaleString();
result.list[i].lastModified =
(new Date(result.list[i].lastModified)).
result.return_value[i].lastModified =
(new Date(result.return_value[i].lastModified)).
toLocaleString();
document_array.push (result.list[i]);
document_array.push (result.return_value[i]);
htmlString += '</a></li>\n';
}
if (htmlString === '') {
......
/*! JIO - v0.1.0 - 2012-05-22
/*! JIO - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -713,52 +713,50 @@ var JIO =
//// Private Methods
priv.fail_checkNameAvailability = function () {
priv.res.isAvailable = false;
priv.res.message = 'Unable to check name availability.';
};
priv.done_checkNameAvailability = function ( isavailable ) {
priv.res.message = priv.job.userName + ' is ' +
(isavailable?'':'not ') + 'available.';
priv.res.isAvailable = isavailable;
priv.res.return_value = isavailable;
};
priv.fail_loadDocument = function () {
priv.res.document = {};
priv.res.message = 'Unable to load document.';
};
priv.done_loadDocument = function ( returneddocument ) {
priv.res.message = 'Document loaded.';
priv.res.document = returneddocument;
priv.res.return_value = returneddocument;
// transform date into ms
priv.res.document.lastModified =
new Date(priv.res.document.lastModified).getTime();
priv.res.document.creationDate =
new Date(priv.res.document.creationDate).getTime();
priv.res.return_value.lastModified =
new Date(priv.res.return_value.lastModified).getTime();
priv.res.return_value.creationDate =
new Date(priv.res.return_value.creationDate).getTime();
};
priv.fail_saveDocument = function () {
priv.res.isSaved = false;
priv.res.message = 'Unable to save document.';
};
priv.done_saveDocument = function () {
priv.res.message = 'Document saved.';
priv.res.isSaved = true;
};
priv.fail_getDocumentList = function () {
priv.res.list = [];
priv.res.message = 'Unable to retrieve document list.';
};
priv.done_getDocumentList = function ( documentlist ) {
var i;
priv.res.message = 'Document list received.';
priv.res.list = documentlist;
for (i = 0; i < priv.res.list.length; i += 1) {
priv.res.list[i].lastModified =
new Date(priv.res.list[i].lastModified).getTime();
priv.res.list[i].creationDate =
new Date(priv.res.list[i].creationDate).getTime();
priv.res.return_value = documentlist;
for (i = 0; i < priv.res.return_value.length; i += 1) {
priv.res.return_value[i].lastModified =
new Date(priv.res.return_value[i].lastModified).getTime();
priv.res.return_value[i].creationDate =
new Date(priv.res.return_value[i].creationDate).getTime();
}
};
priv.fail_removeDocument = function () {
priv.res.isRemoved = false;
priv.res.message = 'Unable to removed document.';
};
priv.done_removeDocument = function () {
priv.res.message = 'Document removed.';
priv.res.isRemoved = true;
};
priv.retryLater = function () {
......@@ -1005,8 +1003,12 @@ var JIO =
// example :
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) { alert('is available? ' +
// result.isAvailable); }});
// function (result) {
// if (result.status === 'done') {
// if (result.return_value === true) { // available
// } else { } // not available
// } else { } // Error
// }});
var settings = $.extend ({
'userName': priv.storage.userName,
......@@ -1036,8 +1038,10 @@ var JIO =
// - true if the job was added or replaced
// jio.saveDocument({'fileName':'file','fileContent':'content',
// 'callback': function (result) { alert('saved?' +
// result.isSaved); }});
// 'callback': function (result) {
// if (result.status === 'done') { // Saved
// } else { } // Error
// }});
var settings = $.extend({
'storage': priv.storage,
......@@ -1067,9 +1071,14 @@ var JIO =
// - true if the job was added or replaced
// jio.loadDocument({'fileName':'file','callback':
// function (result) { alert('content: '+
// result.doc.fileContent + ' creation date: ' +
// result.doc.creationDate); }});
// function (result) {
// if (result.status === 'done') { // Loaded
// } else { } // Error
// }});
// result.return_value is a document object that looks like {
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
'storage': priv.storage,
......@@ -1097,7 +1106,13 @@ var JIO =
// - true if the job was added or replaced
// jio.getDocumentList({'callback':
// function (result) { alert('list: '+result.list); }});
// function (result) {
// if (result.status === 'done') { // OK
// console.log(result.return_value);
// } else { } // Error
// }});
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
'storage': priv.storage,
......@@ -1124,7 +1139,10 @@ var JIO =
// - true if the job was added or replaced
// jio.removeDocument({'fileName':'file','callback':
// function (result) { alert('removed? '+result.isRemoved); }});
// function (result) {
// if(result.status === 'done') { // Removed
// } else { } // Not Removed
// }});
var settings = $.extend ({
'storage': priv.storage,
......
/*! JIO - v0.1.0 - 2012-05-22
/*! JIO - v0.1.0 - 2012-05-23
* 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.isAvailable=!1},e.done_checkNameAvailability=function(a){e.res.message=e.job.userName+" is "+(a?"":"not ")+"available.",e.res.isAvailable=a},e.fail_loadDocument=function(){e.res.document={}},e.done_loadDocument=function(a){e.res.message="Document loaded.",e.res.document=a,e.res.document.lastModified=(new Date(e.res.document.lastModified)).getTime(),e.res.document.creationDate=(new Date(e.res.document.creationDate)).getTime()},e.fail_saveDocument=function(){e.res.isSaved=!1},e.done_saveDocument=function(){e.res.message="Document saved.",e.res.isSaved=!0},e.fail_getDocumentList=function(){e.res.list=[]},e.done_getDocumentList=function(a){var b;e.res.message="Document list received.",e.res.list=a;for(b=0;b<e.res.list.length;b+=1)e.res.list[b].lastModified=(new Date(e.res.list[b].lastModified)).getTime(),e.res.list[b].creationDate=(new Date(e.res.list[b].creationDate)).getTime()},e.fail_removeDocument=function(){e.res.isRemoved=!1},e.done_removeDocument=function(){e.res.message="Document removed.",e.res.isRemoved=!0},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.errno=0,e["fail_"+e.job.method](),e.callback(e.res)},c.fail=function(a,b){e.res.status="fail",e.res.message=a,e.res.errno=b,!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={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.errno=0,e["fail_"+e.job.method](),e.callback(e.res)},c.fail=function(a,b){e.res.status="fail",e.res.message=a,e.res.errno=b,!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
/*! JIO Storage - v0.1.0 - 2012-05-22
/*! JIO Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -521,18 +521,30 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// if the name already exists in a storage, it is not available.
// this.job.userName: the name we want to check.
// this.job.storage.storageArray: An Array of storages.
// TODO
var newjob = {}, isavailable = true, i = 'id',
var newjob = {}, i = 'id', done = false,
res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status === 'fail') {
res.status = 'fail';
} else {
if (result.return_value === false) {
that.done (false);
done = true;
return;
}
}
if (priv.returnsValuesArray.length ===
priv.length) {
if (res.status === 'fail') {
that.fail ('Unable to check name availability.',0);
} else {
that.done (true);
}
done = true;
return;
}
if (!result.isAvailable) { isavailable = false; }
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
that.done(isavailable);
}
};
priv.execJobsFromStorageArray(callback);
......@@ -546,7 +558,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name.
// this.job.fileContent: the document content.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
......@@ -580,7 +591,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
// TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
......@@ -588,7 +598,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.document);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -610,16 +620,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'fileName':string,
// the list is [object,object,...] -> object = {'fileName':string,
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -640,7 +649,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) {
......
/*! JIO Storage - v0.1.0 - 2012-05-22
/*! JIO Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
(function(){var a=function(a,b,c,d){var e=function(){var a=!0,c=function(b){console.error("Fail to load "+b),a=!1};try{b||c("Base64")}catch(d){c("Base64")}return a},f,g,h;f=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("Document not found.",404)},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},g=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):e.fail("Cannot check if "+e.getUserName()+" is available.",a.status)}})},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){e.fail("Cannot save document.",a.status)}})},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){var b;a.status===404?b="Document not found.":b='Cannot load "'+e.getFileName()+'".',e.fail(b,a.status)}})};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){e.fail("Cannot get document informations.",a.status)}})},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){e.fail("Cannot get list.",a.status)}})},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(){e.done()},error:function(a){a.status===404?e.done():e.fail('Cannot remove "'+e.getFileName()+'".',a.status)}})},e},h=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=!0,e="id",f={status:"done"},g=function(a){d.returnsValuesArray.push(a),a.status==="fail"&&(f.status="fail"),a.isAvailable||(c=!1),d.returnsValuesArray.length===d.length&&b.done(c)};d.execJobsFromStorageArray(g)},b.saveDocument=function(){var a={},c={status:"done"},e="id",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to save any file.",0))};d.execJobsFromStorageArray(g)},b.loadDocument=function(){var a={},c=!1,e={},f="id",g=!1,h={status:"done"},i=function(a){d.returnsValuesArray.push(a),g||(a.status!=="fail"?(b.done(a.document),g=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to load any file.",0))};d.execJobsFromStorageArray(i)},b.getDocumentList=function(){var a={},c={status:"done"},e="id",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(a.list),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to retrieve list.",0))};d.execJobsFromStorageArray(g)},b.removeDocument=function(){var a={},c={status:"done"},e="key",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to remove any file.",0))};d.execJobsFromStorageArray(g)},b},c.addStorageType("local",function(a){return new f(a)}),c.addStorageType("dav",function(a){return new g(a)}),c.addStorageType("replicate",function(a){return new h(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(){var a=!0,c=function(b){console.error("Fail to load "+b),a=!1};try{b||c("Base64")}catch(d){c("Base64")}return a},f,g,h;f=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("Document not found.",404)},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},g=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):e.fail("Cannot check if "+e.getUserName()+" is available.",a.status)}})},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){e.fail("Cannot save document.",a.status)}})},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){var b;a.status===404?b="Document not found.":b='Cannot load "'+e.getFileName()+'".',e.fail(b,a.status)}})};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){e.fail("Cannot get document informations.",a.status)}})},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){e.fail("Cannot get list.",a.status)}})},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(){e.done()},error:function(a){a.status===404?e.done():e.fail('Cannot remove "'+e.getFileName()+'".',a.status)}})},e},h=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={status:"done"},g=function(a){d.returnsValuesArray.push(a);if(!e){if(a.status==="fail")f.status="fail";else if(a.return_value===!1){b.done(!1),e=!0;return}if(d.returnsValuesArray.length===d.length){f.status==="fail"?b.fail("Unable to check name availability.",0):b.done(!0),e=!0;return}}};d.execJobsFromStorageArray(g)},b.saveDocument=function(){var a={},c={status:"done"},e="id",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to save any file.",0))};d.execJobsFromStorageArray(g)},b.loadDocument=function(){var a={},c=!1,e={},f="id",g=!1,h={status:"done"},i=function(a){d.returnsValuesArray.push(a),g||(a.status!=="fail"?(b.done(a.return_value),g=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to load any file.",0))};d.execJobsFromStorageArray(i)},b.getDocumentList=function(){var a={},c={status:"done"},e="id",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(a.return_value),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to retrieve list.",0))};d.execJobsFromStorageArray(g)},b.removeDocument=function(){var a={},c={status:"done"},e="key",f=!1,g=function(a){d.returnsValuesArray.push(a),f||(a.status!=="fail"?(b.done(),f=!0):d.returnsValuesArray.length===d.length&&b.fail("Unable to remove any file.",0))};d.execJobsFromStorageArray(g)},b},c.addStorageType("local",function(a){return new f(a)}),c.addStorageType("dav",function(a){return new g(a)}),c.addStorageType("replicate",function(a){return new 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-22
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage =
......
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-22
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
* 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
......@@ -710,52 +710,50 @@ var JIO =
//// Private Methods
priv.fail_checkNameAvailability = function () {
priv.res.isAvailable = false;
priv.res.message = 'Unable to check name availability.';
};
priv.done_checkNameAvailability = function ( isavailable ) {
priv.res.message = priv.job.userName + ' is ' +
(isavailable?'':'not ') + 'available.';
priv.res.isAvailable = isavailable;
priv.res.return_value = isavailable;
};
priv.fail_loadDocument = function () {
priv.res.document = {};
priv.res.message = 'Unable to load document.';
};
priv.done_loadDocument = function ( returneddocument ) {
priv.res.message = 'Document loaded.';
priv.res.document = returneddocument;
priv.res.return_value = returneddocument;
// transform date into ms
priv.res.document.lastModified =
new Date(priv.res.document.lastModified).getTime();
priv.res.document.creationDate =
new Date(priv.res.document.creationDate).getTime();
priv.res.return_value.lastModified =
new Date(priv.res.return_value.lastModified).getTime();
priv.res.return_value.creationDate =
new Date(priv.res.return_value.creationDate).getTime();
};
priv.fail_saveDocument = function () {
priv.res.isSaved = false;
priv.res.message = 'Unable to save document.';
};
priv.done_saveDocument = function () {
priv.res.message = 'Document saved.';
priv.res.isSaved = true;
};
priv.fail_getDocumentList = function () {
priv.res.list = [];
priv.res.message = 'Unable to retrieve document list.';
};
priv.done_getDocumentList = function ( documentlist ) {
var i;
priv.res.message = 'Document list received.';
priv.res.list = documentlist;
for (i = 0; i < priv.res.list.length; i += 1) {
priv.res.list[i].lastModified =
new Date(priv.res.list[i].lastModified).getTime();
priv.res.list[i].creationDate =
new Date(priv.res.list[i].creationDate).getTime();
priv.res.return_value = documentlist;
for (i = 0; i < priv.res.return_value.length; i += 1) {
priv.res.return_value[i].lastModified =
new Date(priv.res.return_value[i].lastModified).getTime();
priv.res.return_value[i].creationDate =
new Date(priv.res.return_value[i].creationDate).getTime();
}
};
priv.fail_removeDocument = function () {
priv.res.isRemoved = false;
priv.res.message = 'Unable to removed document.';
};
priv.done_removeDocument = function () {
priv.res.message = 'Document removed.';
priv.res.isRemoved = true;
};
priv.retryLater = function () {
......@@ -1002,8 +1000,12 @@ var JIO =
// example :
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) { alert('is available? ' +
// result.isAvailable); }});
// function (result) {
// if (result.status === 'done') {
// if (result.return_value === true) { // available
// } else { } // not available
// } else { } // Error
// }});
var settings = $.extend ({
'userName': priv.storage.userName,
......@@ -1033,8 +1035,10 @@ var JIO =
// - true if the job was added or replaced
// jio.saveDocument({'fileName':'file','fileContent':'content',
// 'callback': function (result) { alert('saved?' +
// result.isSaved); }});
// 'callback': function (result) {
// if (result.status === 'done') { // Saved
// } else { } // Error
// }});
var settings = $.extend({
'storage': priv.storage,
......@@ -1064,9 +1068,14 @@ var JIO =
// - true if the job was added or replaced
// jio.loadDocument({'fileName':'file','callback':
// function (result) { alert('content: '+
// result.doc.fileContent + ' creation date: ' +
// result.doc.creationDate); }});
// function (result) {
// if (result.status === 'done') { // Loaded
// } else { } // Error
// }});
// result.return_value is a document object that looks like {
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
'storage': priv.storage,
......@@ -1094,7 +1103,13 @@ var JIO =
// - true if the job was added or replaced
// jio.getDocumentList({'callback':
// function (result) { alert('list: '+result.list); }});
// function (result) {
// if (result.status === 'done') { // OK
// console.log(result.return_value);
// } else { } // Error
// }});
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
'storage': priv.storage,
......@@ -1121,7 +1136,10 @@ var JIO =
// - true if the job was added or replaced
// jio.removeDocument({'fileName':'file','callback':
// function (result) { alert('removed? '+result.isRemoved); }});
// function (result) {
// if(result.status === 'done') { // Removed
// } else { } // Not Removed
// }});
var settings = $.extend ({
'storage': priv.storage,
......
......@@ -518,18 +518,30 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// if the name already exists in a storage, it is not available.
// this.job.userName: the name we want to check.
// this.job.storage.storageArray: An Array of storages.
// TODO
var newjob = {}, isavailable = true, i = 'id',
var newjob = {}, i = 'id', done = false,
res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status === 'fail') {
res.status = 'fail';
} else {
if (result.return_value === false) {
that.done (false);
done = true;
return;
}
}
if (priv.returnsValuesArray.length ===
priv.length) {
if (res.status === 'fail') {
that.fail ('Unable to check name availability.',0);
} else {
that.done (true);
}
done = true;
return;
}
if (!result.isAvailable) { isavailable = false; }
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
that.done(isavailable);
}
};
priv.execJobsFromStorageArray(callback);
......@@ -543,7 +555,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name.
// this.job.fileContent: the document content.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
......@@ -577,7 +588,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
// TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
......@@ -585,7 +595,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.document);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -607,16 +617,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'fileName':string,
// the list is [object,object,...] -> object = {'fileName':string,
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -637,7 +646,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) {
......
......@@ -107,37 +107,37 @@ test ('All tests', function () {
o.jio = JIO.createNew({'type':'dummyallok','userName':'Dummy'},
{'ID':'jiotests'});
mytest('check name availability OK','checkNameAvailability',
'isAvailable',true);
mytest('save document OK','saveDocument','isSaved',true);
mytest('load document OK','loadDocument','document',
'return_value',true);
mytest('save document OK','saveDocument','status','done');
mytest('load document OK','loadDocument','return_value',
{'fileName':'file','fileContent':'content',
'lastModified':15000,'creationDate':10000});
mytest('get document list OK','getDocumentList','list',
mytest('get document list OK','getDocumentList','return_value',
[{'fileName':'file','creationDate':10000,'lastModified':15000},
{'fileName':'memo','creationDate':20000,'lastModified':25000}]);
mytest('remove document OK','removeDocument','isRemoved',true);
mytest('remove document OK','removeDocument','status','done');
o.jio.stop();
// All Fail Dummy Storage
o.jio = JIO.createNew({'type':'dummyallfail','userName':'Dummy'},
{'ID':'jiotests'});
mytest('check name availability FAIL','checkNameAvailability',
'isAvailable',false);
mytest('save document FAIL','saveDocument','isSaved',false);
mytest('load document FAIL','loadDocument','document',{});
mytest('get document list FAIL','getDocumentList','list',[]);
mytest('remove document FAIL','removeDocument','isRemoved',false);
'status','fail');
mytest('save document FAIL','saveDocument','status','fail');
mytest('load document FAIL','loadDocument','status','fail');
mytest('get document list FAIL','getDocumentList','status','fail');
mytest('remove document FAIL','removeDocument','status','fail');
o.jio.stop();
// All Not Found Dummy Storage
o.jio = JIO.createNew({'type':'dummyallnotfound','userName':'Dummy'},
{'ID':'jiotests'});
mytest('check name availability NOT FOUND','checkNameAvailability',
'isAvailable',true);
mytest('save document NOT FOUND','saveDocument','isSaved',true);
mytest('load document NOT FOUND','loadDocument','document',{});
mytest('get document list NOT FOUND','getDocumentList','list',[]);
mytest('remove document NOT FOUND','removeDocument','isRemoved',true);
'return_value',true);
mytest('save document NOT FOUND','saveDocument','status','done');
mytest('load document NOT FOUND','loadDocument','status','fail');
mytest('get document list NOT FOUND','getDocumentList','status','fail');
mytest('remove document NOT FOUND','removeDocument','status','done');
o.jio.stop();
});
......@@ -251,7 +251,7 @@ test ('Check name availability', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (value){
o.f = function (result) {
deepEqual(result.isAvailable,value,'checking name availabality');};
deepEqual(result.return_value,value,'checking name availabality');};
t.spy(o,'f');
o.jio.checkNameAvailability(
{'userName':'MrCheckName','callback': o.f,'maxtries':1});
......@@ -284,7 +284,7 @@ test ('Document save', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,lmcd){
o.f = function (result) {
deepEqual(result.isSaved,value,message);};
deepEqual(result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument(
{'fileName':'file','fileContent':'content','callback': o.f,
......@@ -310,12 +310,12 @@ test ('Document save', function () {
// save and check document existence
clock.tick(200);
// message, value, fun ( creationdate, lastmodified )
mytest('saving document',true,function(cd,lm){
mytest('saving document','done',function(cd,lm){
return (cd === lm);
});
// re-save and check modification date
mytest('saving again',true,function(cd,lm){
mytest('saving again','done',function(cd,lm){
return (cd < lm);
});
......@@ -350,7 +350,7 @@ test ('Document load', function () {
doc = {'fileName':'file','fileContent':'content',
'lastModified':1234,'creationDate':1000};
LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
mytest ('document',doc);
mytest ('return_value',doc);
o.jio.stop();
});
......@@ -364,11 +364,13 @@ test ('Get document list', function () {
mytest = function (value){
o.f = function (result) {
var objectifyDocumentArray = function (array) {
var obj = {};
for (var k in array) {obj[array[k].fileName] = array[k];}
var obj = {}, k;
for (k = 0; k < array.length; k+=1) {
obj[array[k].fileName] = array[k];
}
return obj;
};
deepEqual (objectifyDocumentArray(result.list),
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),'getting list');
};
t.spy(o,'f');
......@@ -401,7 +403,7 @@ test ('Document remove', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (){
o.f = function (result) {
deepEqual(result.isRemoved,true,'removing document');};
deepEqual(result.status,'done','removing document');};
t.spy(o,'f');
o.jio.removeDocument(
{'fileName':'file','callback': o.f,'maxtries':1});
......@@ -430,14 +432,14 @@ test ('Check name availability', function () {
// Test if DavStorage can check the availabality of a name.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (value,errno) {
mytest = function (method,value,errno) {
var server = t.sandbox.useFakeServer();
server.respondWith ("PROPFIND",
"https://ca-davstorage:8080/dav/davcheck/",
[errno, {'Content-Type': 'text/xml' },
'']);
o.f = function (result) {
deepEqual (result.isAvailable,value,'checking name availability');};
deepEqual(result[method],value,'checking name availability');};
t.spy(o,'f');
o.jio.checkNameAvailability({'userName':'davcheck','callback':o.f,
'maxtries':1});
......@@ -453,11 +455,11 @@ test ('Check name availability', function () {
'location':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// 404 error, the name does not exist, name is available.
mytest (true,404);
mytest ('return_value',true,404);
// 200 error, responding ok, the name already exists, name is not available.
mytest (false,200);
// 405 error, random error, name is not available by default.
mytest (false,405);
mytest ('return_value',false,200);
// 405 error, random error
mytest ('status','fail',405);
o.jio.stop();
});
......@@ -477,7 +479,7 @@ test ('Document load', function () {
"GET","https://ca-davstorage:8080/dav/davload/jiotests/file",
[errget,{},'content']);
o.f = function (result) {
deepEqual (result.document,doc,message);};
deepEqual (result.return_value,doc,message);};
t.spy(o,'f');
o.jio.loadDocument({'fileName':'file','callback':o.f,'maxtries':1});
clock.tick(500);
......@@ -498,7 +500,7 @@ test ('Document load', function () {
// 403 Forbidden
// 404 Not Found
// load an inexistant document.
mytest ('load inexistant document',{},404,404);
mytest ('load inexistant document',undefined,404,404);
// load a document.
mytest ('load document',{'fileName':'file','fileContent':'content',
'lastModified':1335953199000,
......@@ -534,7 +536,7 @@ test ('Document save', function () {
// "https://ca-davstorage:8080/dav/davsave/jiotests",
// [200,{},'']);
o.f = function (result) {
deepEqual (result.isSaved,value,message);};
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f,'maxtries':1});
......@@ -559,11 +561,10 @@ test ('Document save', function () {
// mytest('create path if not exists, and create document',
// true,201,404);
// the document does not exist, we want to create it
mytest('create document',true,201,404);
mytest('create document','done',201,404);
clock.tick(8000);
// the document already exists, we want to overwrite it
mytest('overwrite document',
true,204,207);
mytest('overwrite document','done',204,207);
o.jio.stop();
});
......@@ -580,12 +581,18 @@ test ('Get Document List', function () {
davlist]);
o.f = function (result) {
var objectifyDocumentArray = function (array) {
var obj = {};
for (var k in array) {obj[array[k].fileName] = array[k];}
var obj = {}, k;
for (k = 0; k < array.length; k += 1) {
obj[array[k].fileName] = array[k];
}
return obj;
};
deepEqual (objectifyDocumentArray(result.list),
if (result.status === 'fail') {
deepEqual (result.return_value, value, message);
} else {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),message);
}
};
t.spy(o,'f');
o.jio.getDocumentList({'callback':o.f,'maxtries':1});
......@@ -617,7 +624,7 @@ test ('Remove document', function () {
"DELETE","https://ca-davstorage:8080/dav/davremove/jiotests/file",
[errnodel,{},'']);
o.f = function (result) {
deepEqual (result.isRemoved,value,message);};
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.removeDocument({'fileName':'file','callback':o.f,'maxtries':1});
clock.tick(500);
......@@ -631,8 +638,8 @@ test ('Remove document', function () {
'location':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
mytest('remove document',true,204);
mytest('remove an already removed document',true,404);
mytest('remove document','done',204);
mytest('remove an already removed document','done',404);
o.jio.stop();
});
......@@ -647,7 +654,7 @@ test ('Check name availability', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.isAvailable,value,message);
deepEqual (result.return_value,value,message);
};
t.spy(o,'f');
o.jio.checkNameAvailability({'userName':'Dummy','callback':o.f,
......@@ -670,21 +677,21 @@ test ('Check name availability', function () {
{'type':'dummyallok','userName':'1'},
{'type':'dummyallfail','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllOK,Fail : name not available',false);
mytest('DummyStoragesAllOK,Fail : name not available',undefined);
o.jio.stop();
// DummyStorageAllFail,OK
o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallfail','userName':'1'},
{'type':'dummyallok','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllFail,OK : name not available',false);
mytest('DummyStoragesAllFail,OK : name not available',undefined);
o.jio.stop();
// DummyStorageAllFail,Fail
o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallfail','userName':'1'},
{'type':'dummyallfail','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllFail,Fail : name not available',false);
mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
o.jio.stop();
// DummyStorageAllOK,3Tries
o.maxtries = 3 ;
......@@ -710,12 +717,11 @@ test ('Check name availability', function () {
test ('Document load', function () {
// Test if ReplicateStorage can load several documents.
// TODO finish it
var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this;
var mytest = function (message,doc) {
o.f = function (result) {
deepEqual (result.document,doc,message);};
deepEqual (result.return_value,doc,message);};
t.spy(o,'f');
o.jio.loadDocument({'fileName':'file','callback':o.f});
clock.tick(100000);
......@@ -746,12 +752,11 @@ test ('Document load', function () {
test ('Document save', function () {
// Test if ReplicateStorage can save several documents.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
deepEqual (result.isSaved,value,message);};
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f,'maxtries':3});
......@@ -764,23 +769,24 @@ test ('Document save', function () {
{'type':'dummyallok','userName':'1'},
{'type':'dummyallok','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,OK: save a file.',true);
mytest('DummyStorageAllOK,OK: save a file.','done');
o.jio.stop();
});
test ('Get Document List', function () {
// Test if ReplicateStorage can get several list.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
var objectifyDocumentArray = function (array) {
var obj = {}, k;
for (k in array) {obj[array[k].fileName] = array[k];}
for (k = 0; k < array.length; k += 1) {
obj[array[k].fileName] = array[k];
}
return obj;
};
deepEqual (objectifyDocumentArray(result.list),
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),'getting list');
};
t.spy(o,'f');
......@@ -804,19 +810,11 @@ test ('Get Document List', function () {
test ('Remove document', function () {
// Test if ReplicateStorage can remove several documents.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
var objectifyDocumentArray = function (array) {
var obj = {}, k;
for (k in array) {obj[array[k].fileName] = array[k];}
return obj;
};
deepEqual (objectifyDocumentArray(result.list),
objectifyDocumentArray(value),'getting list');
};
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.removeDocument({'fileName':'file','callback':o.f,'maxtries':3});
clock.tick(100000);
......@@ -828,7 +826,7 @@ test ('Remove document', function () {
{'type':'dummyallok','userName':'1'},
{'type':'dummyall3tries','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: remove document .',true);
mytest('DummyStorageAllOK,3tries: remove document.','done');
o.jio.stop();
});
// end require
......@@ -846,7 +844,7 @@ if (window.requirejs) {
Base64API: '../lib/base64/base64',
Base64: '../js/base64.requirejs_module',
JIODummyStorages: '../src/jio.dummystorages',
JIOStorages: '../lib/jio/jio.storage.min'
JIOStorages: '../src/jio.storage'
}
});
require(['jiotestsloader'],thisfun);
......
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