feature(storage) change to async

This commit is contained in:
coderaiser 2014-02-18 04:51:57 -05:00
parent 059b2f054b
commit 961584ba65
4 changed files with 106 additions and 102 deletions

View file

@ -267,9 +267,13 @@ var Util, DOM, CloudFunc;
dirPath = CloudFunc.rmLastSlash(dirPath) || '/';
if (!Storage.get(dirPath))
Storage.set(dirPath, getJSONfromFileTable());
Storage.get(dirPath, function(data) {
if (!data) {
data = getJSONfromFileTable();
Storage.set(dirPath, data);
}
});
});
Util.exec(CloudCmd.Key);
Util.exec(pCallBack);
@ -336,9 +340,7 @@ var Util, DOM, CloudFunc;
* { refresh, nohistory } - необходимость обновить данные о каталоге
*/
this.ajaxLoad = function(path, options) {
var json, str,
ret = options && options.refresh,
SLASH = '/',
var SLASH = '/',
dirPath = DOM.getCurrentDirPath(),
fsPath = decodeURI(path),
noJSONPath = Util.removeStr(fsPath, '?json' ),
@ -372,37 +374,24 @@ var Util, DOM, CloudFunc;
* если стоит поле обязательной перезагрузки -
* перезагружаемся
*/
if (!ret) {
str = Storage.get(cleanPath);
Storage.get(cleanPath, function(json) {
var ret = options && options.refresh;
if (!str)
ret = true;
else {
json = Util.parseJSON(str);
if (!ret && json) {
json = Util.parseJSON(json);
CloudCmd.createFileTable(json);
setTitle();
}
}
if (ret)
DOM.getCurrentFileContent({
url : fsPath,
dataType : 'json',
success : function(data) {
var str = Util.stringifyJSON(data),
MAX_SIZE = 50000;
setTitle();
CloudCmd.createFileTable(data);
Util.log(str.length);
/* если размер данных не очень бошьой *
* сохраняем их в кэше */
if (str.length < MAX_SIZE)
Storage.set(cleanPath, str);
}
});
} else
DOM.getCurrentFileContent({
url : fsPath,
dataType : 'json',
success : function(json) {
setTitle();
CloudCmd.createFileTable(json);
Storage.set(cleanPath, json);
}
});
});
};
/**