diff --git a/lib/client/dom.js b/lib/client/dom.js index e4022a32..2e466a73 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -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); }; /**