Commit 543c6f42 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

JIO Local Storage does not browse all localStorage anymore.

parent 11f81591
...@@ -32,6 +32,34 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -32,6 +32,34 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
var that = Jio.newBaseStorage( spec, my ), priv = {}; var that = Jio.newBaseStorage( spec, my ), priv = {};
priv.storage_file_array_name = 'jio/local/filearray';
priv.getPathArray = function () {
var storage_file_array =
LocalOrCookieStorage.getItem(priv.storage_file_array_name);
if (storage_file_array === null) {
LocalOrCookieStorage.setItem(priv.storage_file_array_name,[]);
return [];
}
return storage_file_array;
};
priv.addPath = function (path) {
var patharray = priv.getPathArray();
patharray.push(path);
LocalOrCookieStorage.setItem(priv.storage_file_array_name,
patharray);
};
priv.removePath = function (path) {
var i, patharray = priv.getPathArray(), newpatharray = [];
for (i = 0; i < patharray.length; i+= 1) {
if (patharray[i] !== path) {
newpatharray.push(patharray[i]);
}
}
LocalOrCookieStorage.setItem(priv.storage_file_array_name,
newpatharray);
};
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// checks the availability of the [job.userName]. // checks the availability of the [job.userName].
// if the name already exists, it is not available. // if the name already exists, it is not available.
...@@ -39,14 +67,14 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -39,14 +67,14 @@ 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 localStorageObject = null, k, splitk; var allpatharray, i, split;
localStorageObject = LocalOrCookieStorage.getAll(); allpatharray = priv.getPathArray();
for (k in localStorageObject) { for (i = 0; i < allpatharray.length; i += 1) {
splitk = k.split('/'); split = allpatharray.split('/');
if (splitk[0] === 'jio' && if (split[0] === 'jio' &&
splitk[1] === 'local' && split[1] === 'local' &&
splitk[2] === that.getUserName()) { split[2] === that.getUserName()) {
return that.done(false); return that.done(false);
} }
} }
...@@ -64,13 +92,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -64,13 +92,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// wait a little in order to simulate asynchronous saving // wait a little in order to simulate asynchronous saving
setTimeout (function () { setTimeout (function () {
var doc = null; var doc = null, path =
'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName();
// reading // reading
doc = LocalOrCookieStorage.getItem( doc = LocalOrCookieStorage.getItem(path);
'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName());
if (!doc) { if (!doc) {
// create document // create document
doc = { doc = {
...@@ -79,6 +107,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -79,6 +107,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
'creationDate': Date.now(), 'creationDate': Date.now(),
'lastModified': Date.now() 'lastModified': Date.now()
}; };
priv.addPath(path);
} else { } else {
// overwriting // overwriting
doc.lastModified = Date.now(); doc.lastModified = Date.now();
...@@ -133,17 +162,18 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -133,17 +162,18 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// 'lastModified':date,'creationDate':date} // 'lastModified':date,'creationDate':date}
setTimeout(function () { setTimeout(function () {
var list = [], localStorageObject = null, k = 'key', var list = [], patharray = [], i, k = 'key',
splitk = ['splitedkey'], fileObject = {}; splitk = ['splitedkey'], fileObject = {};
localStorageObject = LocalOrCookieStorage.getAll(); patharray = priv.getPathArray();
for (k in localStorageObject) { for (i = 0; i < patharray.length; i += 1) {
k = patharray[i];
splitk = k.split('/'); splitk = k.split('/');
if (splitk[0] === 'jio' && if (splitk[0] === 'jio' &&
splitk[1] === 'local' && splitk[1] === 'local' &&
splitk[2] === that.getStorageUserName() && splitk[2] === that.getStorageUserName() &&
splitk[3] === that.getApplicantID()) { splitk[3] === that.getApplicantID()) {
fileObject = JSON.parse(localStorageObject[k]); fileObject = LocalOrCookieStorage.getItem(k);
list.push ({ list.push ({
'fileName':fileObject.fileName, 'fileName':fileObject.fileName,
'creationDate':fileObject.creationDate, 'creationDate':fileObject.creationDate,
...@@ -161,12 +191,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -161,12 +191,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.fileName: the document name. // this.job.fileName: the document name.
setTimeout (function () { setTimeout (function () {
var path = 'jio/local/'+
that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName()
// deleting // deleting
LocalOrCookieStorage.deleteItem( LocalOrCookieStorage.deleteItem(path);
'jio/local/'+ priv.removePath(path);
that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+
that.getFileName());
return that.done(); return that.done();
}, 100); }, 100);
}; };
......
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