app/assets/javascripts/georgia/components/tables/media.js.coffee in georgia-0.7.8 vs app/assets/javascripts/georgia/components/tables/media.js.coffee in georgia-0.8.0
- old
+ new
@@ -1,37 +1,32 @@
-class @MediaTable
+class @MediaTable extends @Table
- constructor: (element) ->
- @element = $(element)
- @checkboxes = @element.find("input:checkbox")
+ constructor: (element, checkboxable) ->
+ super(element, checkboxable)
@downloadBtn = $('.js-download')
@deleteBtn = $('.js-delete')
- @setBindings()
-
- setBindings: () =>
- @checkboxes.on('click', @update)
@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()
- # 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()
- )
+ removeAssets: () =>
+ $.each @getIds(), (index, id) -> $("#asset_#{id}").remove()
updateDownloadableIds: () =>
$('.downloadable-ids').val(@getIds())
enableActions: () =>
@@ -40,20 +35,13 @@
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))
+ checkboxable = new Checkboxable($(this))
+ new MediaTable($(this), checkboxable)
jQuery ->
$("table.assets.js-checkboxable").each ->
$(this).actsAsMediaTable()
\ No newline at end of file