Sha256: f33056d33910dbfa024a69258d61ea30f72b5cb1cb8cf569407976b6371442e2

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

@app.controller 'AssetFieldCtrl',  ['$scope', '$http', ($scope, $http) ->

  $scope.$modal = null
  $scope.assets = []
  $scope.meta   = {}
  $scope.uid    = 'asset-' + Math.uid()
  
  $scope.loadAssets = (page) ->
    config = if page? then { params: { page: page } } else null
    req = $http.get $scope.assetsPath, config
    req.success (data) ->
      $scope.assets = data.assets
      $scope.meta   = data.meta
      $scope.initPagination() if $scope.hasAssets()

  $scope.hasAssets = ->
    $scope.assets.length

  $scope.selectAsset = (asset) ->
    $scope.asset = asset
    $scope.$modal.foundation 'reveal', 'close'
    true

  $scope.deselectAsset = ->
    $scope.asset = null

  $scope.afterUpload = (asset) ->
    $scope.loadAssets()
    $scope.$modal.find('.tab-title a[data-success]').trigger 'click'
    true

]

@app.directive 'paginateAssets', ->
  ($scope, $el, $attrs) ->
    $scope.initPagination = ->
      $el.pagination
        pages:          $scope.meta.total_pages
        currentPage:    $scope.meta.current_page
        hrefTextPrefix: '#/media/page-'
        onPageClick: (page, e) ->
          e.preventDefault()
          $scope.loadAssets(page)



# jQuery init
$(document).on 'ready page:load', ->

  $(document).on 'open.fndtn.reveal', '.asset-field-modal', ->
    $scope = angular.element($(this)).scope()
    $scope.$modal = $(this)
    $scope.loadAssets()
    $scope.$apply()
      
      

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
push_type_admin-0.7.0 app/assets/javascripts/push_type/fields/asset_field.js.coffee
push_type_admin-0.7.0.beta.1 app/assets/javascripts/push_type/fields/asset_field.js.coffee
push_type_admin-0.6.0 app/assets/javascripts/push_type/fields/asset_field.js.coffee
push_type_admin-0.6.0.beta.4 app/assets/javascripts/push_type/fields/asset_field.js.coffee
push_type_admin-0.6.0.beta.3 app/assets/javascripts/push_type/fields/asset_field.js.coffee
push_type_admin-0.6.0.beta.2 app/assets/javascripts/push_type/fields/asset_field.js.coffee