       iconClass : "editor"
       callback  : @bound "createConfigEditor"
 
-  createConfigEditor: ->
-    new EditorModal
-      editor              :
-        title             : "Stack Config Editor <span>(experimental)</span>"
-        content           : @getOptions().stack?.meta?.config or ""
-        saveMessage       : "Stack config saved."
-        saveFailedMessage : "Couldn't save your config"
-        saveCallback      : @bound "saveConfig"
-
-  saveConfig: (config, modal) ->
-    {stack} = @getOptions()
-
-    stack.updateConfig config, (err, res) =>
-      eventName = if err then "SaveFailed" else "Saved"
-      modal.emit eventName
+
+  updateView:(dataUpdated = no)->
+    @scene.updateConnections()  if dataUpdated
+
+    @setHeight @getProperHeight()  if @getHeight() > 50
+
+    @scene.highlightLines()
+    @scene.updateScene()


    return if asYaml then jsyaml.dump dump else dump

  updateView:(dataUpdated = no)->
    @scene.updateConnections()  if dataUpdated

    if @getHeight() > 50
      @setHeight @getProperHeight()

    @scene.highlightLines()
    @scene.updateScene()

  getProperHeight:->
    (Math.max.apply null, \
      (box.diaCount() for box in @scene.containers)) * 45 + 170

  getMenuItems: ->
    items =

    super options, data

    @bindTransitionEnd()
    @stack = @getData()


  viewAppended:->

    @createHeaderElements()

    # Main scene for DIA
    @addSubView @scene = new EnvironmentScene {}, @stack

    # Rules Container
    @rules = new EnvironmentRuleContainer {}, @stack
    @scene.addContainer @rules
    # @rules.on "itemAdded", @lazyBound "updateView", yes

    # Domains Container
    @domains = new EnvironmentDomainContainer {}, @stack
    @scene.addContainer @domains
    # @domains.on 'itemAdded', @lazyBound 'updateView', yes

    # VMs / Machines Container
    @machines = new EnvironmentMachineContainer {}, @stack
    @scene.addContainer @machines
    # @machies.on 'itemAdded', @lazyBound 'updateView', yes

    # Extras Container
    @extras = new EnvironmentExtraContainer {}, @stack
    @scene.addContainer @extras
    # @extras.on 'itemAdded', @lazyBound 'updateView', yes

    @loadContainers()
    @emit "ready", this

  loadContainers: (data)->

    # Add rules
    if @stack.rules?
      @rules.removeAllItems()
      @rules.addItem rule        for rule in @stack.rules

    # Add domains
    if @stack.domains?
      @domains.removeAllItems()
      @domains.addDomain domain  for domain in @stack.domains

    # Add machines
    if @stack.machines?
      @machines.removeAllItems()
      @machines.addItem machine  for machine in @stack.machines

    # Add extras
    if @stack.extras?
      @extras.removeAllItems()
      @extras.addItem extra      for extra in @stack.extras

    @setHeight @getProperHeight()

    KD.utils.wait 300, =>
      @_inProgress = no
      @updateView yes


  deleteStack: ->

    stackTitle = @stack.title or ""
    stackSlug  = "confirm"

    modal      = new VmDangerModalView
      name     : stackTitle
      action   : "DELETE MY STACK"
      title    : "Delete your #{stackTitle} stack"
      width    : 650
      content  : """
          <div class='modalformline'>
            <p><strong>CAUTION! </strong>This will destroy your #{stackTitle} stack including</strong>
            all VMs and domains inside this stack. You will also lose all your data in your VMs. This action <strong>CANNOT</strong> be undone.</p><br><p>
            Please enter <strong>#{stackSlug}</strong> into the field below to continue: </p>
          </div>
        """
      callback : =>

        modal.destroy()
        @stack.delete (err, res) =>
          return KD.showError err  if err
          @destroy()

    , stackSlug


  ### Stack Config Helpers ###

  ###*
   * creates a new EditorModal
   * @return {EditorModal} stack config editor
  ###
  createConfigEditor: ->
    new EditorModal
      editor              :
        title             : "Stack Config Editor <span>(experimental)</span>"
        content           : @stack.config or ""
        saveMessage       : "Stack config saved."
        saveFailedMessage : "Couldn't save your config"
        saveCallback      : =>
          @stack.modify { config }, (err, res) =>
            eventName = if err then "SaveFailed" else "Saved"
            modal.emit eventName


  ### Stack Dump Helpers ###

  ###*
   * helper to dump stack information
   * inside of a {new EditorModal}
  ###
  dumpStack:->

    stackRecipe  = @getStackDump yes

    editorModal  = new EditorModal
      removeOnOverlayClick : yes
      cssClass   : "recipe-editor"
