From 5089be1af042cee9f98ebb000b7a08641a9ee7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Mon, 5 May 2014 02:12:24 +0200 Subject: [PATCH] Add delete folder button to web UI --- ui/index.html | 3 ++- ui/javascripts/app/controllers.js | 29 ++++++++++++++++++++++------- ui/javascripts/app/routes.js | 7 ++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ui/index.html b/ui/index.html index f0cd715175..97d5b00f57 100644 --- a/ui/index.html +++ b/ui/index.html @@ -151,6 +151,7 @@ {{/if}} + @@ -211,7 +212,7 @@ - + diff --git a/ui/javascripts/app/controllers.js b/ui/javascripts/app/controllers.js index 29b4910e2c..8b04a55e64 100644 --- a/ui/javascripts/app/controllers.js +++ b/ui/javascripts/app/controllers.js @@ -109,7 +109,26 @@ App.KvShowController.reopen({ // Render the error message on the form if the request failed controller.set('errorMessage', 'Received error while processing: ' + response.statusText) }); + }, + deleteFolder: function() { + this.set('isLoading', true); + + var key = this.get("model"); + var controller = this; + + // Delete the folder + Ember.$.ajax({ + url: ("/v1/kv/" + key.get('parentKey') + '?recurse'), + type: 'DELETE' + }).then(function(response) { + // Tranisiton back up a level + controller.transitionToRoute('kv.show', key.get('grandParentKey')); + controller.set('isLoading', false); + }).fail(function(response) { + // Render the error message on the form if the request failed + controller.set('errorMessage', 'Received error while processing: ' + response.statusText) + }) } } }); @@ -151,13 +170,10 @@ App.KvEditController = Ember.Controller.extend({ deleteKey: function() { this.set('isLoading', true); + + var dc = this.get('dc').get('datacenter'); var key = this.get("model"); var controller = this; - var dc = this.get('dc').get('datacenter'); - - // Get the parent for the transition back up a level - // after the delete - var parent = key.get('parentKey'); // Delete the key Ember.$.ajax({ @@ -165,13 +181,12 @@ App.KvEditController = Ember.Controller.extend({ type: 'DELETE' }).then(function(response) { // Tranisiton back up a level - controller.transitionToRoute('kv.show', parent); + controller.transitionToRoute('kv.show', key.get('parentKey')); controller.set('isLoading', false); }).fail(function(response) { // Render the error message on the form if the request failed controller.set('errorMessage', 'Received error while processing: ' + response.statusText) }) - } } diff --git a/ui/javascripts/app/routes.js b/ui/javascripts/app/routes.js index a96a3d31eb..f31e04d980 100644 --- a/ui/javascripts/app/routes.js +++ b/ui/javascripts/app/routes.js @@ -19,7 +19,11 @@ App.BaseRoute = Ember.Route.extend({ grandParentKey = parts.join("/") + "/"; } - return {grandParent: grandParentKey, parent: parentKey} + return { + parent: parentKey, + grandParent: grandParentKey, + isRoot: parentKey === '/' + } }, removeDuplicateKeys: function(keys, matcher) { @@ -131,6 +135,7 @@ App.KvShowRoute = App.BaseRoute.extend({ controller.set('content', models.keys); controller.set('parentKey', parentKeys.parent); controller.set('grandParentKey', parentKeys.grandParent); + controller.set('isRoot', parentKeys.isRoot); controller.set('newKey', App.Key.create()); } });