Commit 258ef1c7 authored by François Billioud's avatar François Billioud

comment and correct DAVStorage

parent caa4fec2
......@@ -70,11 +70,12 @@
/*************************************************************************
************************* specific storages *****************************/
/************************************************************
*********************** DAVstorage *************************/
/************************************************************
*********************** DAVstorage *************************/
/**
* Class DAVStorage
* @class provides usual API to save/load/delete documents on a storage webDav
......@@ -237,61 +238,6 @@
},
/**
* load the list of the documents in this storage
* @param option : optional object containing
* "success" : the function to execute when the load is done
* "errorHandler" : the function to execute if an error occures
* "asynchronous" : a boolean set to false if the request must be synchronous
* @return null if the request is asynchronous, the list of documents otherwise.
* @example {"file1":{fileName:"file1",creationDate:"Tue, 23 Aug 2011 15:18:32 GMT",lastModified:"Tue, 23 Aug 2011 15:18:32 GMT"},...}
*/
getDocumentList: function(option) {
var storage = this;
var list = null;
$.ajax({
url: storage.location + "/dav/"+storage.userName+"/"+storage.applicationID+"/",
async: option.asyncronous || true,
type: "PROPFIND",
dataType: "xml",
headers: {Authorization: "Basic "+Base64.encode(this.userName+":"+this.applicationPassword), Depth: "1"},
fields: {withCredentials: "true"},
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");}
});
return list;//warning : always null if asyncronous
function xml2jsonFileList(xmlData) {//transform the xml into a list
var fileList = {};
$("D\\:response",xmlData)
.each(function(i,data){
if(i>0) {//exclude the parent folder
var name = fileName(data);
fileList[name]=xml2jsonFile(data)
fileList[name].fileName = name;
}
});
//remove webDav files from the list
delete fileList[".htaccess"];
delete fileList[".htpasswd"];
return fileList;
}
function xml2jsonFile(xmlData) {//transform the xml about a file into json information
var file = {};
file.lastModified = $($("lp1\\:getlastmodified",xmlData).get(0)).text();
file.creationDate = $($("lp1\\:creationdate",xmlData).get(0)).text();
return file;
}
function fileName(xmlData) {//read the name of a file in the xml
var string = $($("D\\:href",xmlData).get(0)).text()
var T = string.split("/");
return T[T.length-1] ? T[T.length-1] : T[T.length-2]+"/";
}
}
}
/************************************************************
*********************** LocalStorage ************************/
/**
......
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