Sha256: 11fe5e7472437e51115598bbdfd0af7a687338ec79099a054c93fb204f0c177e

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

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)
    # TODO: send event to controller

  ham: (event) ->
    @stopEvent(event)
    # TODO: send event to controller

  enableActions: () =>
    @spamBtn.removeClass('disabled').addClass('btn-warning')
    @hamBtn.removeClass('disabled').addClass('btn-warning')
    @deleteBtn.removeClass('disabled').addClass('btn-danger')

  disableActions: () =>
    @spamBtn.addClass('disabled').removeClass('btn-warning')
    @hamBtn.addClass('disabled').removeClass('btn-warning')
    @deleteBtn.addClass('disabled').removeClass('btn-danger')

  stopEvent: (event) ->
    event.stopPropagation()
    event.preventDefault()

  getChecked: () => @element.find("input:checkbox:checked[data-checkbox='child']")
  getId:      (c) => $(c).data('id')
  getIds:     () => $.map(@getChecked(), (c) => @getId(c))

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

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
georgia_mailer-0.1.3 app/assets/javascripts/georgia_mailer/components/message_table.js.coffee
georgia_mailer-0.1.2 app/assets/javascripts/georgia_mailer/components/message_table.js.coffee
georgia_mailer-0.1.1 app/assets/javascripts/georgia_mailer/components/message_table.js.coffee
georgia_mailer-0.1.0 app/assets/javascripts/georgia_mailer/components/message_table.js.coffee
georgia-0.7.3 app/assets/javascripts/georgia/components/tables/messages.js.coffee
georgia-0.7.2 app/assets/javascripts/georgia/components/tables/messages.js.coffee
georgia-0.7.1 app/assets/javascripts/georgia/components/tables/messages.js.coffee
georgia-0.7.0 app/assets/javascripts/georgia/components/tables/messages.js.coffee