define('app/views/key', ['app/views/page', 'app/models/machine'],
    /**
     *  Single Key View
     *
     *  @returns Class
     */
    function (PageView, Machine) {
        return App.KeyView = PageView.extend({

            /**
             *  Properties
             */

            key: null,
            machines: [],


            /**
             *
             *  Initialization
             *
             */

            load: function () {

                // Add event listeners
                Mist.keysController.on('onKeyListChange', this, 'updateView');
                Mist.keysController.on('onKeyDisassociate', this, 'updateMachines');
                Mist.backendsController.on('onMachineListChange', this, 'updateMachines');

                this.updateView();

            }.on('didInsertElement'),


            unload: function () {

                // Remove event listeners
                Mist.keysController.off('onKeyListChange', this, 'updateView');
                Mist.keysController.off('onKeyDisassociate', this, 'updateMachines');
                Mist.backendsController.off('onMachineListChange', this, 'updateMachines');

            }.on('willDestroyElement'),


            /**
             *
             *  Methods
             *
             */

            updateView: function () {

                this.updateModel();

                // In case keys haven't been loaded yet, a
                // dummy model will be passed to the view so
                // that things won't brake. This model doesn't
                // have an "id" attribute.
                if (Mist.keysController.keyExists(this.key.id)) {
                    this.updateMachines();
                    this.showPublicKey();
                }
            },


            updateModel: function () {

                // Check if user has requested a specific key
                // through the address bar and retrieve it
                var key = Mist.keysController.getRequestedKey();
                if (key)
                    this.get('controller').set('model', key);

                // Get a reference of key model
                this.set('key', this.get('controller').get('model'));
            },


            updateMachines: function () {

                // Construct an array of machine models
                // that are associated with this key
                var newMachines = [];
                this.key.machines.forEach(function (machine) {
                    var newMachine = Mist.backendsController.getMachine(machine[1], machine[0]);
                    if (!newMachine) {
                        var backend = Mist.backendsController.getBackend(machine[0]);
                        newMachine = Machine.create({
                            id: machine[1],
                            name: machine[1],
                            state: backend ? 'terminated' : 'unknown',
                            backend: backend ? backend : machine[0],
                            isGhost: true,
                        });
                    }
                    newMachines.push(newMachine);
                });

                // These machines will be rendered
                // under the "machines" collapsible
                this.set('machines', newMachines);
            },


            renderMachines: function () {
                Ember.run.next(function () {
                    if ($('#single-key-machines').collapsible)
                        $('#single-key-machines').collapsible()
                                                 .trigger('create');
                });
            },


            showPublicKey: function () {
                Mist.keysController.getPublicKey(this.key.id, function (success, keyPublic) {
                    if (success)
                        $('#public-key').val(keyPublic);
                });
            },


            /**
             *
             *  Actions
             *
             */

            actions: {

                displayClicked: function () {
                    Mist.keysController.getPrivateKey(this.key.id, function (success, keyPrivate) {
                        if (success) {
                            Mist.dialogController.open({
                                type: DIALOG_TYPES.BACK,
                                head: 'Private Key',
                                body: [
                                    {
                                        command: keyPrivate
                                    }
                                ],
                            });
                        }
                    });
                },


                renameClicked: function () {
                    var key = this.key;
                    Mist.keyEditController.open(key.id, function (success) {
                        if (success) {
                            Mist.Router.router.transitionTo('key', key);
                        }
                    });
                },


                deleteClicked: function () {

                    var keyId = this.key.id;

                    Mist.confirmationController.set('title', 'Delete key');
                    Mist.confirmationController.set('text', 'Are you sure you want to delete "' + keyId + '" ?');
                    Mist.confirmationController.set('callback', function () {
                        Mist.keysController.deleteKey(keyId, function (success) {

                            // Wait for the confirmation popup to close
                            // before navigating to #/keys. Else, the
                            // rest of the popups will never open
                            Ember.run.later(function () {
                                if (success)
                                    Mist.Router.router.transitionTo('keys');
                            }, 300);

                        });
                    });
                    Mist.confirmationController.show();
                }
            },


            /**
             *
             *  Observers
             *
             */

            modelObserver: function () {
                Ember.run.once(this, 'updateView');
            }.observes('controller.model'),


            modelMachinesObserver: function () {
                Ember.run.once(this, 'updateMachines');
            }.observes('key.machines'),


            viewMachinesObserver: function () {
                Ember.run.once(this, 'renderMachines');
            }.observes('machines')
        });
    }
);

@@ -5142,43 +5142,112 @@
 ist.
-confirmationController.set('title',
+dialogController.open(%7B%0A                        type: DIALOG_TYPES.YES_NO,%0A                        head:
  'De
@@ -5255,19 +5255,19 @@
 ete key'
-);%0A
+,%0A 
         
@@ -5282,47 +5282,91 @@
     
-Mist.confirmationController.set('text',
+   body: %5B%0A                            %7B%0A                                paragraph:
  'Ar
@@ -5403,25 +5403,13 @@
 %22' +
- keyId + '%22 ?');%0A
+%0A    
     
@@ -5428,149 +5428,49 @@
     
-Mist.confirmationController.set('callback', function () %7B%0A                        Mist.keysController.deleteKey(keyId, function (success) %7B%0A%0A
+            keyId + '%22 ?'%0A               
     
@@ -5470,32 +5470,34 @@
                 
+%7D%0A
                /
@@ -5499,246 +5499,218 @@
     
-// Wait for the confirmation popup to close%0A                            // before navigating to #/keys. Else, the%0A                            // rest of the popups will never open%0A                            Ember.run.later(function () %7B%0A
+         %5D,%0A                        callback: function (didConfirm) %7B%0A                            if (didConfirm) %7B%0A                                Mist.keysController.deleteKey(keyId, function (success) %7B%0A    
     
@@ -5742,32 +5742,36 @@
    if (success)%0A
+    
                 
@@ -5863,18 +5863,20 @@
     
-%7D, 300);%0A%0A
+    %7D);%0A    
     
@@ -5888,35 +5888,36 @@
                %7D
-);%0A
+%0A   
                 
@@ -5912,35 +5912,34 @@
                 
+ 
 %7D
-);
 %0A               
@@ -5947,41 +5947,9 @@
     
-Mist.confirmationController.show(
+%7D
 );%0A 

Remove confirmation controller from key view