Commit fcce672d authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Fix some errors and bugs.

- Unexpected Results:
object.attr || true (-> always true)
is completly different than
object.attr !== undefined ? oject.attr : true (-> if attr is defined then attr else true)
- Adding few semicolon at the end of some instructions.
- Adding few comments to improve reading comprehension.
parent 688ed2c7
...@@ -54,19 +54,19 @@ ...@@ -54,19 +54,19 @@
//IO functions //IO functions
getLocation: function() {return this.location}, getLocation: function() {return this.location},
userNameAvailable: function(name, option) { userNameAvailable: function(name, option) {
return this.storage.userNameAvailable(name, option||{}); return this.storage.userNameAvailable(name, option !== undefined ? option : {});
}, },
loadDocument: function(fileName, option) { loadDocument: function(fileName, option) {
return this.storage.loadDocument(fileName, option||{}); return this.storage.loadDocument(fileName, option !== undefined ? option : {});
}, },
saveDocument: function(data, fileName, option) { saveDocument: function(data, fileName, option) {
return this.storage.saveDocument(data, fileName, option||{}); return this.storage.saveDocument(data, fileName, option !== undefined ? option : {});
}, },
deleteDocument: function(file, option) { deleteDocument: function(file, option) {
return this.storage.deleteDocument(file, option||{}); return this.storage.deleteDocument(file, option !== undefined ? option : {});
}, },
getDocumentList: function(option) { getDocumentList: function(option) {
return this.storage.getDocumentList(option||{}); return this.storage.getDocumentList(option !== undefined ? option : {});
} }
} }
...@@ -111,11 +111,13 @@ ...@@ -111,11 +111,13 @@
$.ajax({ $.ajax({
url: this.location + "/dav/"+name, url: this.location + "/dav/"+name,
type: "HEAD", type: "HEAD",
async: option.asyncronous || true, async: option.asynchronous !== undefined ? option.asynchronous : true,
success: function() {isAvailable=true;if(option.sucess) option.success();}, success: function() {isAvailable=true;if(option.sucess) option.success();},
error: option.errorHandler || function(type) {if(type.status==404) {isAvailable=false;}else{alert("Error "+type.status+" : fail while trying to check "+name);}} error: option.errorHandler !== undefined ?
option.errorHandler :
function(type) {if(type.status==404) {isAvailable=false;}else{alert("Error "+type.status+" : fail while trying to check "+name);}}
}); });
return isAvailable;//warning : always null if asyncronous return isAvailable;//warning : always null if asynchronous
}, },
...@@ -134,14 +136,16 @@ ...@@ -134,14 +136,16 @@
$.ajax({ $.ajax({
url: this.location + "/dav/"+this.userName+"/"+this.applicationID+"/"+fileName, url: this.location + "/dav/"+this.userName+"/"+this.applicationID+"/"+fileName,
type: "GET", type: "GET",
async: option.asyncronous || true, async: option.asynchronous !== undefined ? option.asynchronous : true,
dataType: option.type || "text", dataType: option.type !== undefined ? option.type : "text",
headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword)}, headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword)},
fields: {withCredentials: "true"}, fields: {withCredentials: "true"},
success: function(content) {if(option.success) option.success(content);data=content}, success: function(content) {if(option.success) option.success(content);data=content},
error: option.errorHandler || function(type) {alert("Error "+type.status+" : fail while trying to load "+fileName);} error: option.errorHandler !== undefined ?
option.errorHandler :
function(type) {alert("Error "+type.status+" : fail while trying to load "+fileName);}
}); });
return data;//warning : always null if asyncronous return data;//warning : always null if asynchronous
}, },
...@@ -162,7 +166,7 @@ ...@@ -162,7 +166,7 @@
var storage = this;//save the context var storage = this;//save the context
//check if already exists and for diffs //check if already exists and for diffs
var loadOption = { this.loadDocument(fileName, {
type: option.type, type: option.type,
asynchronous: false,//TODO : try to asynchronize asynchronous: false,//TODO : try to asynchronize
success: function(remoteData) { success: function(remoteData) {
...@@ -172,18 +176,18 @@ ...@@ -172,18 +176,18 @@
if(type.status==404) { if(type.status==404) {
save(); save();
} else { } else {
option.errorHandler || save(); option.errorHandler !== undefined ?
} option.errorHandler : save();
} }
} }
this.loadDocument(fileName, loadOption); });
function save() { function save() {
$.ajax({ $.ajax({
url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/"+fileName, url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/"+fileName,
type: "PUT", type: "PUT",
async: option.asynchronous || true, async: option.asynchronous !== undefined ? option.asynchronous : true,
dataType: option.type || "text", dataType: option.type !== undefined ? option.type : "text",
data: data, data: data,
headers: {Authorization: "Basic "+Base64.encode(storage.userName+":"+storage.applicationPassword)}, headers: {Authorization: "Basic "+Base64.encode(storage.userName+":"+storage.applicationPassword)},
fields: {withCredentials: "true"}, fields: {withCredentials: "true"},
...@@ -193,16 +197,16 @@ ...@@ -193,16 +197,16 @@
else {option.errorHandler ? option.errorHandler.call(this,type) : alert("Error "+type.status+" : fail while trying to save "+fileName);} else {option.errorHandler ? option.errorHandler.call(this,type) : alert("Error "+type.status+" : fail while trying to save "+fileName);}
} }
}); });
} }// end save function
function merge(serverData) { function merge(serverData) {
if(option.overwrite!==false) { if(option.overwrite!==false) {
//if(diff(oldData,serverData)) {merge(newData, serverData);} //if(diff(oldData,serverData)) {merge(newData, serverData);}
save(); save();
} }
} }// end merge function
}, },// end saveDocument function
/** /**
...@@ -221,7 +225,7 @@ ...@@ -221,7 +225,7 @@
$.ajax({ $.ajax({
url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/"+fileName, url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/"+fileName,
type: "DELETE", type: "DELETE",
async: option.asynchronous || true, async: option.asynchronous !== undefined ? option.asynchronous : true,
headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword)}, headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword)},
fields: {withCredentials: "true"}, fields: {withCredentials: "true"},
success: successFunction, success: successFunction,
...@@ -255,15 +259,15 @@ ...@@ -255,15 +259,15 @@
var list = null; var list = null;
$.ajax({ $.ajax({
url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/", url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/",
async: option.asyncronous || true, async: option.asynchronous !== undefined ? option.asynchronous : true,
type: "PROPFIND", type: "PROPFIND",
dataType: "xml", dataType: "xml",
headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword), Depth: "1"}, headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword), Depth: "1"},
fields: {withCredentials: "true"}, fields: {withCredentials: "true"},
success: function(data) {list=xml2jsonFileList(data);if(option.success) option.success(list)}, success: function(data) {list=xml2jsonFileList(data);if(option.success) option.success(list)},
error: option.errorHandler || function(type) {alert("Error "+type.status+" : fail while trying to load file list");} error: option.errorHandler !== undefined ? option.errorHandler : function(type) {alert("Error "+type.status+" : fail while trying to load file list");}
}); });
return list;//warning : always null if asyncronous return list;//warning : always null if asynchronous
function xml2jsonFileList(xmlData) {//transform the xml into a list function xml2jsonFileList(xmlData) {//transform the xml into a list
var fileList = {}; var fileList = {};
...@@ -372,7 +376,7 @@ ...@@ -372,7 +376,7 @@
this.documents[fileName].lastModified = Date.now(); this.documents[fileName].lastModified = Date.now();
this.documents[fileName].content = data; this.documents[fileName].content = data;
this.save(); this.save();
if(option.success) option.success(); if(option.success !== undefined) option.success();
} else { //repport an error } else { //repport an error
var error = {status: 403,message: "document already exists"}; var error = {status: 403,message: "document already exists"};
if(option.errorHandler) option.errorHandler(error); if(option.errorHandler) option.errorHandler(error);
...@@ -430,7 +434,7 @@ ...@@ -430,7 +434,7 @@
* @param applicant : object containing inforamtion about the person/application needing this JIO object * @param applicant : object containing inforamtion about the person/application needing this JIO object
*/ */
JIO.IndexedStorage = function(data, applicant) { JIO.IndexedStorage = function(data, applicant) {
this.storage = createStorage(data.storage, applicant)//create the object allowing IO in storages this.storage = createStorage(data.storage, applicant);//create the object allowing IO in storages
this.index = null; this.index = null;
//initialize the index //initialize the index
...@@ -488,7 +492,7 @@ ...@@ -488,7 +492,7 @@
var fileAlreadyExist = this.getIndex()[fileName]!==undefined; var fileAlreadyExist = this.getIndex()[fileName]!==undefined;
var instruction = function() { var instruction = function() {
var time = Date.now(); var time = Date.now();
indexedStorage.getIndex()[fileName] = option.metaData || {}; indexedStorage.getIndex()[fileName] = (option.metaData !== undefined ? option.metaData : {});
indexedStorage.getIndex()[fileName].lastModified = time; indexedStorage.getIndex()[fileName].lastModified = time;
indexedStorage.getIndex()[fileName].fileName = fileName; indexedStorage.getIndex()[fileName].fileName = fileName;
if(!fileAlreadyExist) {indexedStorage.getIndex()[fileName].creationDate = time;} if(!fileAlreadyExist) {indexedStorage.getIndex()[fileName].creationDate = time;}
...@@ -816,7 +820,7 @@ ...@@ -816,7 +820,7 @@
if(path.length>1) { if(path.length>1) {
var storage = path.shift(); var storage = path.shift();
var name = path.join("/"); var name = path.join("/");
this.storageList[storage].saveDocument(data, name, option) this.storageList[storage].saveDocument(data, name, option);
} else { } else {
//TODO : decide how to choose between storages //TODO : decide how to choose between storages
} }
...@@ -995,7 +999,7 @@ ...@@ -995,7 +999,7 @@
async: false, async: false,
dataType: "script", dataType: "script",
success: function(script){var CustomStorage = eval(script);waitedNode = new CustomStorage(data)}, success: function(script){var CustomStorage = eval(script);waitedNode = new CustomStorage(data)},
error: data.errorHandler || function(type) {alert("Error "+type.status+" : fail while trying to instanciate storage"+data.location);} error: data.errorHandler !== undefined ? data.errorHandler : function(type) {alert("Error "+type.status+" : fail while trying to instanciate storage"+data.location);}
}); });
return waitedNode; return waitedNode;
break; break;
......
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