Add delete folder button to web UI

This commit is contained in:
William Tisäter 2014-05-05 02:12:24 +02:00 committed by William Tisäter
parent 6440fc77b6
commit 5089be1af0
3 changed files with 30 additions and 9 deletions

View File

@ -151,6 +151,7 @@
{{/if}}
<button {{ action "createKey"}} {{bind-attr disabled=newKey.isInvalid }} {{ bind-attr class=":btn newKey.isValid:btn-success:btn-default" }}>Create</button>
<button {{ action "deleteFolder"}} {{bind-attr disabled=isRoot }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete folder</button>
</form>
</div>
</div>
@ -211,7 +212,7 @@
</div>
<button {{ action "updateKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn isLoading:btn-warning:btn-success" }}>Update</button>
<button {{ action "cancelEdit"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn isLoading:btn-warning:btn-default" }}>Cancel</button>
<button {{ action "deleteKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete</button>
<button {{ action "deleteKey"}} {{bind-attr disabled=isLoading }} {{ bind-attr class=":btn :pull-right isLoading:btn-warning:btn-danger" }}>Delete key</button>
</form>
</div>
</div>

View File

@ -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)
})
}
}

View File

@ -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());
}
});