   build: (editor, name, values) ->
     snippet = {}
 
-    snippet['snippet_id'] = -> $(this.wrapper.$).find('div.cke_widget_element').data('snippet')
     snippet['configured'] = false
-    snippet['template'] = values.template
+    snippet['template'] = "<div></div>" # This gets replaced when we click on the Submit Dialog button
     snippet['dialog_url'] = values.dialog_url
     snippet['dialog'] = name if values.dialog_url
     snippet['requiredContent'] = "div(#{name})"

SaveAll = {
  replaceSnippets: (html) ->
    obj = $('<div>' + html + '</div>')
    obj.find('div[data-snippet]').each -> $(this).replaceWith("[#{$(this).data('snippet')}]")
    obj.html()

  exec: (editor) ->
    data = {}

    for name, instance of CKEDITOR.instances # All CKEditors on the whole page
      snippets_data = {}
      for name, widget of instance.widgets.instances
        console.log name
        console.log widget
        console.log widget.data
        snippets_data[widget.snippet_id()] = widget.data 

      data[name] = {
        content: @replaceSnippets(instance.getData())
        snippets: snippets_data
      }

    url = window.location.protocol + '//' + window.location.host + '/edit' + window.location.pathname

    $.ajax
      url: url

        complete: (data) -> $(widget.wrapper.$).find('div.cke_widget_element').html(data.responseText)

    snippet['init'] = ->
      for k, v of $(this.wrapper.$).find('div.cke_widget_element').data('snippet-data')
        this.data[k] = v

      this.on 'dialog', (evt) -> @configured = true
      this.on 'data', (evt) -> @loadTemplate(evt.sender) if @configured

    snippet
}
