From ed5a359327adf03032c78df5b11a5d49a248ef1e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 17 Apr 2014 07:01:46 -0400 Subject: [PATCH] feature(dom) moveCurrent -> moveFiles --- lib/client/dom.js | 123 +++++++++++++++++----------------------- lib/client/key.js | 2 +- lib/client/listeners.js | 2 +- lib/server/rest.js | 24 ++++---- 4 files changed, 66 insertions(+), 85 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 262a326d..a7b043f8 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -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 + }); }; /** diff --git a/lib/client/key.js b/lib/client/key.js index 21b83b93..a808b05a 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -252,7 +252,7 @@ var CloudCmd, Util, DOM; break; case Key.F6: - DOM.moveCurrent(current); + DOM.moveFiles(); DOM.preventDefault(event); break; diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 4368f651..5faeadb6 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -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 }, diff --git a/lib/server/rest.js b/lib/server/rest.js index 5dc9b826..57b0ea96 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -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)