added ability to delete files

This commit is contained in:
coderaiser 2013-04-11 10:43:47 -04:00
parent 55a8d7c354
commit e0b4eb7b42
4 changed files with 52 additions and 35 deletions

View file

@ -484,9 +484,10 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander;
lUrl = CloudCmd.HOST,
lLoadDirOnce = CloudCmd.loadDir();
CloudCmd.refresh = function(){
CloudCmd.refresh = function(pCurrent){
var lNEEDREFRESH = true,
lPath = DOM.getCurrentDirPath(),
lPanel = pCurrent && pCurrent.parentElement,
lPath = DOM.getCurrentDirPath(lPanel),
lLink = CloudFunc.FS + lPath,
lNotSlashlLink = CloudFunc.removeLastSlash(lLink),
lLoad = CloudCmd.loadDir(lNotSlashlLink, lNEEDREFRESH);

View file

@ -488,15 +488,14 @@ var CloudCommander, Util, DOM = {}, CloudFunc;
if(lCurrent)
lUrl = DOM.getCurrentPath(lCurrent);
else
else{
lUrl = DOM.getCurrentDirPath();
lCurrent = lFiles[0];
}
if(lCurrent || lSelected)
DOM.RESTfull.delete(lUrl, lSelected, function(){
if(n > 1)
DOM.deleteSelected(lFiles);
else
DOM.deleteCurrent(lCurrent);
CloudCommander.refresh(lCurrent);
}, lQuery);
return lCurrent;

View file

@ -164,31 +164,48 @@
else if(lQuery === 'files'){
getBody(p.request, function(pBody){
var lFiles = Util.parseJSON(pBody),
lDir = p.name;
n = lFiles.length,
lDir = p.name,
log = Util.retExec(Util.log),
lAssync = 0;
function stat(pParams){
var lRet = Util.checkParams(pParams, 'params');
console.log(n);
function stat(pStat){
console.log(pStat);
var lRet = Util.checkObjTrue(pStat, 'params') &&
Util.checkObjTrue(pStat.params, 'name');
if(lRet){
var p = pParams,
d = p.params;
var p = pStat,
d = p.params;
if(p.data.isDirectory()){
}
else if(p.data.isFile()){
++lAssync;
if( p.error ){
main.sendError(pParams, p.error);
Util.log(p.error);
}
else
if(p.data.isDirectory())
fs.rmdir(d.name, log);
else if(p.data.isFile())
fs.unlink(d.name, log);
if(lAssync === n && !p.error)
main.sendResponse(pParams, 'Files deleted: ' + pBody);
}
}
for(var i = 0, n = lFiles.length; i < n; i ++){
Util.log(lDir + lFiles[i]);
//fs.stat(lDir + lFiles[i], Util.call())
for(var i = 0; i < n; i ++){
var lName = lDir + lFiles[i];
Util.log(lName);
fs.stat(lName, Util.call(stat, {
name: lName
}));
}
main.sendResponse(pParams, pBody);
});
}else
fs.unlink(p.name, function(pError){
@ -280,6 +297,7 @@
main.sendError(pParams, lError);
});
break;
case 'mv':
if( Util.checkObjTrue(lFiles, ['from', 'to']) )
fs.rename(lFiles.from, lFiles.to, function(pError){

View file

@ -114,21 +114,20 @@ Util = exports || {};
* @param pTrueArr
*/
Util.checkObjTrue = function(pObj, pTrueArr){
var lRet,
var lRet, lTrueArr,
i, n;
if( pObj ){
lRet = Util.isArray(pTrueArr);
if(lRet){
n = pTrueArr.length;
for(i = 0; i < n; i++){
var lProp = pTrueArr[i];
lRet = pObj[lProp];
if( !lRet){
Util.logError(lProp + ' not true!');
Util.log(pObj);
break;
}
lTrueArr = Util.isArray(pTrueArr) ? pTrueArr : [pTrueArr];
n = lTrueArr.length;
for(i = 0; i < n; i++){
var lProp = lTrueArr[i];
lRet = pObj[lProp];
if( !lRet){
Util.logError(lProp + ' not true!');
Util.log(pObj);
break;
}
}
}