 Events = require './events'
 StackEditor = require './views'
 StackWizardModal = require './views/wizard/stackwizardmodal'
-
 
 { markAsLoaded, log } = require './helpers'
 

    return  unless @templates[templateId]

    delete @templates[templateId]
    @openEditor templateId, reset = yes


  fetchStackTemplate: (templateId, callback) ->

    @stackEditor.on Events.InitializeRequested, @bound 'initializeStack'


  openEditor: (templateId, options = {}, callback = kd.noop) ->

    { reset = no } = options

    unless templateId
      do @openStackWizard
      return callback { message: 'No template provided' }

    @fetchStackTemplate templateId, (err, template) =>

      if err
        showErrorNotification err
        return callback err

      @stackEditor.setTemplateData template, reset
      callback null

    markAsLoaded templateId

