Sha256: efb3e37bfaef1c0feb94e533a1afa00850bedbef2efbf5300aaadf052d3f6f42

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

#= require ./base

MomentPicker = Tao.Form.MomentPicker

class MomentPicker.MonthSegment extends MomentPicker.SegmentBase

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

  segmentName: 'month'

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

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

  setMomentData: (momentData) ->
    super
    @_render()
    @momentData

  _render: ->
    @jq.find('.month.selected').removeClass 'selected'
    @jq.find('.month.current').removeClass 'current'
    unless _.isNil @value()
      @jq.find(".month[data-month='#{@value()}']").addClass 'selected'

    now = moment()
    if @momentData['year'] == now.year()
      @jq.find(".month[data-month='#{now.month()}']").addClass 'current'

  label: ->
    moment.monthsShort()[@value() * 1]

TaoComponent.register MomentPicker.MonthSegment

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tao_form-0.1.9 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.8 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.7 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.6 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.5 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.4 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee
tao_form-0.1.3 lib/assets/javascripts/tao/form/shared/fields/moment_picker/segments/month_segment.coffee