Merge pull request #127 from tiwilliam/fix-cancel-transition

ui: Fix parentKey transitions to root on cancel
pull/129/head
Armon Dadgar 2014-05-05 13:45:38 -07:00
commit 226b0520a1
1 changed files with 11 additions and 6 deletions

View File

@ -66,6 +66,13 @@ App.DcController = Ember.Controller.extend({
}) })
KvBaseController = Ember.ObjectController.extend({ KvBaseController = Ember.ObjectController.extend({
getParentKeyRoute: function() {
if (this.get('isRoot')) {
return this.get('rootKey');
}
return this.get("parentKey");
},
transitionToNearestParent: function(parent) { transitionToNearestParent: function(parent) {
var controller = this; var controller = this;
var rootKey = controller.get('rootKey'); var rootKey = controller.get('rootKey');
@ -136,12 +143,11 @@ App.KvShowController.reopen({
this.set('isLoading', true); this.set('isLoading', true);
var controller = this; var controller = this;
var key = controller.get("model"); var grandParent = controller.get('grandParentKey');
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/" + controller.get('parentKey') + '?recurse'),
type: 'DELETE' type: 'DELETE'
}).then(function(response) { }).then(function(response) {
controller.transitionToNearestParent(grandParent); controller.transitionToNearestParent(grandParent);
@ -184,7 +190,7 @@ App.KvEditController = KvBaseController.extend({
cancelEdit: function() { cancelEdit: function() {
this.set('isLoading', true); this.set('isLoading', true);
this.transitionToRoute('kv.show', this.get("model").get('parentKey')); this.transitionToRoute('kv.show', this.getParentKeyRoute());
this.set('isLoading', false); this.set('isLoading', false);
}, },
@ -194,8 +200,7 @@ App.KvEditController = KvBaseController.extend({
var controller = this; var controller = this;
var dc = controller.get('dc').get('datacenter'); var dc = controller.get('dc').get('datacenter');
var key = controller.get("model"); var key = controller.get("model");
var isRoot = controller.get('isRoot'); var parent = controller.getParentKeyRoute();
var parent = isRoot ? controller.get('rootKey') : key.get('parentKey');
// Delete the key // Delete the key
Ember.$.ajax({ Ember.$.ajax({