       type: "POST"
       dataType: "JSON"
       url: "/admin/messages/#{@getIds()}/ham"
-      success: (data) =>
-        $.each data, (i, message_id) => @removeMessage(message_id)
-    )
+      success: @removeMessages
+    ).always(@notify)
+
+  removeMessages: () =>
+    $.each @getIds(), (i, message_id) => @removeMessage(message_id)
 
   removeMessage: (message_id) ->
     $("tr#message_#{message_id}").remove();

class @MessagesTable

  constructor: (element) ->
    @element          = $(element)
    @checkboxes       = @element.find("input:checkbox")
    @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'
    )

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

      type: "POST"
      dataType: "JSON"
      url: "/admin/messages/#{@getIds()}/spam"
      success: @removeMessages
    ).always(@notify)

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