-kd = require 'kd'
-KDButtonView = kd.ButtonView
-SidebarSearchModal = require './sidebarsearchmodal'
-ModalMachineItem = require './modalmachineitem'
+kd                        = require 'kd'
+checkFlag                 = require 'app/util/checkFlag'
+KDModalView               = kd.ModalView
+KDButtonView              = kd.ButtonView
+ModalMachineItem          = require './modalmachineitem'
 {handleNewMachineRequest} = require '../../providers/computehelpers'
-checkFlag = require 'app/util/checkFlag'
 
-module.exports = class MoreVMsModal extends SidebarSearchModal
+
+module.exports = class MoreVMsModal extends KDModalView
 
   constructor: (options = {}, data = []) ->
 
-    hasContainer             = options.container?
-
-    options.cssClass         = kd.utils.curry 'more-modal more-vms', options.cssClass
-    options.width            = 462
-    options.title          or= 'Your VMs'
-    options.disableSearch    = yes
-    options.itemClass      or= ModalMachineItem
-    options.bindModalDestroy = no
-    options.appendToDomBody  = !hasContainer
-    options.draggable        = no
-    options.overlay          = !hasContainer
+    options.cssClass = kd.utils.curry 'more-modal more-vms', options.cssClass
+    options.width    = 462
+    options.title    = 'Your VMs'
+    options.overlay  = yes
 
     super options, data
 
-    if container = @getOption 'container'
-      kd.utils.defer => container.addSubView this
+    @createAddKodingVMButton()
+    @createAddYourVMButton()
+    @listMachines()
 
-  viewAppended: ->
+
+  createAddKodingVMButton: ->
 
     @addButton = new KDButtonView
       title    : "Create a Koding VM"


    @addSubView @addButton, '.kdmodal-content'

    if checkFlag 'super-admin'
      
      @setClass 'managed'
      @addManagedButton = new KDButtonView
        title    : "Add Your own VM"


      @addSubView @addManagedButton, '.kdmodal-content'

  listMachines: ->

    for machine in @getData()
      view = new ModalMachineItem {}, machine.data
      view.once 'ModalItemSelected', @bound 'destroy'
      @addSubView view
