Commit 10a18668 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Improving LocalStorage + updating Qunit tests.

parent d0ac8107
This diff is collapsed.
...@@ -23,20 +23,47 @@ var getXML = function (url) { ...@@ -23,20 +23,47 @@ var getXML = function (url) {
dataType:'text',success:function(xml){tmp=xml;}}); dataType:'text',success:function(xml){tmp=xml;}});
return tmp; return tmp;
}, },
addPath = function (path) { addFile = function (user,appid,file) {
var array = LocalOrCookieStorage.getItem ('jio/localfilearray') || []; var i, l, found = false, filenamearray,
array.push(path); userarray = LocalOrCookieStorage.getItem('jio/localuserarray') || [];
LocalOrCookieStorage.setItem ('jio/localfilearray',array); for (i = 0, l = userarray.length; i < l; i+= 1) {
if (userarray[i] === user) { found = true; }
}
if (!found) {
userarray.push(user);
LocalOrCookieStorage.setItem('jio/localuserarray',userarray);
LocalOrCookieStorage.setItem('jio/localfilenamearray/'+user+'/'+appid,
[file.fileName]);
} else {
filenamearray =
LocalOrCookieStorage.getItem(
'jio/localfilenamearray/'+user+'/'+appid) || [];
filenamearray.push(file.fileName);
LocalOrCookieStorage.setItem(
'jio/localfilenamearray/'+user+'/'+appid,
filenamearray);
LocalOrCookieStorage.setItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName,
file);
}
LocalOrCookieStorage.setItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName,
file);
}, },
removePath = function (path) { removeFile = function (user,appid,file) {
var array = LocalOrCookieStorage.getItem ('jio/localfilearray') || [], var i, l, newarray = [],
newarray = [], i; filenamearray =
for (i = 0; i < array.length; i+= 1) { LocalOrCookieStorage.getItem(
if (array[i] !== path) { 'jio/localfilenamearray/'+user+'/'+appid) || [];
newarray.push (array[i]); for (i = 0, l = filenamearray.length; i < l; i+= 1) {
if (filenamearray[i] !== file.fileName) {
newarray.push(filenamearray[i]);
} }
} }
LocalOrCookieStorage.setItem ('jio/localfilearray',newarray); LocalOrCookieStorage.setItem('jio/localfilenamearray/'+user+'/'+appid,
newarray);
LocalOrCookieStorage.deleteItem(
'jio/local/'+user+'/'+appid+'/'+file.fileName);
}; };
//// end tools //// end tools
...@@ -281,11 +308,11 @@ test ('Check name availability', function () { ...@@ -281,11 +308,11 @@ test ('Check name availability', function () {
{"ID":'noid'}); {"ID":'noid'});
// name must be available // name must be available
removePath ('jio/local/MrCheckName/jiotests/file'); removeFile ('MrCheckName','jiotests',{fileName:'file'});
mytest(true); mytest(true);
// name must be unavailable // name must be unavailable
addPath ('jio/local/MrCheckName/jiotests/file'); addFile ('MrCheckName','jiotests',{fileName:'file'});
mytest(false); mytest(false);
o.jio.stop(); o.jio.stop();
...@@ -401,10 +428,8 @@ test ('Get document list', function () { ...@@ -401,10 +428,8 @@ test ('Get document list', function () {
'lastModified':1,'creationDate':0}; 'lastModified':1,'creationDate':0};
doc2 = {'fileName':'memo','fileContent':'test', doc2 = {'fileName':'memo','fileContent':'test',
'lastModified':5,'creationDate':2}; 'lastModified':5,'creationDate':2};
addPath ('jio/local/MrListName/jiotests/file'); addFile ('MrListName','jiotests',doc1);
addPath ('jio/local/MrListName/jiotests/memo'); addFile ('MrListName','jiotests',doc2);
LocalOrCookieStorage.setItem ('jio/local/MrListName/jiotests/file',doc1);
LocalOrCookieStorage.setItem ('jio/local/MrListName/jiotests/memo',doc2);
delete doc1.fileContent; delete doc1.fileContent;
delete doc2.fileContent; delete doc2.fileContent;
mytest ([doc1,doc2]); mytest ([doc1,doc2]);
......
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