         ], # /contents
 
         onShow: -> this.setupContent(this.effective_menu_item)
-        onOk: -> this.commitContent(this.effective_menu_item)
+        onOk: ->
+          this.commitContent(this.effective_menu_item)
+          this.effective_menu_item = undefined
+        onCancel: ->
+          this.effective_menu_item = undefined
       }


      retval[@menu.data('effective-menu-id')] = items

    assignLftRgt: ->
      stack = []
      console.log @menu.find('li')

      @menu.find('li').each (item) ->
        console.log 'item'


  $.fn.extend effectiveMenuEditor: (option, args...) ->
    @each ->

      @menu.on 'click', 'a', (event) -> event.preventDefault()

    serialize: (retval) ->

      # console.log "============ BEFORE =============="
      # @menu.find('li').each (index, item) =>
      #   item = $(item)
      #   label = item.children('a').first().text()
      #   left = item.children('.menu-item').children("input[name$='[lft]']").val()
      #   right = item.children('.menu-item').children("input[name$='[rgt]']").val()
      #   console.log "[#{label}] #{left}, #{right}"
      # console.log "=================================="

      @assignLftRgt(@menu, 1)

      # console.log "============ AFTER =============="
      # @menu.find('li').each (index, item) =>
      #   item = $(item)
      #   label = item.children('a').first().text()
      #   left = item.children('.menu-item').children("input[name$='[lft]']").val()
      #   right = item.children('.menu-item').children("input[name$='[rgt]']").val()
      #   console.log "[#{label}] #{left}, #{right}"
      # console.log "=================================="

      items = {}

      $.each @menu.find('input').serializeArray(), ->
