From fd8791af9e2df783e4a0cb9a85dba0fb69c7bcf9 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 13 Mar 2014 07:24:20 -0400 Subject: [PATCH] feature(dom) add sendDelete --- lib/client/dom.js | 75 +++++++++++++++++++++++++++-------------- lib/client/key.js | 14 +++----- lib/client/listeners.js | 2 +- lib/client/menu.js | 2 +- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 4c6a62e2..22b4e7d0 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -594,13 +594,12 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; /** - * delete currentfile, prompt before it + * prompt and delete current file or selected files * * @currentFile */ - this.promptDeleteSelected = function(current) { - var ret, type, isDir, path, query, msg, - RESTful = DOM.RESTful, + this.promptDelete = function(currentFile) { + var ret, type, isDir, msg, current, name = '', msgAsk = 'Do you really want to delete the ', msgSel = 'selected ', @@ -608,12 +607,10 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; names = Cmd.getSelectedNames(files), i, n = names && names.length; - if (!Cmd.isCurrentFile(current)) + if (!Cmd.isCurrentFile(currentFile)) current = DOM.getCurrentFile(); - if (n > 1) { - path = Cmd.getCurrentDirPath(); - + if (n) { for (i = 0; i < 5 && i < n; i++) name += '\n' + names[i]; @@ -621,15 +618,12 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; name += '\n...'; msg = msgAsk + msgSel + n + ' files/directoris?\n' + name ; - query = '?files'; } else { - path = Cmd.getCurrentPath(current); isDir = Cmd.isCurrentIsDir(current); - if (isDir) { - query = '?dir'; + if (isDir) type ='directory'; - } else + else type = 'file'; type += ' '; @@ -644,22 +638,53 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; Dialog.alert('No files selected!'); if (ret) - RESTful.delete(path + query, names, function() { - var Storage = DOM.Storage, - dirPath = CurrentInfo.dirPath, - dir = CloudFunc.rmLastSlash(dirPath); - - if (n > 1) - DOM.deleteSelected(files); - else - DOM.deleteCurrent(current); - - Storage.remove(dir); - }); + DOM.sendDelete(files); return ret; }; + /** + * delete current or selected files + * + * @files + */ + this.sendDelete = function(files) { + var n, names, path, + query = '', + RESTful = DOM.RESTful, + current = CurrentInfo.element, + isDir = DOM.CurrentInfo.isDir; + + if (!files) + files = Cmd.getSelectedFiles(); + + if (isDir) + query = '?dir'; + + names = DOM.getSelectedNames(files), + n = names && names.length; + + if (n) { + path = Cmd.getCurrentDirPath(); + query = '?files'; + } else { + path = Cmd.getCurrentPath(current); + } + + RESTful.delete(path + query, names, function() { + var Storage = DOM.Storage, + dirPath = CurrentInfo.dirPath, + dir = CloudFunc.rmLastSlash(dirPath); + + if (n > 1) + DOM.deleteSelected(files); + else + DOM.deleteCurrent(current); + + Storage.remove(dir); + }); + }; + /** * get current direcotory name diff --git a/lib/client/key.js b/lib/client/key.js index 07192bd3..fd2368b5 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -201,16 +201,10 @@ var CloudCmd, Util, DOM; break; case Key.DELETE: - if (shift) { - if (Info.isDir) - path += '?dir'; - - DOM.RESTful.delete(path, function() { - DOM.deleteCurrent(current); - }); - } + if (shift) + DOM.sendDelete(); else - DOM.promptDeleteSelected(current); + DOM.promptDelete(current); break; case Key.ASTERISK: @@ -269,7 +263,7 @@ var CloudCmd, Util, DOM; break; case Key.F8: - DOM.promptDeleteSelected(current); + DOM.promptDelete(current); break; case Key.F9: diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 0b0ef1f8..795b3813 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -60,7 +60,7 @@ var Util, DOM, CloudCmd; 'f5' : DOM.copyCurrent, 'f6' : DOM.moveCurrent, 'f7' : DOM.promptNewDir, - 'f8' : DOM.promptDeleteSelected + 'f8' : DOM.promptDelete }, func = clickFuncs[id]; diff --git a/lib/client/menu.js b/lib/client/menu.js index 9aafe42c..be37d632 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -187,7 +187,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; 'Rename' : function() { setTimeout(DOM.renameCurrent, 100); }, - 'Delete' : DOM.promptDeleteSelected, + 'Delete' : DOM.promptDelete, '(Un)Select All': DOM.toggleAllSelectedFiles, 'Zip file' : DOM.zipFile };