Sha256: cb02c2c3bf9d7c7d11ca8241f0b64f661856752575cf1b427e01ed261e14666e

Contents?: true

Size: 1.74 KB

Versions: 18

Compression:

Stored size: 1.74 KB

Contents

class Apiv1.TreeTaxonLiComponent extends Ember.Component
  tagName: 'li'
  classNames: ['tree-taxon-li']
  classNameBindings: ['isSelected:selected', 'isExpanded:expanded']
  adminMode: false

  +computed taxon, activeTaxons.@each, isExpandable
  isExpanded: (key, expand) -> 
    return false unless @isExpandable
    if arguments.length > 1
      @expansionCoefficient = expand
    unless @expansionCoefficient?
      @expansionCoefficient = @isExpandable and @activeTaxons.contains @taxon
    @expansionCoefficient

  +computed taxon.hasChildren
  isExpandable: -> @get("taxon.hasChildren")

  +computed taxon.hasChildren
  isSelectable: -> not @get("taxon.hasChildren")

  +computed taxon, activeTaxons.@each, isSelectable
  isSelected: (key, select) ->
    return false unless @isSelectable
    if arguments.length > 1
      @selectionCoefficient = select
    unless @selectionCoefficient?
      @selectionCoefficient = @isSelectable and @activeTaxons.contains @taxon
    @selectionCoefficient

  +computed adminMode
  adminModeReasonable: ->
    @adminMode && @taxon.id

  toggleExpansion: ->
    if @isExpanded
      @unexpandMe()
    else
      @expandMe()

  toggleSelection: ->
    if @isSelected
      @unselectMe()
    else
      @selectMe()

  unexpandMe: ->
    @isExpanded = false

  expandMe: ->
    @isExpanded = true

  unselectMe: ->
    @activeTaxons ||= []
    @activeTaxons.removeObject @taxon
    @isSelected = false

  selectMe: ->
    @activeTaxons ||= []
    @activeTaxons.addObject @taxon
    @isSelected = true

  actions:
    killTaxon: ->
      @taxon.destroyRecord().then -> Apiv1.Flash.register "success", "taxon destroyed", 2000

    interactWithTaxon: ->
      if @taxon.hasChildren
        @toggleExpansion()
      else
        @toggleSelection()

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cloudrider-0.3.0 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.18 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.15 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.14 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.12 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.11 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.10 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.9 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.8 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.7 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.6 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.5 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.4 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.3 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.2 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.1 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.2.0 generica/app/assets/javascripts/components/tree/taxon-li.js.em
cloudrider-0.1.3 generica/app/assets/javascripts/components/tree/taxon-li.js.em