From 636bac5f94c281939be1ae4350cd6b340375e953 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 9 Apr 2013 09:44:00 -0400 Subject: [PATCH] added ability to delete file when f8 key pressed --- ChangeLog | 2 ++ README.md | 2 +- lib/client/dom.js | 3 ++- lib/client/keyBinding.js | 5 ++++ lib/server/main.js | 2 +- lib/server/rest.js | 53 ++++++++++++++++++++++------------------ 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index f52a5847..e1ba610c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,8 @@ is pressed and current file is directory. * Added function getSelectedNames. +* Added ability to delete file when f8 key pressed. + 2012.03.01, Version 0.1.9 diff --git a/README.md b/README.md index b99c43f7..eba34413 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ There is a short list: - **Page Down** - down on one page - **Home** - to begin of list - **End** - to end of list -- **Delete** - remove current file +- **F8, Delete** - remove current file - **Shift + Delete** - remove without prompt - **Insert** - select current file - **F2** - rename current file diff --git a/lib/client/dom.js b/lib/client/dom.js index b4225dfb..7b52708d 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -38,10 +38,11 @@ var CloudCommander, Util, DOM = {}, CloudFunc; /* Обьект содержит функции для работы с CloudCmd API */ RESTfull = function(){ - this.delete = function(pUrl, pCallBack){ + this.delete = function(pUrl, pData, pCallBack){ sendRequest({ method : 'DELETE', url : CloudFunc.FS + pUrl, + data : pData, callback : pCallBack }); }; diff --git a/lib/client/keyBinding.js b/lib/client/keyBinding.js index 362ee2d4..01d26993 100644 --- a/lib/client/keyBinding.js +++ b/lib/client/keyBinding.js @@ -41,6 +41,7 @@ var CloudCommander, Util, DOM; F5 : 116, F6 : 117, F7 : 118, + F8 : 119, F10 : 121, TRA : 192 /* Typewritten Reverse Apostrophe (`) */ @@ -171,6 +172,10 @@ var CloudCommander, Util, DOM; DOM.promptNewDir(); break; + case KEY.F8: + DOM.promptDeleteCurrent(lCurrent); + break; + case KEY.F: DOM.promptDeleteCurrent(lCurrent); break; diff --git a/lib/server/main.js b/lib/server/main.js index 52570055..8f3ac835 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -103,7 +103,7 @@ exports.appcache = srvrequire('appcache'), exports.cache = srvrequire('cache').Cache, exports.cloudfunc = librequire('cloudfunc'), - exports.dir = srvrequire('dir'); + exports.dir = srvrequire('dir'), exports.rest = srvrequire('rest').api, exports.update = srvrequire('update'), exports.ischanged = srvrequire('ischanged'); diff --git a/lib/server/rest.js b/lib/server/rest.js index 940403be..e05d1500 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -109,26 +109,25 @@ else main.sendError(pParams, pErr); }); - else - fs.stat(p.name, function(pError, pStat){ - if(!pError) - if( pStat.isDirectory() ) - main.commander.getDirContent(pParams.name, function(pError, pData){ - if(!pError){ - pParams.request.url += '.json'; - pParams.data = Util.stringifyJSON(pData); - main.sendResponse(pParams); - } - else - main.sendError(pParams, pError); - }); - else - main.sendFile(pParams); + else + fs.stat(p.name, function(pError, pStat){ + if(!pError) + if( pStat.isDirectory() ) + main.commander.getDirContent(pParams.name, function(pError, pData){ + if(!pError){ + pParams.request.url += '.json'; + pParams.data = Util.stringifyJSON(pData); + main.sendResponse(pParams); + } + else + main.sendError(pParams, pError); + }); else - main.sendError(pParams, pError); - - }); - + main.sendFile(pParams); + else + main.sendError(pParams, pError); + + }); break; case 'PUT': @@ -157,12 +156,18 @@ case 'DELETE': if(lQuery === 'dir') fs.rmdir(p.name, function(pError){ - if(!pError) - main.sendResponse(pParams, 'Folder ' + p.name + ' deleted.'); - else - main.sendError(pParams, pError); + if(!pError) + main.sendResponse(pParams, 'Folder ' + p.name + ' deleted.'); + else + main.sendError(pParams, pError); + }); + else if(lQuery === 'files'){ + getBody(p.request, function(pBody){ + var lFiles = Util.parseJSON(pBody); + for(var i = 0, n = lFiles.length; i < n; i ++) + Util.log(lFiles[i]); }); - else + }else fs.unlink(p.name, function(pError){ if(!pError) main.sendResponse(pParams, 'File ' + p.name + ' delete.');