From e36df63a0ba742a464bcb8df36a000c3f1d21622 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 24 Apr 2015 05:22:47 -0400 Subject: [PATCH] feature(dom) processFiles: add ask before overwriting --- lib/client/dom.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 47bd6e9c..f34697e2 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1574,7 +1574,10 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; */ function processFiles(operation, data) { var name, files, opFunc, + panel, shouldAsk, + sameName, + ok, RESTful = DOM.RESTful, from = '', @@ -1582,11 +1585,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; names = []; - if (!data) { - data = {}; - shouldAsk = true; - } - switch(operation) { case 'copy': opFunc = RESTful.cp; @@ -1596,22 +1594,41 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; break; } - from = data.from || CurrentInfo.dirPath; - to = data.to || DOM.getNotCurrentDirPath(); - names = data.names || Cmd.getSelectedNames(); + if (data) { + from = data.from; + to = data.to; + names = data.names; + panel = CurrentInfo.panel; + } else { + from = CurrentInfo.dirPath; + to = DOM.getNotCurrentDirPath(); + names = Cmd.getSelectedNames(); + data = {}; + shouldAsk = true; + panel = CurrentInfo.panelPassive; + } if (!names.length) names.push(DOM.getCurrentName()); name = names[0]; + sameName = !!DOM.getCurrentByName(name, panel); + if (name === '..') { Dialog.alert('No files selected!'); } else { if (shouldAsk) to = processMessage(to, operation, names); - if (from !== to && to) { + ok = from !== to && to; + + if (ok && (shouldAsk && sameName)) + ok = Dialog.confirm(Util.render('"{{ name }}" already exist. Overwrite?', { + name: name + })); + + if (ok) { Images.show.load('top'); files = {