               KD.singleton("vmController").createNewVM (err) ->
                 KD.showError err
 
-  getDomainCreateForm: ->
+  getDomainCreateForm: (domainsContainer)->
     domainCreateForm = new DomainCreateForm
-    @domainsContainer.on "itemRemoved", domainCreateForm.bound "updateDomains"
-    domainCreateForm.on "DomainSaved", @domainsContainer.bound "loadItems"
+    domainsContainer.on "itemRemoved", domainCreateForm.bound "updateDomains"
+    domainCreateForm.on "DomainSaved", domainsContainer.bound "loadItems"
     return domainCreateForm
 
   getVmSelectionView: ->

        <h1>Environments</h1>
      """

    # Main scene for DIA
    @addSubView @scene = new EnvironmentScene

    @paymentController = KD.getSingleton("paymentController")
    @paymentController.fetchActiveSubscription tags: "vm", (err, subscription) =>
      return console.error err  if err
      if not subscription or "nosync" in subscription.tags
        @addSubView @freePlanView = new KDView
          cssClass : 'bottom-warning'
          partial  : """
            You are on a free developer plan, see your usage or <a href="/Pricing">upgrade</a>.
          """

    @paymentController.on "SubscriptionCompleted", =>
      @freePlanView?.hide()

    # Rules Container
    rulesContainer = new EnvironmentRuleContainer
    @scene.addContainer rulesContainer
    rulesContainer.on 'PlusButtonClicked', ->
      new KDNotificationView title: "Adding more rules will be available soon."
    # rulesContainer.on "itemRemoved", @domainCreateForm.bound "updateDomains"

    # Domains Container
    @domainsContainer = new EnvironmentDomainContainer
    @scene.addContainer @domainsContainer
    @domainsContainer.on "itemRemoved", @scene.bound 'updateConnections'

    # VMs / Machines Container
    @machinesContainer = new EnvironmentMachineContainer
    @scene.addContainer @machinesContainer

    @_containers = [@machinesContainer, @domainsContainer]

    # Rules Container
    extrasContainer = new EnvironmentExtraContainer
    @scene.addContainer extrasContainer
    extrasContainer.on 'PlusButtonClicked', ->
      new KDNotificationView title: "Adding more resource will be available soon."

    @_containers = @_containers.concat [rulesContainer, extrasContainer]

    for container in @_containers
      container.on 'DataLoaded', @scene.bound 'updateConnections'

    @refreshContainers()

    KD.getSingleton("vmController").on 'VMListChanged', @bound 'refreshContainers'

    # Plus button on @domainsContainer opens up the domainCreateModal
    @domainsContainer.on 'PlusButtonClicked', =>
      return unless KD.isLoggedIn()
        new KDNotificationView title: "You need to login to add a new domain."

      return if @machinesContainer.diaCount() is 0
        new KDNotificationView
          title: "You need to have at least one VM to manage domains."

      domainCreateForm = @getDomainCreateForm()

      new KDModalView
        title          : "Add Domain"

        vmc = KD.getSingleton("vmController")
        vmc.emit 'VMListChanged'

    # Plus button on machinesContainer uses the vmController
    machinesContainer.on 'PlusButtonClicked', =>
      return unless KD.isLoggedIn()
        new KDNotificationView
          title: "You need to login to create a new machine."
