diff --git a/ChangeLog b/ChangeLog index c048782e..b4ed3607 100644 --- a/ChangeLog +++ b/ChangeLog @@ -184,6 +184,8 @@ generation of json of directory listing. * Added to html templating. +* Added ability to rename files. + 2012.12.12, Version 0.1.8 diff --git a/lib/client/dom.js b/lib/client/dom.js index 4bfa5639..fc748496 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1348,18 +1348,19 @@ var CloudCommander, Util, pCurrentFile = null; var lCurrent = pCurrentFile || DOM.getCurrentFile(), - lName = DOM.getCurrentName(lCurrent), - lNewName = prompt("Rename", lName) || lName; - - if( !Util.strCmp(lName, lNewName) ){ + lFrom = DOM.getCurrentName(lCurrent), + lTo = prompt("Rename", lFrom) || lFrom, + lDirPath = DOM.getCurrentDirPath(); + if( !Util.strCmp(lFrom, lTo) ){ var lFiles = { - from : lName, - to : lNewName + from : lDirPath + lFrom, + to : lDirPath + lTo }; + DOM.Images.showLoad(); + CloudCommander.getConfig(function(pConfig){ - var lUrl = DOM.getCurrentDirPath(); - lUrl = pConfig && pConfig.api_url + '/mv'; + var lUrl = pConfig && pConfig.api_url + '/mv'; DOM.ajax({ method : 'put', @@ -1368,7 +1369,7 @@ var CloudCommander, Util, error : DOM.Images.showError, success : function(pData){ DOM.Images.hideLoad(); - DOM.setCurrentName(lName, lCurrent); + DOM.setCurrentName(lTo, lCurrent); Util.log(pData); } }); diff --git a/lib/server/rest.js b/lib/server/rest.js index 8a52f4f3..30102fcd 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -212,7 +212,7 @@ if(lRet){ var p = pParams, lCmd = p.command, - lFiles = Util.stringifyJSON(p.body); + lFiles = Util.parseJSON(p.body); console.log(p.body); switch(lCmd){ case 'auth': @@ -234,14 +234,15 @@ }); break; case 'mv': - if(lFiles) - Util.log(lFiles); + if( Util.checkObjTrue(lFiles, ['from', 'to']) ) fs.rename(lFiles.from, lFiles.to, function(pError){ if(!pError) main.sendResponse(pParams); else main.sendError(pParams, pError); }); + else + main.sendError(pParams, p.data); break; case 'cp':