diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index 2d0a2be..75e1163 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -348,12 +348,54 @@ app.controller('websiteCtrl', [ vm.Sites.remove = function (r, opts) { + var pkg = Auth.oauth3.pkg('www@daplie.com'); + + getPathToDelete(r, opts); + + if (!window.confirm("Delete files for this site?")) { + return; + } + + vm.checkForOthers(r); + // return pkg.remove({ + // hostname: r.domain + // , domain: r.domain + // , tld: r.tld + // , sld: r.sld + // //, sub: vm.record.sub + // // , path: opts.path || r.path + // , confirm: opts.confirm || r.confirm + // }).then(function (result) { + // window.alert(JSON.stringify(result)); + // }); + debugger; function getPathToDelete(r, pathName) { vm.autoPopulateWebPath; if (vm.autoPopulateWebPath === undefined && opts !== undefined) { r.path = '/' + opts; } else { r.path = vm.autoPopulateWebPath + pathName; + + // Delete the directory if there is no other files or directories inside + // if (vm.currentDirectoryFilesCount === 1 && vm.currentDirectoryDirectoriesCount === 0) { + // debugger; + // r.path = vm.autoPopulateWebPath; + // return pkg.remove({ + // hostname: r.domain + // , domain: r.domain + // , tld: r.tld + // , sld: r.sld + // //, sub: vm.record.sub + // , path: opts.path || r.path + // , confirm: opts.confirm || r.confirm + // }).then(function (result) { + // // console.log('result', result); + // }); + // } else { + // console.log('do it'); + // } + + } if (opts === undefined) { opts = {}; @@ -363,29 +405,35 @@ app.controller('websiteCtrl', [ opts.confirm = true; } } - getPathToDelete(r, opts); - - if (!window.confirm("Delete files for this site?")) { - return; - } - var pkg = Auth.oauth3.pkg('www@daplie.com'); - - return pkg.remove({ - hostname: r.domain - , domain: r.domain - , tld: r.tld - , sld: r.sld - //, sub: vm.record.sub - , path: opts.path || r.path - , confirm: opts.confirm || r.confirm - }).then(function (result) { - console.log('the result', result); - window.alert(JSON.stringify(result)); - }); }; + vm.checkForOthers = function (r) { + vm.isOtherDirectories = []; + vm.isOtherFiles = []; + vm.currentDirectoryDirectoriesCount = 0; + vm.currentDirectoryFilesCount = 0; + var pkg = Auth.oauth3.pkg('www@daplie.com'); + return pkg.contents({ + hostname: r.domain, + domain: r.domain, + tld: r.tld, + sld: r.sld, + //, sub: r.sub, + path: vm.autoPopulateWebPath + }).then(function (result) { + result.data.forEach(function(file){ + if (file.file) { + vm.isOtherFiles.push(file); + vm.currentDirectoryFilesCount = vm.isOtherFiles.length; + } else if (file.directory) { + vm.isOtherDirectories.push(file); + vm.currentDirectoryDirectoriesCount = vm.isOtherDirectories.length; + } + }); + }); + } - vm.breadcrumbs = ['Root']; + vm.breadcrumbs = ['root']; vm.breadcrumbsPath = ['/']; vm.breadcrumbPathClicked = false; vm.webPathAutofill = '/'; @@ -407,8 +455,8 @@ app.controller('websiteCtrl', [ vm.autoPopulateWebPath = vm.autoPopulateWebPath.join(''); } if (vm.breadcrumbPathClicked) { - if (path === 'Root') { - vm.breadcrumbs = ['Root']; + if (path === 'root') { + vm.breadcrumbs = ['root']; vm.breadcrumbsPath = ['/']; vm.breadcrumbPathClicked = false; vm.autoPopulateWebPath = "/"; diff --git a/templates/widgets/filetree.html b/templates/widgets/filetree.html index 4cbcbaa..7444728 100644 --- a/templates/widgets/filetree.html +++ b/templates/widgets/filetree.html @@ -13,6 +13,7 @@ +