Sha256: 8ca65204a536776164125f9afb8209aae45f5c1404a559a7dcceb58fd7799319

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

angular.module("SWAT.components").directive "customDropdown", ($document)->
  restrict: 'AE'
  replace: true
  templateUrl: '/swat/pages/components/custom_dropdown.html'
  scope:
    model: '='
    options: '='
    modelAttr: '='
    emptyOption: '='
    placeholder: '='
    glTabIndex: '='
    afterUpdate: '&'
    glDisabled: '='

  controller: ($scope, $attrs, $timeout)->
    $scope.init = ->
      $scope.id = Math.random()*1000
      $scope.decorateOptions()
      $scope.$watch('options', $scope.decorateOptions)
      if $scope.placeholder && !$scope.model
        $scope.model = $scope.placeholder

    $scope.selectOption = (option)->
      $scope.reprocess = true
      $timeout(->
        $scope.afterUpdate() if $scope.afterUpdate
        $scope.reprocess = false
      , 0)

    $scope.decorateOptions = ->
      $scope.selectOptions = _.map($scope.options, (el)-> if $scope.modelAttr then el[$scope.modelAttr] else el )
      if $scope.placeholder
        $scope.selectOptions.unshift $scope.placeholder

    $scope.init()

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sw2at-ui-0.0.16 app/assets/javascripts/swat/app/directives/components/custom-dropdown.coffee
sw2at-ui-0.0.15 app/assets/javascripts/swat/app/directives/components/custom-dropdown.coffee
sw2at-ui-0.0.14 app/assets/javascripts/swat/app/directives/components/custom-dropdown.coffee