mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
refactor(client) ajaxLoad
This commit is contained in:
parent
5baa32871a
commit
cad88ad229
1 changed files with 35 additions and 40 deletions
|
|
@ -327,26 +327,26 @@ var Util, DOM, CloudFunc;
|
|||
* @param pOptions
|
||||
* { refresh, nohistory } - необходимость обновить данные о каталоге
|
||||
*/
|
||||
this.ajaxLoad = function(pPath, pOptions) {
|
||||
if (!pOptions)
|
||||
pOptions = {};
|
||||
this.ajaxLoad = function(path, options) {
|
||||
var json, str,
|
||||
ret = options && options.refresh,
|
||||
SLASH = '/',
|
||||
fsPath = decodeURI(path),
|
||||
noJSONPath = Util.removeStr(fsPath, '?json' ),
|
||||
cleanPath = Util.removeStrOneTime(noJSONPath, CloudFunc.FS) || SLASH,
|
||||
title = CloudFunc.getTitle(cleanPath),
|
||||
oldURL = window.location.pathname;
|
||||
|
||||
/* Отображаем красивые пути */
|
||||
var lSLASH = '/',
|
||||
title = CloudFunc.getTitle(lCleanPath),
|
||||
lFSPath = decodeURI(pPath),
|
||||
lNOJSPath = Util.removeStr( lFSPath, '?json' ),
|
||||
lCleanPath = Util.removeStrOneTime( lNOJSPath, CloudFunc.FS ) || lSLASH,
|
||||
|
||||
lOldURL = window.location.pathname;
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
if (lCleanPath === lSLASH)
|
||||
lNOJSPath = lSLASH;
|
||||
if (cleanPath === SLASH)
|
||||
noJSONPath = SLASH;
|
||||
|
||||
Util.log ('reading dir: "' + lCleanPath + '";');
|
||||
Util.log ('reading dir: "' + cleanPath + '";');
|
||||
|
||||
if (!pOptions.nohistory)
|
||||
DOM.setHistory(lNOJSPath, null, lNOJSPath);
|
||||
if (!options.nohistory)
|
||||
DOM.setHistory(noJSONPath, null, noJSONPath);
|
||||
|
||||
DOM.setTitle(title);
|
||||
|
||||
|
|
@ -357,40 +357,35 @@ var Util, DOM, CloudFunc;
|
|||
* если стоит поле обязательной перезагрузки -
|
||||
* перезагружаемся
|
||||
*/
|
||||
var lRet = pOptions.refresh;
|
||||
if (!lRet) {
|
||||
var lJSON = Storage.get(lCleanPath);
|
||||
if (!ret) {
|
||||
str = Storage.get(cleanPath);
|
||||
|
||||
if (lJSON) {
|
||||
lJSON = Util.parseJSON(lJSON);
|
||||
CloudCmd.createFileTable(lJSON);
|
||||
if (!str)
|
||||
ret = true;
|
||||
else {
|
||||
json = Util.parseJSON(str);
|
||||
CloudCmd.createFileTable(json);
|
||||
}
|
||||
else
|
||||
lRet = true;
|
||||
}
|
||||
|
||||
if (lRet)
|
||||
if (ret)
|
||||
DOM.getCurrentFileContent({
|
||||
url : lFSPath,
|
||||
|
||||
dataType: 'json',
|
||||
|
||||
error : function() {
|
||||
DOM.setHistory(lOldURL, null, lOldURL);
|
||||
url : fsPath,
|
||||
dataType : 'json',
|
||||
error : function() {
|
||||
DOM.setHistory(oldURL, null, oldURL);
|
||||
},
|
||||
|
||||
success : function(pData) {
|
||||
CloudCmd.createFileTable(pData);
|
||||
success : function(data) {
|
||||
var str = Util.stringifyJSON(data),
|
||||
MAX_SIZE = 50000;
|
||||
|
||||
/* переводим таблицу файлов в строку, для *
|
||||
* сохранения в localStorage */
|
||||
var lJSON_s = Util.stringifyJSON(pData);
|
||||
Util.log(lJSON_s.length);
|
||||
CloudCmd.createFileTable(data);
|
||||
Util.log(str.length);
|
||||
|
||||
/* если размер данных не очень бошьой *
|
||||
* сохраняем их в кэше */
|
||||
if (lJSON_s.length < 50000 )
|
||||
Storage.set(lCleanPath, lJSON_s);
|
||||
if (str.length < MAX_SIZE)
|
||||
Storage.set(cleanPath, str);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue