Sha256: 02f134fc2eb339949cb1d527416f32e7710d654ea848024602e2311846486ec2

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

class @MediaTable extends @Table

  constructor: (element, checkboxable) ->
    super(element, checkboxable)
    @downloadBtn  = $('.js-download')
    @deleteBtn    = $('.js-delete')
    @deleteBtn.on('click', @destroy)

  # TODO: Should mark item while request is sent. Should sent one request per selected asset for faster feedback
  destroy: (event) =>
    @stopEvent(event)
    $.ajax(
      url: "/admin/media/#{@getIds()}"
      type: 'DELETE'
      dataType: 'JSON'
      success: @removeAssets
    ).always(@notify)

  update: () =>
    @updateDownloadableIds()
    if @getChecked().length
      @enableActions()
    else
      @disableActions()

  removeAssets: () =>
    $.each @getIds(), (index, id) -> $("#asset_#{id}").remove()

  updateDownloadableIds: () =>
    $('.downloadable-ids').val(@getIds())

  enableActions: () =>
    @downloadBtn.removeClass('disabled').addClass('btn-info')
    @deleteBtn.removeClass('disabled').addClass('btn-danger')

  disableActions: () =>
    @downloadBtn.addClass('disabled').removeClass('btn-info')
    @deleteBtn.addClass('disabled').removeClass('btn-danger')

$.fn.actsAsMediaTable = () ->
  @each ->
    checkboxable = new Checkboxable($(this))
    new MediaTable($(this), checkboxable)

jQuery ->
  $("table.assets.js-checkboxable").each ->
    $(this).actsAsMediaTable()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/assets/javascripts/georgia/components/tables/media.js.coffee