Sha256: 398dc2d0ae87efe54808e629337ff345b20550f448508a391701e6fd5d824cb5

Contents?: true

Size: 1.21 KB

Versions: 17

Compression:

Stored size: 1.21 KB

Contents

class Tenon.features.AssetAttachment
  constructor: (@$browseButton, @$container) ->
    @$assetField = @_getAssetField()
    @_setupAssetList()
    @_setupAssetUploading()

  _setupAssetList: =>
    @$list = @$container.find('ul.asset-list')
    new Tenon.features.RecordList(@$list)
    @$list.on('click', 'li.asset a', @_pickAsset)

  _setupAssetUploading: =>
    @uploader = new Tenon.features.AssetUploader(@_uploadComplete)
    @uploader.initialize('#new_asset')

  _pickAsset: (e) =>
    e.preventDefault()
    e.stopPropagation()
    $li = $(e.currentTarget).closest('li.asset')
    @_setFields($li)
    @$container.closest('.modal').modal('hide')

  _uploadComplete: (e, data) =>
    li = JST["tenon/templates/assets/asset_row"](asset : data.result)
    @_setFields($(li))
    @$container.closest('.modal').modal('hide')

  _setFields: ($li) =>
    @$assetField.find('.asset-id-field').val($li.data('record-id'))
    @$assetField.find('.thumbnail').html($li.find('.thumbnail').html())
    @$assetField.find('.asset-info').html($li.find('.record-title a').html())

  _getAssetField: =>
    if @$browseButton.data('asset-field')
      $(@$browseButton.data('asset-field'))
    else
      @$browseButton.closest('.tn-tc-asset-field')

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
tenon-1.1.8 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.7 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.6 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.5 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.4 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.3 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.2 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.1.1 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.76 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.75 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.74 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.73 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.72 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.71 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.70 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.69 app/assets/javascripts/tenon/features/asset_attachment.js.coffee
tenon-1.0.68 app/assets/javascripts/tenon/features/asset_attachment.js.coffee