refactor(client) initModules

This commit is contained in:
coderaiser 2014-01-31 08:17:22 -05:00
parent 1a87898577
commit e38e88ac7d

View file

@ -11,6 +11,7 @@ var Util, DOM, CloudFunc;
function CloudCmdProto(Util, DOM, CloudFunc) {
var Key, Config, Modules, Extensions,
FileTemplate, PathTemplate, LinkTemplate, Listeners,
Images = DOM.Images,
Info = DOM.CurrentInfo,
CloudCmd = this,
Storage = DOM.Storage;
@ -45,7 +46,7 @@ var Util, DOM, CloudFunc;
lLink += '?json';
if (lLink || lCurrentLink.target !== '_blank') {
DOM.Images.showLoad(pNeedRefresh ? {top:true} : null);
Images.showLoad(pNeedRefresh ? {top:true} : null);
/* загружаем содержимое каталога */
CloudCmd.ajaxLoad(lLink, { refresh: pNeedRefresh });
@ -187,45 +188,48 @@ var Util, DOM, CloudFunc;
});
CloudCmd.getModules(function(pModules) {
pModules = pModules || [];
pModules = pModules || [];
var i, n, lStorage = 'storage',
lShowLoadFunc = Util.retFunc( DOM.Images.showLoad, {top:true} ),
var i, n, module, storageObj, mod, name, path,
STORAGE = 'storage',
showLoadFunc = Images.showLoad.bind(null, {
top:true
}),
lDoBefore = {
'edit' : lShowLoadFunc,
'view' : lShowLoadFunc,
'menu' : lShowLoadFunc
doBefore = {
'edit' : showLoadFunc,
'view' : showLoadFunc,
'menu' : showLoadFunc
},
lLoad = function(pName, pPath, pDoBefore) {
load = function(name, path, func) {
loadModule({
path : pPath,
name : pName,
dobefore : pDoBefore
name : name,
path : path,
dobefore : func
});
};
for (i = 0, n = pModules.length; i < n ; i++) {
var lModule = pModules[i];
module = pModules[i];
if ( Util.isString(lModule) )
lLoad(null, lModule, lDoBefore[lModule]);
if (Util.isString(module))
load(null, module, doBefore[module]);
}
var lStorageObj = Util.findObjByNameInArr( pModules, lStorage ),
lMod = Util.getNamesFromObjArray( lStorageObj );
storageObj = Util.findObjByNameInArr(pModules, STORAGE),
mod = Util.getNamesFromObjArray(storageObj);
for (i = 0, n = lMod.length; i < n; i++) {
var lName = lMod[i],
lPath = lStorage + '/_' + lName.toLowerCase();
name = mod[i],
path = STORAGE + '/_' + lName.toLowerCase();
lLoad(lName, lPath);
load(lName, lPath);
}
Util.exec(pCallBack);
});
}