Sha256: ccc6a0a33011fc7603469a724e5582a99c20917f41298568c5c9c5fc79c10a3a

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

class @MediaTable

  constructor: (element) ->
    @element      = $(element)
    @checkboxes   = @element.find("input:checkbox")
    @downloadBtn  = $('.js-download')
    @deleteBtn    = $('.js-delete')
    @setBindings()

  setBindings: () =>
    @checkboxes.on('click', @update)
    @deleteBtn.on('click', @destroy)

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

  # TODO: Should mark item while request is sent. Should sent one request per selected asset for faster feedback
  destroy: (event) =>
    @stopEvent(event)
    $.ajax(
      type: 'DELETE'
      url: '/admin/media'
      data:
        id: @getIds()
      dataType: 'JSON'
    ).always(() =>
      $.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')

  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.actsAsMediaTable = () ->
  @each ->
    new MediaTable($(this))

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
georgia-0.7.8 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.7 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.6 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.5 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.4 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.3 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.2 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.1 app/assets/javascripts/georgia/components/tables/media.js.coffee
georgia-0.7.0 app/assets/javascripts/georgia/components/tables/media.js.coffee