From 9fb3f124955cbca0847125f2e3c9aafc1da10df8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 15 Mar 2013 11:24:25 -0400 Subject: [PATCH] moved out set current file from cloudfunc to client.js --- ChangeLog | 2 ++ lib/client.js | 64 ++++++++++++++++++++++++++---------------------- lib/cloudfunc.js | 22 +++++------------ package.json | 2 +- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d23be7a..aeba3f82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,8 @@ would be on top. * Fixed bug with saving json to localStorage, it's always writed root directory. +* Moved out set current file from cloudfunc to client.js + 2012.03.01, Version 0.1.9 diff --git a/lib/client.js b/lib/client.js index c7780a8a..f82e23cf 100644 --- a/lib/client.js +++ b/lib/client.js @@ -7,7 +7,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; (function(Util, DOM){ 'use strict'; - var Config, Modules; + var Config, Modules, FileTemplate; /* Клиентский обьект, содержащий функциональную часть*/ var CloudCmd = { @@ -44,6 +44,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; LIBDIR : '/lib/', LIBDIRCLIENT : '/lib/client/', JSONDIR : '/json/', + HTMLDIR : '/html/', /* height of Cloud Commander * seting up in init() */ @@ -378,26 +379,30 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; CloudCmd.KeyBinding(); } - CloudCmd.getConfig = function(pCallBack){ - Util.ifExec(Config, pCallBack, function(pCallBack){ - DOM.ajax({ - url : CloudCmd.JSONDIR + 'config.json', - success : function(pConfig){ - Config = pConfig; - Util.exec(pCallBack, pConfig); - } - }); - }); - }; - CloudCmd.getModules = function(pCallBack){ - Util.ifExec(Modules, pCallBack, function(pCallBack){ - DOM.ajax({ - url : CloudCmd.JSONDIR + 'modules.json', - success : Util.retExec(pCallBack) + function getSystemFile(pGlobal, pURL){ + + function lGetSysFile(pCallBack){ + Util.ifExec(pGlobal, pCallBack, function(pCallBack){ + DOM.ajax({ + url : pURL, + success : function(pLocal){ + pGlobal = pLocal; + Util.exec(pCallBack, pLocal); + } + }); }); - }); - }; + } + + return lGetSysFile; + } + + + + CloudCmd.getConfig = getSystemFile(Config, CloudCmd.JSONDIR + 'config.json'); + CloudCmd.getModules = getSystemFile(Modules, CloudCmd.JSONDIR + 'modules.json'); + CloudCmd.getFileTemplate = getSystemFile(FileTemplate, CloudCmd.HTMLDIR + 'file.html'); + CloudCmd.execFromModule = function(pModuleName, pFuncName, pParams){ var lObject = CloudCmd[pModuleName]; @@ -579,7 +584,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; if (lJSON){ /* переводим из текста в JSON */ lJSON = Util.parseJSON(lJSON); - CloudCmd._createFileTable(lPanel, lJSON, true); + CloudCmd._createFileTable(lPanel, lJSON); CloudCmd._changeLinks(lPanel); } else @@ -595,7 +600,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; }, success : function(pData){ - CloudCmd._createFileTable(lPanel, pData, true); + CloudCmd._createFileTable(lPanel, pData); CloudCmd._changeLinks(lPanel); /* переводим таблицу файлов в строку, для * @@ -616,7 +621,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; * @param pEleme - родительский элемент * @param pJSON - данные о файлах */ - CloudCmd._createFileTable = function(pElem, pJSON, pSetCurrent){ + CloudCmd._createFileTable = function(pElem, pJSON){ var lElem = DOM.getById(pElem), /* getting current element if was refresh */ lPath = DOM.getByClass('path', lElem), @@ -635,11 +640,12 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; lElem.removeChild(lElem.lastChild); /* заполняем панель новыми элементами */ - lElem.innerHTML = CloudFunc.buildFromJSON(pJSON, pSetCurrent); + lElem.innerHTML = CloudFunc.buildFromJSON(pJSON); + var lFound; /* searching current file */ if(lWasRefresh_b){ - var lFound, n = lElem.childNodes.length; + var n = lElem.childNodes.length; for(i = 2; i < n ; i++){ var lVarCurrent = lElem.childNodes[i], lVarName = DOM.getCurrentName(lVarCurrent); @@ -651,12 +657,12 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander; break; } } - - if(!lFound) /* .. */ - lCurrent = lElem.childNodes[2]; - - DOM.setCurrentFile(lCurrent); } + if(!lFound) /* .. */ + lCurrent = lElem.childNodes[2]; + + DOM.setCurrentFile(lCurrent); + }; /** diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index 2eb11f28..e796f89d 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -106,7 +106,7 @@ var CloudFunc, exports, Util; } /* оставляем последние 3 символа*/ - pPerm_s = pPerm_s.length> 5 ?pPerm_s.substr(3) : pPerm_s.substr(2); + pPerm_s = pPerm_s.length > 5 ? pPerm_s.substr(3) : pPerm_s.substr(2); /* Рекомендации гугла советуют вместо string[3] * использовать string.charAt(3) @@ -165,6 +165,7 @@ var CloudFunc, exports, Util; /* добавляем 2 цыфры до 5 */ return '00' + lOwner + lGroup + lAll; }; + /** Функция получает короткие размеры * конвертируя байт в килобайты, мегабойты, * гигайбайты и терабайты @@ -294,7 +295,7 @@ var CloudFunc, exports, Util; * [{path:'путь',size:'dir'}, * {name:'имя',size:'размер',mode:'права доступа'}] */ - CloudFunc.buildFromJSON = function(pJSON, pSetCurrent) + CloudFunc.buildFromJSON = function(pJSON) { var files = pJSON, /* сохраняем путь каталога в котором мы сейчас находимся*/ @@ -311,7 +312,6 @@ var CloudFunc, exports, Util; * если он есть */ lRefreshPath = CloudFunc.removeLastSlash(lPath), - lFS_s = CloudFunc.FS, lFileTable = '
  • '+ @@ -321,7 +321,7 @@ var CloudFunc, exports, Util; '' + '' + - '' + + '' + '' + '' + '' + lHtmlPath + '' + @@ -345,8 +345,7 @@ var CloudFunc, exports, Util; if(lDotDot === '') lDotDot = '/'; - lLink = lFS_s + lDotDot; - + lLink = FS + lDotDot; /* Сохраняем путь к каталогу верхнего уровня*/ lFileTable += '
  • ' + @@ -373,7 +372,7 @@ var CloudFunc, exports, Util; '">'; lFileTable += ''; lFileTable += '' + - '', - '
  • '); - return lFileTable; }; })(); \ No newline at end of file diff --git a/package.json b/package.json index d0b8679f..d3fbed19 100644 --- a/package.json +++ b/package.json @@ -23,4 +23,4 @@ "node": ">=0.4.x" }, "main": "cloudcmd.js" -} \ No newline at end of file +}