Sha256: b8a776983856c781216c111ec2e6173a27e24fedb94f8dd47a4d03af12df93a3

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

#= require ../shared/asset_picker_view

Locomotive.Views.ContentAssets ||= {}

class Locomotive.Views.ContentAssets.PickerView extends Locomotive.Views.Shared.AssetPickerView

  number_items_per_row: 4

  _item_views: []

  template: ->
    ich.content_asset_picker

  fetch_assets: ->
    @collection.fetch()

  build_uploader: (el, link) ->
    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()

  add_asset: (asset, first) ->
    view = new Locomotive.Views.ContentAssets.PickerItemView model: asset, parent: @

    (@_item_views ||= []).push(view)
    @$('ul.list .clear').before(view.render().el)

    @_refresh()

    @_move_to_last_asset() unless first == true

  remove_asset: (asset) ->
    view = _.find @_item_views, (tmp) -> tmp.model == asset
    view.remove() if view?
    @_refresh()

  _on_refresh: ->
    self = @
    @$('ul.list li.asset').each (index) ->
      if (index + 1) % self.number_items_per_row == 0
        $(@).addClass('last')
      else
        $(@).removeClass('last')

  _reset: ->
    _.each @_item_views || [], (view) -> view.remove()
    super()

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotive_cms-2.0.0.rc7 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee
locomotive_cms-2.0.0.rc6 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee
locomotive_cms-2.0.0.rc5 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee
locomotive_cms-2.0.0.rc4 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee
locomotive_cms-2.0.0.rc2 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee
locomotive_cms-2.0.0.rc1 app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee