refactored

This commit is contained in:
coderaiser 2012-12-23 06:26:34 -05:00
parent 4e12e8b4a4
commit 9ed41613ff

View file

@ -104,6 +104,34 @@ var CloudCommander, Util, DOM, $;
return lRet;
}
/**
* get all menu items
* pItems = [{pName, pFunc}]
*/
function getAllItems(pItems){
var lRet = {};
if( Util.isArray(pItems) ){
var lName,
lFunc,
i, n = pItems.length;
for(i = 0; i < n; i++){
var lItem = pItems[i];
if(lItem){
lName = lItem.name;
for(var lProp in lItem){
lName = lProp;
lFunc = lItem[lProp];
}
lRet[lName] = getItem(lName, lFunc);
}
}
}
return lRet;
}
/**
* function return configureation for menu
*/
@ -120,42 +148,43 @@ var CloudCommander, Util, DOM, $;
},
// define the elements of the menu
items: {
'View' : getItem( 'View', Util.retExec(showEditor, true) ),
'Edit' : getItem( 'Edit', Util.retExec(showEditor) ),
'Delete' : getItem( 'Delete', Util.retExec(DOM.promptRemoveCurrent) ),
'Upload to' : getItem( 'Upload to',
getUploadToItem( ['GitHub', 'GDrive', 'DropBox'] ) ),
'Download' : getItem( 'Download', function(key, opt){
DOM.Images.showLoad();
var lPath = DOM.getCurrentPath(),
lId = DOM.getIdBySrc(lPath);
Util.log('downloading file ' + lPath +'...');
lPath = lPath + '?download';
if(!DOM.getById(lId)){
var lDownload = DOM.anyload({
name : 'iframe',
async : false,
className : 'hidden',
src : lPath,
func : Util.retFunc(DOM.Images.hideLoad)
});
items: getAllItems([
{ 'View' : Util.retExec(showEditor, true) },
{ 'Edit' : Util.retExec(showEditor) },
{ 'Delete' : Util.retExec(DOM.promptRemoveCurrent) },
{ 'Upload to' : getUploadToItem( ['GitHub', 'GDrive', 'DropBox'] ) },
{
'Download' : function(key, opt){
DOM.Images.showLoad();
DOM.Images.hideLoad();
setTimeout(function() {
document.body.removeChild(lDownload);
}, 10000);
var lPath = DOM.getCurrentPath(),
lId = DOM.getIdBySrc(lPath);
Util.log('downloading file ' + lPath +'...');
lPath = lPath + '?download';
if(!DOM.getById(lId)){
var lDownload = DOM.anyload({
name : 'iframe',
async : false,
className : 'hidden',
src : lPath,
func : Util.retFunc(DOM.Images.hideLoad)
});
DOM.Images.hideLoad();
setTimeout(function() {
document.body.removeChild(lDownload);
}, 10000);
}
else
DOM.Images.showError({
responseText: 'Error: You trying to' +
'download same file to often'});
}
else
DOM.Images.showError({
responseText: 'Error: You trying to' +
'download same file to often'});
})
}
}
])
};
}