2011-11-19 16:33:16 +00:00
|
|
|
#= require ../shared/asset_picker_view
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
Locomotive.Views.ContentAssets ||= {}
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
class Locomotive.Views.ContentAssets.PickerView extends Locomotive.Views.Shared.AssetPickerView
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
number_items_per_row: 4
|
|
|
|
|
|
|
|
_item_views: []
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
template: ->
|
|
|
|
ich.content_asset_picker
|
2011-11-19 14:47:56 +00:00
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
fetch_assets: ->
|
2012-05-29 22:53:48 +00:00
|
|
|
@_reset()
|
|
|
|
@collection.fetch
|
|
|
|
success: () =>
|
|
|
|
@open()
|
2011-11-19 14:47:56 +00:00
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
build_uploader: (el, link) ->
|
2011-12-07 15:10:21 +00:00
|
|
|
link.bind 'click', (event) ->
|
|
|
|
event.stopPropagation() & event.preventDefault()
|
|
|
|
el.click()
|
|
|
|
|
|
|
|
el.bind 'change', (event) =>
|
|
|
|
_.each event.target.files, (file) =>
|
|
|
|
asset = new Locomotive.Models.ContentAsset(source: file)
|
|
|
|
asset.save {},
|
|
|
|
headers: { 'X-Flash': true }
|
|
|
|
success: (model, response) => @collection.add(model.prepare())
|
|
|
|
error: => @shake()
|
2011-11-19 14:47:56 +00:00
|
|
|
|
2011-11-20 00:27:23 +00:00
|
|
|
add_asset: (asset, first) ->
|
2011-11-19 14:47:56 +00:00
|
|
|
view = new Locomotive.Views.ContentAssets.PickerItemView model: asset, parent: @
|
|
|
|
|
|
|
|
(@_item_views ||= []).push(view)
|
|
|
|
@$('ul.list .clear').before(view.render().el)
|
|
|
|
|
2011-11-20 00:27:23 +00:00
|
|
|
@_refresh()
|
|
|
|
|
|
|
|
@_move_to_last_asset() unless first == true
|
2011-11-19 14:47:56 +00:00
|
|
|
|
|
|
|
remove_asset: (asset) ->
|
|
|
|
view = _.find @_item_views, (tmp) -> tmp.model == asset
|
|
|
|
view.remove() if view?
|
|
|
|
@_refresh()
|
|
|
|
|
2011-11-19 16:33:16 +00:00
|
|
|
_on_refresh: ->
|
|
|
|
self = @
|
|
|
|
@$('ul.list li.asset').each (index) ->
|
|
|
|
if (index + 1) % self.number_items_per_row == 0
|
|
|
|
$(@).addClass('last')
|
|
|
|
else
|
|
|
|
$(@).removeClass('last')
|
2011-11-18 23:20:37 +00:00
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
_reset: ->
|
|
|
|
_.each @_item_views || [], (view) -> view.remove()
|
2011-11-19 16:33:16 +00:00
|
|
|
super()
|