Transition to nearest parent on key delete
This commit is contained in:
parent
a730174f0c
commit
f4c4b5ace8
|
@ -65,8 +65,29 @@ App.DcController = Ember.Controller.extend({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
KvHelpController = Ember.ObjectController.extend({
|
||||||
|
transitionToNearestParent: function(parent) {
|
||||||
|
var controller = this;
|
||||||
|
var rootKey = controller.get('rootKey');
|
||||||
|
var dc = controller.get('dc').get('datacenter');
|
||||||
|
|
||||||
|
Ember.$.ajax({
|
||||||
|
url: ('/v1/kv/' + parent + '?keys&c=' + dc),
|
||||||
|
type: 'GET'
|
||||||
|
}).then(function(data) {
|
||||||
|
controller.transitionToRoute('kv.show', parent);
|
||||||
|
}).fail(function(response) {
|
||||||
|
if (response.status === 404) {
|
||||||
|
controller.transitionToRoute('kv.show', rootKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.set('isLoading', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add mixins
|
// Add mixins
|
||||||
App.KvShowController = Ember.ObjectController.extend(Ember.Validations.Mixin);
|
App.KvShowController = KvHelpController.extend(Ember.Validations.Mixin);
|
||||||
|
|
||||||
App.KvShowController.reopen({
|
App.KvShowController.reopen({
|
||||||
needs: ["dc"],
|
needs: ["dc"],
|
||||||
|
@ -79,11 +100,11 @@ App.KvShowController.reopen({
|
||||||
createKey: function() {
|
createKey: function() {
|
||||||
this.set('isLoading', true);
|
this.set('isLoading', true);
|
||||||
|
|
||||||
var newKey = this.get('newKey');
|
|
||||||
var parentKey = this.get('parentKey');
|
|
||||||
var grandParentKey = this.get('grandParentKey');
|
|
||||||
var controller = this;
|
var controller = this;
|
||||||
var dc = this.get('dc').get('datacenter');
|
var newKey = controller.get('newKey');
|
||||||
|
var parentKey = controller.get('parentKey');
|
||||||
|
var grandParentKey = controller.get('grandParentKey');
|
||||||
|
var dc = controller.get('dc').get('datacenter');
|
||||||
|
|
||||||
// If we don't have a previous model to base
|
// If we don't have a previous model to base
|
||||||
// on our parent, or we're not at the root level,
|
// on our parent, or we're not at the root level,
|
||||||
|
@ -114,26 +135,27 @@ App.KvShowController.reopen({
|
||||||
deleteFolder: function() {
|
deleteFolder: function() {
|
||||||
this.set('isLoading', true);
|
this.set('isLoading', true);
|
||||||
|
|
||||||
var key = this.get("model");
|
|
||||||
var controller = this;
|
var controller = this;
|
||||||
|
var key = controller.get("model");
|
||||||
|
var grandParent = key.get('grandParentKey');
|
||||||
|
|
||||||
// Delete the folder
|
// Delete the folder
|
||||||
Ember.$.ajax({
|
Ember.$.ajax({
|
||||||
url: ("/v1/kv/" + key.get('parentKey') + '?recurse'),
|
url: ("/v1/kv/" + key.get('parentKey') + '?recurse'),
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
// Tranisiton back up a level
|
controller.transitionToNearestParent(grandParent);
|
||||||
controller.transitionToRoute('kv.show', key.get('grandParentKey'));
|
|
||||||
controller.set('isLoading', false);
|
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
// Render the error message on the form if the request failed
|
// Render the error message on the form if the request failed
|
||||||
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
controller.set('isLoading', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
App.KvEditController = Ember.Controller.extend({
|
App.KvEditController = KvHelpController.extend({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
needs: ["dc"],
|
needs: ["dc"],
|
||||||
dc: Ember.computed.alias("controllers.dc"),
|
dc: Ember.computed.alias("controllers.dc"),
|
||||||
|
@ -181,10 +203,8 @@ App.KvEditController = Ember.Controller.extend({
|
||||||
Ember.$.ajax({
|
Ember.$.ajax({
|
||||||
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
url: ("/v1/kv/" + key.get('Key') + '?dc=' + dc),
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
}).then(function(response) {
|
}).then(function(data) {
|
||||||
// Tranisiton back up a level
|
controller.transitionToNearestParent(parent);
|
||||||
controller.transitionToRoute('kv.show', parent);
|
|
||||||
controller.set('isLoading', false);
|
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
// Render the error message on the form if the request failed
|
// Render the error message on the form if the request failed
|
||||||
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
controller.set('errorMessage', 'Received error while processing: ' + response.statusText)
|
||||||
|
|
|
@ -137,6 +137,7 @@ App.KvShowRoute = App.BaseRoute.extend({
|
||||||
controller.set('grandParentKey', parentKeys.grandParent);
|
controller.set('grandParentKey', parentKeys.grandParent);
|
||||||
controller.set('isRoot', parentKeys.isRoot);
|
controller.set('isRoot', parentKeys.isRoot);
|
||||||
controller.set('newKey', App.Key.create());
|
controller.set('newKey', App.Key.create());
|
||||||
|
controller.set('rootKey', this.rootKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -170,9 +171,9 @@ App.KvEditRoute = App.BaseRoute.extend({
|
||||||
controller.set('content', models.key);
|
controller.set('content', models.key);
|
||||||
controller.set('parentKey', parentKeys.parent);
|
controller.set('parentKey', parentKeys.parent);
|
||||||
controller.set('grandParentKey', parentKeys.grandParent);
|
controller.set('grandParentKey', parentKeys.grandParent);
|
||||||
|
controller.set('isRoot', parentKeys.isRoot);
|
||||||
controller.set('siblings', models.keys);
|
controller.set('siblings', models.keys);
|
||||||
controller.set('rootKey', this.rootKey);
|
controller.set('rootKey', this.rootKey);
|
||||||
controller.set('isRoot', parentKeys.isRoot);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue