Commit d275a48c authored by François Billioud's avatar François Billioud

correct storage saving in localStorage

parent a87133ef
...@@ -210,24 +210,25 @@ var Storage = new UngObject(); ...@@ -210,24 +210,25 @@ var Storage = new UngObject();
Storage.load({ Storage.load({
/* create the storage from storage. Used in the login page */ /* create the storage from storage. Used in the login page */
create: function (jioFileContent) { create: function (jioFileContent) {
this.jio = JIO.initialize(jioFileContent,{"ID":"www.ungproject.com"}); this.jio = jioFileContent;
JIO.initialize(jioFileContent,{"ID":"www.ungproject.com"});
Storage.currentStorage = this; Storage.currentStorage = this;
//try to load user parameters //try to load user parameters
var storage = this; var storage = this;
var option = { var option = {
success: function(data) {//success success: function(data) {//success
storage.setUser(new User(JSON.parse(data))); storage.user = new User(JSON.parse(data));
storage.save(); storage.userName = storage.user.getName();
storage.fireEvent(Storage.STORAGE_CREATED); storage.save(function() {storage.fireEvent(Storage.STORAGE_CREATED);});
}, },
errorHandler: function(errorEvent) {//fail errorHandler: function(errorEvent) {//fail
if(errorEvent.status==404){//create a new user if there was no such one if(errorEvent.status==404){//create a new user if there was no such one
var user = new User(); var user = new User();
user.setName(jioFileContent.userName); user.setName(jioFileContent.userName);
storage.setUser(user); storage.user = user;
storage.user.storageLocation = jioFileContent.location; storage.userName = storage.user.getName();
storage.save(); storage.user.storageLocation = jioFileContent.location;debugger;
storage.fireEvent(Storage.STORAGE_CREATED); storage.save(function() {storage.fireEvent(Storage.STORAGE_CREATED);});
} }
}, },
asynchronous: false asynchronous: false
...@@ -295,10 +296,17 @@ Storage.load({ ...@@ -295,10 +296,17 @@ Storage.load({
} }
JIO.getDocumentList(option); JIO.getDocumentList(option);
}, },
save: function() { // update and save user information in the localStorage save: function(instruction) { // update and save user information in the localStorage
this.updateUser(); this.updateUser();
this.saveDocument(this.user,this.user.getName()+".profile",function() { this.saveDocument(this.user,this.user.getName()+".profile",function() {
localStorage.setItem("currentStorage",JSON.stringify(this)); var storage = {
jio:Storage.jio,
user:Storage.user,
userName:Storage.userName
}
debugger;
localStorage.currentStorage = JSON.stringify(storage);
if(instruction) {instruction();}
}); });
}, },
......
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