Sha256: 9e5c553b2d1a319339ab3ded1c8f5ff9aa462ae68525561c5684d48a804d6679

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

#= require ./base

MomentPicker = Tao.Form.MomentPicker

class MomentPicker.YearSegment extends MomentPicker.SegmentBase

  @tag 'tao-moment-picker-year-segment'

  segmentName: 'year'

  _bind: ->
    @on 'click', '.year', (e) =>
      $year = $ e.currentTarget
      momentData = _.clone @momentData
      momentData.year = $year.data 'year'
      momentData.month = null
      momentData.date = null
      @trigger 'dataSelect', [momentData]

    @on 'click', '.link-prev-years, .link-next-years', (e) =>
      momentData = _.clone @momentData
      if $(e.currentTarget).is('.link-prev-years')
        momentData['year'] -= 9
      else
        momentData['year'] += 9
      momentData.month = null
      momentData.date = null
      @trigger 'dataRefresh', [momentData]

  setMomentData: (momentData) ->
    super

    if _.isNil @value()
      momentData.year = moment().year()
      @trigger 'dataRefresh', [momentData]
      return false

    @_render()

  _render: ->
    $yearList = @jq.find('.year-list').empty()

    start = @value() - 4
    end = @value() + 4
    currentYear = moment().year()
    for year in [start..end]
      $year = $ '<a>',
        href: 'javascript:;'
        class: 'year'
        'data-year': year
        text: year

      $year.addClass('current') if year == currentYear
      $year.addClass('selected') if year == @value()
      $year.appendTo $yearList

TaoComponent.register MomentPicker.YearSegment

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tao_form-0.1.2 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/year_segment.coffee
tao_form-0.1.1 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/year_segment.coffee
tao_form-0.1.0 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/year_segment.coffee