           buttons: [{
             text: 'Ok'
             click: (e) -> 
-              console.log "OK button clicked:", e, w
+              attrform.find("div.attrform:hidden").each (e) ->
+                console.log "removing", $(this).data('attribute_name')
+                editorNode.removeAttr $(this).data('attribute_name')
+              attrform.find("div.attrform:visible").each (e) ->
+                console.log "setting", $(this).data('attribute_name'), "to", $(this).find('.attrinput').val()
+                editorNode.attr $(this).data('attribute_name'), $(this).find('.attrinput').val()
               wm.close(null, w.id)
           }, {
             text: 'Cancel'

          # TODO: Better way to get the actual base document element?
          # TODO: Only set this when necessary, maybe?
          @editor.dom.select("body")[0].firstElementChild.setAttribute("xmlns:#{prefix}", params.ns)
          attrValue = node.getAttributeNS(params.ns, name)
          if attrValue
            node.removeAttributeNS(params.ns, name)
            node.setAttribute("#{prefix}:#{name}", attrValue)
          else
        if prefix
          name = "#{prefix}:#{name}"
          attrValue = node.getAttribute(name)
      else
        attrValue = node.getAttribute(name)

      if params.required or attrValue?
        display = "block"
      else
        display = "none"
      out = document.createElement("div")
      out.setAttribute("style", """display: #{display};""")
      out.class = "attr_#{name}"
      label = document.createElement("label")
      label.appendChild(document.createTextNode("#{name}"))
      out.appendChild(label)

      if params.value?.length
        sel = document.createElement("select")
        sel.name = "attr_#{name}"
        if not params.required
          opt = document.createElement("option")
          opt.value = ""
          opt.appendChild(document.createTextNode(" -- empty -- "))
          sel.appendChild(opt)
        for value in params.value
          opt = document.createElement("option")
          opt.value = value
          if value is attrValue
            opt.setAttribute("selected", "selected")
          opt.appendChild(document.createTextNode(value))
          sel.appendChild(opt)
        out.appendChild(sel)
      else if params.data isnt undefined
        sel = document.createElement("input")
        sel.type = "text"
        if attrValue?
          sel.value = attrValue
        out.appendChild(sel)
      else if params.$?
        sel = document.createElement("textarea")
        if attrValue?
          sel.appendChild(document.createTextNode(attrValue))
        out.appendChild(sel)

      out


      attroptional = {}
      attrrequired = {}
      attrgroups = {}
      editorNode = @editorNodeFromListNode node
      newtagname = $(editorNode).attr("data-xmlel") || params['key']
      elementattrs = @editor.plugins.textorum.schema.defs[newtagname]?.attr

      attrRequiredList = $(document.createElement("ul"))
      attrlist = $(document.createElement("ul"))
      attrform = $(document.createElement("div"))

      attrwindow = $(document.createElement("div"))
      attrwindow.addClass "textorum_attributewindow"
      attrlists = $(document.createElement("div"))
      attrlists.append attrRequiredList
      attrlists.append attrlist
      attrwindow.append attrlists
      attrwindow.append attrform
      
      attrlists.on 'click', 'li.optional', (e) ->
        el = $(this)
        window.foo = el
        el.parents(".textorum_attributewindow").find("div.#{el.data('target')}").toggle()

      for own attr of elementattrs
        attrform.append @attrFormElement(attr, elementattrs[attr], node)
        if elementattrs[attr].required
          attrRequiredList.append @attrListElement(attr, elementattrs[attr], node)
          attroptional[attr] = elementattrs[attr]
        else
          attrlist.append @attrListElement(attr, elementattrs[attr], node)
          attrrequired[attr] = elementattrs[attr]
      if attrform.children().length
        window.attrform = attrform
        wm = @editor.windowManager
        w = wm.open {
          inline: true
