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

Redesigning classes and var names.

parent 806c6e95
This diff is collapsed.
This diff is collapsed.
/*! JIO Storage - v0.1.0 - 2012-05-23 /*! JIO Storage - v0.1.0 - 2012-05-24
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
...@@ -12,21 +12,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -12,21 +12,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Tools // Tools
var extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools // end Tools
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Classes // Classes
var LocalStorage,DAVStorage,ReplicateStorage; newLocalStorage,newDAVStorage,newReplicateStorage;
// end Classes // end Classes
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Local Storage // Local Storage
LocalStorage = function ( args ) { newLocalStorage = function ( spec, my ) {
// LocalStorage constructor // LocalStorage constructor
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// checks the availability of the [job.userName]. // checks the availability of the [job.userName].
...@@ -99,7 +106,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -99,7 +106,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
var doc = null, settings = $.extend( var doc = null, settings = extend(
{'getContent':true},that.cloneOptionObject()); {'getContent':true},that.cloneOptionObject());
doc = LocalOrCookieStorage.getItem( doc = LocalOrCookieStorage.getItem(
...@@ -174,8 +181,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -174,8 +181,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// DAVStorage // DAVStorage
DAVStorage = function ( args ) { newDAVStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( spec, my );
that.mkcol = function ( options ) { that.mkcol = function ( options ) {
// create folders in dav storage, synchronously // create folders in dav storage, synchronously
...@@ -188,7 +195,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -188,7 +195,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO this method is not working !!! // TODO this method is not working !!!
var settings = $.extend ({ var settings = extend ({
'success':function(){},'error':function(){}},options), 'success':function(){},'error':function(){}},options),
splitpath = ['splitedpath'], tmppath = 'temp/path'; splitpath = ['splitedpath'], tmppath = 'temp/path';
...@@ -321,7 +328,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -321,7 +328,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
var doc = {}, var doc = {},
settings = $.extend({'getContent':true},that.cloneOptionObject()), settings = extend({'getContent':true},that.cloneOptionObject()),
// TODO check if job's features are good // TODO check if job's features are good
getContent = function () { getContent = function () {
...@@ -476,12 +483,10 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -476,12 +483,10 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.getStorageUserName() + ':' + that.getStorageUserName() + ':' +
that.getStoragePassword() )}, that.getStoragePassword() )},
// xhrFields: {withCredentials: 'true'}, // cross domain // xhrFields: {withCredentials: 'true'}, // cross domain
success: function (a) { success: function () {
console.log (a);
that.done(); that.done();
}, },
error: function (type) { error: function (type) {
console.log (type);
if (type.status === 404) { if (type.status === 404) {
that.done(); that.done();
} else { } else {
...@@ -499,8 +504,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -499,8 +504,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// ReplicateStorage // ReplicateStorage
ReplicateStorage = function ( args ) { newReplicateStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storageArray = that.getStorageArray(); priv.storageArray = that.getStorageArray();
// TODO Add a tests that check if there is no duplicate storages. // TODO Add a tests that check if there is no duplicate storages.
...@@ -706,13 +711,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -706,13 +711,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// add key to storageObjectType of global jio // add key to storageObjectType of global jio
Jio.addStorageType('local', function (options) { Jio.addStorageType('local', function (options) {
return new LocalStorage(options); return newLocalStorage(options);
}); });
Jio.addStorageType('dav', function (options) { Jio.addStorageType('dav', function (options) {
return new DAVStorage(options); return newDAVStorage(options);
}); });
Jio.addStorageType('replicate', function (options) { Jio.addStorageType('replicate', function (options) {
return new ReplicateStorage(options); return newReplicateStorage(options);
}); });
}; };
......
This diff is collapsed.
/*! 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 */ * Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage = 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 */ * 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()}(); 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 @@ ...@@ -9,8 +9,8 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok // Dummy Storage 1 : all ok
var DummyStorageAllOk = function ( args ) { var newDummyStorageAllOk = function ( spec, my ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// The [job.userName] IS available. // The [job.userName] IS available.
...@@ -81,8 +81,8 @@ ...@@ -81,8 +81,8 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail // Dummy Storage 2 : all fail
DummyStorageAllFail = function ( args ) { newDummyStorageAllFail = function ( spec, my ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// Fails to check [job.userName]. // Fails to check [job.userName].
...@@ -147,8 +147,8 @@ ...@@ -147,8 +147,8 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found // Dummy Storage 3 : all not found
DummyStorageAllNotFound = function ( args ) { newDummyStorageAllNotFound = function ( spec, my ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( spec, my );
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// [job.userName] not found, so the name is available. // [job.userName] not found, so the name is available.
...@@ -211,8 +211,8 @@ ...@@ -211,8 +211,8 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries // Dummy Storage 4 : all 3 tries
DummyStorageAll3Tries = function ( args ) { newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.doJob = function (ifokreturn) { priv.doJob = function (ifokreturn) {
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
...@@ -270,16 +270,16 @@ ...@@ -270,16 +270,16 @@
// add key to storageObjectType of global jio // add key to storageObjectType of global jio
Jio.addStorageType('dummyallok', function (options) { Jio.addStorageType('dummyallok', function (options) {
return new DummyStorageAllOk(options); return newDummyStorageAllOk(options);
}); });
Jio.addStorageType('dummyallfail', function (options) { Jio.addStorageType('dummyallfail', function (options) {
return new DummyStorageAllFail(options); return newDummyStorageAllFail(options);
}); });
Jio.addStorageType('dummyallnotfound', function (options) { Jio.addStorageType('dummyallnotfound', function (options) {
return new DummyStorageAllNotFound(options); return newDummyStorageAllNotFound(options);
}); });
Jio.addStorageType('dummyall3tries', function (options) { Jio.addStorageType('dummyall3tries', function (options) {
return new DummyStorageAll3Tries(options); return newDummyStorageAll3Tries(options);
}); });
}; };
......
This diff is collapsed.
...@@ -9,21 +9,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -9,21 +9,28 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Tools // Tools
var extend = function (o1,o2) {
var key;
for (key in o2) {
o1[key] = o2[key];
}
return o1;
},
// end Tools // end Tools
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Classes // Classes
var LocalStorage,DAVStorage,ReplicateStorage; newLocalStorage,newDAVStorage,newReplicateStorage;
// end Classes // end Classes
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Local Storage // Local Storage
LocalStorage = function ( args ) { newLocalStorage = function ( spec, my ) {
// LocalStorage constructor // LocalStorage constructor
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// checks the availability of the [job.userName]. // checks the availability of the [job.userName].
...@@ -96,7 +103,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -96,7 +103,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
var doc = null, settings = $.extend( var doc = null, settings = extend(
{'getContent':true},that.cloneOptionObject()); {'getContent':true},that.cloneOptionObject());
doc = LocalOrCookieStorage.getItem( doc = LocalOrCookieStorage.getItem(
...@@ -171,8 +178,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -171,8 +178,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// DAVStorage // DAVStorage
DAVStorage = function ( args ) { newDAVStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( spec, my );
that.mkcol = function ( options ) { that.mkcol = function ( options ) {
// create folders in dav storage, synchronously // create folders in dav storage, synchronously
...@@ -185,7 +192,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -185,7 +192,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO this method is not working !!! // TODO this method is not working !!!
var settings = $.extend ({ var settings = extend ({
'success':function(){},'error':function(){}},options), 'success':function(){},'error':function(){}},options),
splitpath = ['splitedpath'], tmppath = 'temp/path'; splitpath = ['splitedpath'], tmppath = 'temp/path';
...@@ -318,7 +325,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -318,7 +325,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
var doc = {}, var doc = {},
settings = $.extend({'getContent':true},that.cloneOptionObject()), settings = extend({'getContent':true},that.cloneOptionObject()),
// TODO check if job's features are good // TODO check if job's features are good
getContent = function () { getContent = function () {
...@@ -494,8 +501,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -494,8 +501,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// ReplicateStorage // ReplicateStorage
ReplicateStorage = function ( args ) { newReplicateStorage = function ( spec, my ) {
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storageArray = that.getStorageArray(); priv.storageArray = that.getStorageArray();
// TODO Add a tests that check if there is no duplicate storages. // TODO Add a tests that check if there is no duplicate storages.
...@@ -701,13 +708,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -701,13 +708,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// add key to storageObjectType of global jio // add key to storageObjectType of global jio
Jio.addStorageType('local', function (options) { Jio.addStorageType('local', function (options) {
return new LocalStorage(options); return newLocalStorage(options);
}); });
Jio.addStorageType('dav', function (options) { Jio.addStorageType('dav', function (options) {
return new DAVStorage(options); return newDAVStorage(options);
}); });
Jio.addStorageType('replicate', function (options) { Jio.addStorageType('replicate', function (options) {
return new ReplicateStorage(options); return newReplicateStorage(options);
}); });
}; };
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
$ = loader.jQuery; $ = loader.jQuery;
//// clear jio localstorage //// clear jio localstorage
(function () { (function () {
var k, storageObject = LocalOrCookieStorage.getAll(); var k, storageObject = LocalOrCookieStorage.getAll();
for (k in storageObject) { for (k in storageObject) {
var splitk = k.split('/'); var splitk = k.split('/');
if ( splitk[0] === 'jio' ) { if ( splitk[0] === 'jio' ) {
LocalOrCookieStorage.deleteItem(k); LocalOrCookieStorage.deleteItem(k);
}
} }
}()); }
}());
//// end clear jio localstorage //// end clear jio localstorage
//// Tools //// Tools
...@@ -152,12 +152,12 @@ test ('Simple Job Elimination', function () { ...@@ -152,12 +152,12 @@ test ('Simple Job Elimination', function () {
id = o.jio.getID(); id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1,'maxtries':1}); 'callback':o.f1,'maxtries':1});
ok(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'], ok(LocalOrCookieStorage.getItem('jio/jobobject/'+id)['1'],
'job creation'); 'job creation');
clock.tick(10); clock.tick(10);
o.jio.removeDocument({'fileName':'file','fileContent':'content', o.jio.removeDocument({'fileName':'file','fileContent':'content',
'callback':o.f2,'maxtries':1}); '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'); ok(!o.tmp || o.tmp.status === 'fail','job elimination');
}); });
...@@ -180,7 +180,7 @@ test ('Simple Job Replacement', function () { ...@@ -180,7 +180,7 @@ test ('Simple Job Replacement', function () {
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f2,'maxtries':1}); 'callback':o.f2,'maxtries':1});
deepEqual(LocalOrCookieStorage.getItem( 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.'); 'The first job date have to be equal to the second job date.');
clock.tick(500); clock.tick(500);
deepEqual([o.f1.calledOnce,o.status],[true,'fail'], deepEqual([o.f1.calledOnce,o.status],[true,'fail'],
...@@ -205,16 +205,16 @@ test ('Simple Job Waiting', function () { ...@@ -205,16 +205,16 @@ test ('Simple Job Waiting', function () {
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f4,'maxtries':1}); 'callback':o.f4,'maxtries':1});
ok(LocalOrCookieStorage.getItem( ok(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'] && 'jio/jobobject/'+id)['2'] &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['1'].status === 'ongoing', 'jio/jobobject/'+id)['1'].status === 'ongoing',
'The second job must not overwrite the first ongoing one.'); 'The second job must not overwrite the first ongoing one.');
ok(LocalOrCookieStorage.getItem( ok(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].status === 'wait' && 'jio/jobobject/'+id)['2'].status === 'wait' &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].waitingFor && 'jio/jobobject/'+id)['2'].waitingFor &&
JSON.stringify (LocalOrCookieStorage.getItem( 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'); 'The second job must be waiting for the first to end');
clock.tick(500); clock.tick(500);
ok(o.f3.calledOnce,'first request passed'); 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