Sha256: 45472c39f195ad2f78c0e9950fab11879d80e39713c9c0c898985d6217d60208

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

class Tao.Form.MomentPicker.ElementBase extends TaoComponent

  @attribute 'valueFormat', 'displayFormat'

  @attribute 'active', 'disabled', type: 'boolean', observe: true

  @get 'value', ->
    @field?.val()

  @set 'value', (val) ->
    @setMoment val

  _connected: ->
    [@result, @segmentList] = @findComponent(
      '.tao-moment-picker-result',
      '.tao-moment-picker-segment-list',
      @_childComponentsReady.bind(@)
    )
    @_bind()

  _disconnected: ->
    @off()

  _bind: ->
    @on 'tao:activeClick', '.tao-moment-picker-result', (e) =>
      return if @disabled
      @_toggleActive()
      null

    @on 'tao:clear', '.tao-moment-picker-result', (e) =>
      return if @disabled
      @active = false
      @setMoment null
      @namespacedTrigger 'change', [@moment]
      null

    @on 'tao:select', '.tao-moment-picker-segment-list', (e, m) =>
      @active = false
      @setMoment m
      @namespacedTrigger 'change', [@moment]
      null

  _childComponentsReady: ->
    @field = @result.field
    @result.format = @displayFormat
    @setMoment @field.val()
    @namespacedTrigger 'ready'

  _toggleActive: ->
    @active = !@active

  setMoment: (m) ->
    m = moment(m, @valueFormat) unless moment.isMoment(m)
    if m && m.isValid()
      @result.setMoment m
      @field.val m.format(@valueFormat)
      @moment = m
    else
      @result.setMoment null
      @field.val ''
      @moment = null
    @moment

  disableBefore: (m) ->
    @segmentList.segments.forEach (segment) ->
      segment.disableBefore = m

  disableAfter: (m) ->
    @segmentList.segments.forEach (segment) ->
      segment.disableAfter = m

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tao_form-0.2.3 lib/assets/javascripts/tao/form/shared/fields/moment_picker/element/base.coffee
tao_form-0.2.2 lib/assets/javascripts/tao/form/shared/fields/moment_picker/element/base.coffee
tao_form-0.2.1 lib/assets/javascripts/tao/form/shared/fields/moment_picker/element/base.coffee
tao_form-0.2.0 lib/assets/javascripts/tao/form/shared/fields/moment_picker/element/base.coffee
tao_form-0.1.10 lib/assets/javascripts/tao/form/shared/fields/moment_picker/element/base.coffee