From 217b53218ca3e04d81a1b9a07ece46f0de07d865 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 16 Apr 2014 10:28:55 -0400 Subject: [PATCH] feature(rest) cp: add ability to copy couple files --- lib/client/dom.js | 36 ++++++++++++++++++++++++++++-------- lib/server/rest.js | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 54a66f9e..03dd415b 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1748,22 +1748,42 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; * @param current */ this.copyCurrent = function(current) { - var name, from, to, files, cmp, - path = DOM.CurrentInfo.dirPath, - RESTful = DOM.RESTful; + var n, name, from, to, files, cmp, msg, + path = CurrentInfo.dirPath, + RESTful = DOM.RESTful, + names = Cmd.getSelectedNames(), + length = names && names.length; if (!Cmd.isCurrentFile(current)) current = Cmd.getCurrentFile(); - name = Cmd.getCurrentName(current), - from = Cmd.getCurrentPath(), - to = Cmd.getNotCurrentDirPath() + name; - to = Dialog.prompt('Copy file "' + name + '" to', to); - cmp = Util.strCmp(from, to); + if (!length) { + name = Cmd.getCurrentName(current); + names.push(name); + } else if (length === 1) { + name = names[0]; + } + + n = names.length; + + msg = 'Copy '; + + if (n > 1) + msg += n + ' file(s)'; + else + msg += '"' + name + '"'; + + msg += ' to'; + + from = path; + to = DOM.getNotCurrentDirPath(); + to = Dialog.prompt(msg, to); + cmp = Util.strCmp(from, to); if (!cmp) { files = { from : from, + names : names, to : to }; diff --git a/lib/server/rest.js b/lib/server/rest.js index 0c014a85..f413292b 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -242,7 +242,7 @@ * @param pParams {command, method, body, requrest, response} */ function onPUT(pParams) { - var name, json, config, + var name, json, config, names, to, from, copyFiles, ret = main.checkParams(pParams, ['body']); if (ret) { @@ -276,15 +276,37 @@ break; case 'cp': - if (!Util.checkObjTrue(lFiles, ['from', 'to'])) + if (!Util.checkObjTrue(lFiles, ['from', 'names', 'to'])) sendError(pParams, p.data); - else - fse.copy(lFiles.from, lFiles.to, function(error) { - if (error) - sendError(pParams, error); - else - sendMsg(pParams, 'copy', lFiles.to); - }); + else { + lFiles.namesAll = Util.slice(lFiles.names); + + copyFiles = function(files) { + var names = files.names, + namesAll = files.namesAll, + name = names.shift(); + from = files.from, + to = files.to, + + fse.copy(from + name, to + name, function(error) { + var length = names.length; + + if (error) + sendError(pParams, error); + else if (!length) + sendMsg(pParams, 'copy', namesAll); + else + copyFiles({ + from : from, + to : to, + names : names, + namesAll: namesAll + }); + }); + }; + + copyFiles(lFiles); + } break; case 'zip':