feature(dom) moveCurrent -> moveFiles

This commit is contained in:
coderaiser 2014-04-17 07:01:46 -04:00
parent b534b945b6
commit ed5a359327
4 changed files with 66 additions and 85 deletions

View file

@ -699,7 +699,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
RESTful.unzip(fileFrom, CloudCmd.refresh);
};
/**
* prompt and delete current file or selected files
*
@ -1708,63 +1707,27 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}
};
/**
* move current file
*
* @currentFile
/*
* process files (copy or move)
* @param operation
*/
this.moveCurrent = function(current) {
var name, from, to, cmp, files,
path = CurrentInfo.dirPath,
RESTful = DOM.RESTful;
path = CloudFunc.rmLastSlash(path);
if (!Cmd.isCurrentFile(current))
current = Cmd.getCurrentFile();
name = Cmd.getCurrentName(current),
from = Cmd.getCurrentPath(),
to = Cmd.getNotCurrentDirPath() + name;
to = Dialog.prompt('Rename/Move file "' + name + '"', to);
cmp = !Util.strCmp(from, to);
if (to && cmp) {
files = {
from : from,
to : to
};
RESTful.mv(files, function() {
var dotDot,
panel = DOM.getPanel(true),
id = panel.id,
name = '..(' + id + ')';
dotDot = DOM.getById(name);
DOM.deleteCurrent(current);
DOM.setCurrentFile(dotDot);
CloudCmd.refresh(dotDot, panel);
DOM.Storage.remove(path);
});
}
};
/**
* copy current file
*
* @param current
*/
this.copyFiles = function() {
var n, name, from, to, files, cmp, msg,
function processFiles(operation) {
var n, name, from, to, files, cmp, msg, opFunc,
path = CurrentInfo.dirPath,
RESTful = DOM.RESTful,
names = Cmd.getSelectedNames(),
length = names && names.length;
if (operation.copy) {
opFunc = RESTful.cp;
msg = 'Copy ';
} else if (operation.move) {
opFunc = RESTful.mv;
msg = 'Rename/Move ';
}
if (!length) {
name = DOM.getCurrentName();
names.push(name);
@ -1774,8 +1737,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
n = names.length;
msg = 'Copy ';
if (n > 1)
msg += n + ' file(s)';
else
@ -1785,26 +1746,48 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
from = path;
to = DOM.getNotCurrentDirPath();
to = Dialog.prompt(msg, to);
cmp = Util.strCmp(from, to);
if (!cmp) {
files = {
from : from,
names : names,
to : to
};
if (name === '..') {
Dialog.alert('No files selected!');
} else {
to = Dialog.prompt(msg, to);
RESTful.cp(files, function() {
var panel = DOM.getPanel(true),
id = panel.id,
dotDot = DOM.getById( '..(' + id + ')');
cmp = Util.strCmp(from, to);
if (!cmp) {
files = {
from : from,
names : names,
to : to
};
DOM.setCurrentFile(dotDot);
CloudCmd.refresh(dotDot, panel);
DOM.Storage.remove(path);
});
opFunc(files, function() {
var panel = DOM.getPanel(),
panelPassive = DOM.getPanel(true),
id = panelPassive.id,
dotDot = DOM.getById( '..(' + id + ')');
if (operation.move)
CloudCmd.refresh(dotDot, panel);
DOM.setCurrentFile(dotDot);
CloudCmd.refresh(dotDot, panelPassive);
DOM.Storage.remove(path);
});
}
}
}
this.copyFiles = function() {
processFiles({
copy: true
});
};
this.moveFiles = function() {
processFiles({
move: true
});
};
/**

View file

@ -252,7 +252,7 @@ var CloudCmd, Util, DOM;
break;
case Key.F6:
DOM.moveCurrent(current);
DOM.moveFiles();
DOM.preventDefault(event);
break;

View file

@ -67,7 +67,7 @@ var Util, DOM, CloudCmd;
'f2' : DOM.renameCurrent,
'f5' : DOM.copyFiles,
'f6' : DOM.moveCurrent,
'f6' : DOM.moveFiles,
'f7' : DOM.promptNewDir,
'f8' : DOM.promptDelete
},

View file

@ -288,8 +288,8 @@
else {
files.namesAll = Util.slice(files.names);
copyFiles(files,
function(name, callback) {
fse.remove(name, function(error) {
function(path, callback) {
fse.delete(path, function(error) {
if (error)
sendError(params, error);
else
@ -297,13 +297,11 @@
});
},
function(error, length) {
fse.remove(name, function(error) {
if (error)
sendError(params, error);
else if (!length)
sendMsg(params, 'move', files.namesAll);
});
function(error) {
if (error)
sendError(params, error);
else
sendMsg(params, 'move', files.namesAll);
});
}
@ -314,10 +312,10 @@
sendError(params, p.data);
else {
files.namesAll = Util.slice(files.names);
copyFiles(files, null, function(error, isLast) {
copyFiles(files, null, function(error) {
if (error)
sendError(params, error);
else if (isLast)
else
sendMsg(params, 'copy', files.namesAll);
});
}
@ -408,10 +406,10 @@
copy = function() {
var isLast = !names.length,
name = names.shift(),
process = Util.retExec(callbackProcess, name);
process = Util.retExec(callbackProcess, from + name);
if (isLast)
Util.exec(callback, null, isLast);
Util.exec(callback, null);
else
fse.copy(from + name, to + name, function(error) {
if (error)