Created
September 4, 2015 21:59
-
-
Save Janther/3f06a492b3554637497a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.DatetimePickerComponent = Em.Component.extend | |
$picker: null | |
picker_format: 'dd/mm/yy' | |
placeholder: Em.computed.alias('format') | |
# Init function | |
didInsertElement: -> | |
$picker = @$('input').datepicker | |
dateFormat: @get('picker_format') | |
@set('$picker', $picker) | |
$picker.datepicker('setDate', @get('value')) if @get('value') | |
$picker.on 'change', => | |
@set('value', $picker.datepicker('getDate')) | |
$picker.blur() | |
# Model Observer | |
datetimeChanged: (-> | |
# get model datetime | |
modelDatetime = @get('value') | |
# get picker datetime | |
$picker = @get('$picker') | |
pickerDatetime = $picker.datepicker('getDate') | |
# Overwrite picker date if modelDatetime and pickerDatetime are not the same. | |
unless Em.isEqual(modelDatetime, pickerDatetime) | |
$picker.datepicker('setDate', modelDatetime) | |
).observes('value') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment