25 lines
1.1 KiB
CoffeeScript
25 lines
1.1 KiB
CoffeeScript
import Ember from 'ember'
|
|
import UiCalendarComponent from 'ember-semantic-ui-calendar/components/ui-calendar'
|
|
{ computed, inject, merge } = Ember
|
|
export default UiCalendarComponent.extend
|
|
momentValue: null
|
|
firstDayOfWeek: null
|
|
is_date: false
|
|
|
|
# Provide the Date object that is used by ui-calendar
|
|
date: computed('momentValue', ->
|
|
if momentValue = @get('momentValue') then momentValue.toDate() else null
|
|
).readOnly()
|
|
|
|
willInitSemantic: (settings) ->
|
|
settings.firstDayOfWeek = if Number.isFinite(@get('firstDayOfWeek')) then @get('firstDayOfWeek') else (if Number.isFinite(@get('globals.first_day_of_week')) then @get('globals.first_day_of_week') else 1)
|
|
@_super arguments...
|
|
@set('is_date', true) if @get('momentValue._f') is 'YYYY-MM-DD' or @get('momentValue._ambigTime') or @get('type') is 'date'
|
|
merge settings,
|
|
onChange: (date) ->
|
|
# Wraps the Date in a moment object an triggers the onChange action
|
|
momentDate = if date then moment(date) else null
|
|
momentDate._ambigTime = true if momentDate and @get('is_date')
|
|
@sendAction 'onChange', momentDate
|
|
|