-class @MessagesTable
+class @MessagesTable extends @Table
 
-  constructor: (element) ->
-    @element          = $(element)
-    @checkboxes       = @element.find("input:checkbox")
-    @deleteBtn        = @element.find('.js-delete')
-    @spamBtn          = @element.find('.js-spam')
-    @hamBtn           = @element.find('.js-ham')
+  constructor: (element, checkboxable) ->
+    super(element, checkboxable)
+    @deleteBtn  = @element.find('.js-delete')
+    @spamBtn    = @element.find('.js-spam')
+    @hamBtn     = @element.find('.js-ham')
     @setBindings()
 
   setBindings: () =>
-    @checkboxes.on('change', @update)
     @deleteBtn.on('click', @delete)
     @spamBtn.on('click', @spam)
     @hamBtn.on('click', @ham)
-
-  update: () =>
-    if @getChecked().length then @enableActions() else @disableActions()
 
   delete: (event) =>
     @stopEvent(event)
     $.ajax(
       url: "/admin/messages/#{@getIds()}"
       type: 'DELETE'
-    )
+      dataType: "JSON"
+      success: @removeMessages
+    ).always(@notify)
 
   spam: (event) =>
     @stopEvent(event)

      type: "POST"
      dataType: "JSON"
      url: "/admin/messages/#{@getIds()}/spam"
      success: (data) =>
        $.each data, (i, message_id) => @removeMessage(message_id)
    )

  ham: (event) =>
    @stopEvent(event)

    @hamBtn.addClass('disabled').removeClass('btn-warning')
    @deleteBtn.addClass('disabled').removeClass('btn-danger')

$.fn.actsAsMessagesTable = () ->
  @each ->
    checkboxable = new Checkboxable($(this))
    new MessagesTable($(this), checkboxable)

jQuery ->
  $("table.messages.js-checkboxable").each ->
