mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
refactored
This commit is contained in:
parent
4e12e8b4a4
commit
9ed41613ff
1 changed files with 63 additions and 34 deletions
|
|
@ -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'});
|
||||
})
|
||||
}
|
||||
}
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue