         onShow: -> this.setupContent(this.effective_menu_item) if this.effective_menu_item
 
         onOk: ->
-          this.commitContent(this.effective_menu_item)
-          this.effective_menu_item.removeClass('new-item') if this.effective_menu_item.hasClass('new-item')
-          this.effective_menu_item = undefined
+          if this.effective_menu_item
+            this.commitContent(this.effective_menu_item)
+            this.effective_menu_item.removeClass('new-item') if this.effective_menu_item.hasClass('new-item')
 
         onCancel: ->
-          this.effective_menu_item.remove() if this.effective_menu_item.hasClass('new-item')
-          this.effective_menu_item = undefined
+          if this.effective_menu_item && this.effective_menu_item.hasClass('new-item')
+            this.effective_menu_item.remove()
       }
-
-      # console.log definition
-      # definition
-
-      # # So we've built the definition above, now we're going to add one checkbox each for all roles
-      # elements = definition['contents'][1]['elements']
-
-      # for effective_role in CKEDITOR.config['effective_regions']['roles']
-      #   description = effective_role[0]
-      #   role = effective_role[1]
-      #   disabled = effective_role[2]
-
-
-
-      # definition

                setup: (element) ->
                  this.setValue(element.children('.menu-item').children("input[name$='[menuable_id]']").val())
                commit: (element) ->
                  if this.getElement().isVisible()
                    element.children('.menu-item').children("input[name$='[menuable_id]']").val(this.getValue())
                    element.children('.menu-item').children("input[name$='[menuable_type]']").val('Effective::Page')
                  else
                    element.children('.menu-item').children("input[name$='[menuable_id]']").val('')
                    element.children('.menu-item').children("input[name$='[menuable_type]']").val('')
                validate: ->
                  if this.getElement().isVisible() && (this.getValue() || '').length == 0
                    CKEDITOR.dialog.validate.notEmpty('please select a page').apply(this)
              },
              {
                id: 'url',

    $('.effective-menu').effectiveMenuEditor() # Initialize the EffectiveMenus

    CKEDITOR.dialog.add 'effectiveMenusDialog', (editor) ->
      {
        title: 'Effective Menu Item'
        minWidth: 350,
        minHeight: 200,
