mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 01:47:35 +00:00
refactor(dom) processFiles
This commit is contained in:
parent
3da7e63da2
commit
7ed1afa775
1 changed files with 53 additions and 41 deletions
|
|
@ -1573,55 +1573,43 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
* @param operation
|
||||
*/
|
||||
function processFiles(operation, data) {
|
||||
var n, name, files, msg, opFunc,
|
||||
var name, files, opFunc,
|
||||
shouldAsk,
|
||||
RESTful = DOM.RESTful,
|
||||
|
||||
from = '',
|
||||
to = '',
|
||||
|
||||
names = [],
|
||||
|
||||
length = 0;
|
||||
names = [];
|
||||
|
||||
if (operation.copy) {
|
||||
if (!data) {
|
||||
data = {};
|
||||
shouldAsk = true;
|
||||
}
|
||||
|
||||
switch(operation) {
|
||||
case 'copy':
|
||||
opFunc = RESTful.cp;
|
||||
msg = 'Copy ';
|
||||
} else if (operation.move) {
|
||||
break;
|
||||
case 'move':
|
||||
opFunc = RESTful.mv;
|
||||
msg = 'Rename/Move ';
|
||||
break;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
from = data.from;
|
||||
to = data.to;
|
||||
names = data.names;
|
||||
} else {
|
||||
from = CurrentInfo.dirPath;
|
||||
to = DOM.getNotCurrentDirPath();
|
||||
|
||||
names = Cmd.getSelectedNames();
|
||||
length = names && names.length;
|
||||
|
||||
if (!length) {
|
||||
name = DOM.getCurrentName();
|
||||
names = [name];
|
||||
}
|
||||
|
||||
name = names[0];
|
||||
|
||||
if (length > 1)
|
||||
msg += n + ' file(s)';
|
||||
else
|
||||
msg += '"' + name + '"';
|
||||
|
||||
msg += ' to';
|
||||
}
|
||||
from = data.from || CurrentInfo.dirPath;
|
||||
to = data.to || DOM.getNotCurrentDirPath();
|
||||
names = data.names || Cmd.getSelectedNames();
|
||||
|
||||
if (!names.length)
|
||||
names.push(DOM.getCurrentName());
|
||||
|
||||
name = names[0];
|
||||
|
||||
if (name === '..') {
|
||||
Dialog.alert('No files selected!');
|
||||
} else {
|
||||
if (!data)
|
||||
to = Dialog.prompt(msg, to);
|
||||
if (shouldAsk)
|
||||
to = processMessage(to, operation, names);
|
||||
|
||||
if (from !== to && to) {
|
||||
Images.show.load('top');
|
||||
|
|
@ -1656,16 +1644,40 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
}
|
||||
}
|
||||
|
||||
function processMessage(to, operation, names) {
|
||||
var ret,
|
||||
msg = '',
|
||||
n = names.length,
|
||||
name = names[0];
|
||||
|
||||
switch(operation) {
|
||||
case 'copy':
|
||||
msg = 'Copy ';
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
msg = 'Rename/Move ';
|
||||
break;
|
||||
}
|
||||
|
||||
if (names.length > 1)
|
||||
msg += n + ' file(s)';
|
||||
else
|
||||
msg += '"' + name + '"';
|
||||
|
||||
msg += ' to';
|
||||
|
||||
ret = Dialog.prompt(msg, to);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
this.copyFiles = function(data) {
|
||||
processFiles({
|
||||
copy: true
|
||||
}, data);
|
||||
processFiles('copy', data);
|
||||
};
|
||||
|
||||
this.moveFiles = function(data) {
|
||||
processFiles({
|
||||
move: true
|
||||
}, data);
|
||||
processFiles('move', data);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue