Created
June 23, 2015 08:19
-
-
Save automagisch/f4dd050fb55a01252572 to your computer and use it in GitHub Desktop.
Basic Ember Date Selector
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.DateSelectionView = Em.View.extend({ | |
templateName: "date-selection", | |
tagName: "div", | |
classNames: ['date-selector','clearfix'], | |
classNameBindings: ['showLabels::no-labels'], | |
date: null, | |
showLabels: true, | |
timezone: true, | |
until_year: 2030, | |
from_year: 1900, | |
month: null, | |
year: null, | |
day: null, | |
init: function() { | |
this._super(); | |
}, | |
years: function() { | |
var years = [], | |
until_year = this.get('until_year'), | |
from_year = this.get('from_year'); | |
for(var year = from_year; year <= until_year; year++) { | |
years.push(year); | |
} | |
return years; | |
}.property(''), | |
months: function() { | |
return [ | |
{ value: 0, label: 'January' }, | |
{ value: 1, label: 'February' }, | |
{ value: 2, label: 'March' }, | |
{ value: 3, label: 'April' }, | |
{ value: 4, label: 'May' }, | |
{ value: 5, label: 'June' }, | |
{ value: 6, label: 'July' }, | |
{ value: 7, label: 'August' }, | |
{ value: 8, label: 'September' }, | |
{ value: 9, label: 'October' }, | |
{ value: 10, label: 'November' }, | |
{ value: 11, label: 'December' } | |
]; | |
}.property(''), | |
days: function() { | |
var days = []; | |
for(var day = 0; day < 31; day++) { | |
days.push(day+1); | |
} | |
return days; | |
}.property(''), | |
parseDate: function() { | |
var date = moment(this.get('date')); | |
this.set('day', date.date()); | |
this.set('month', date.month()); | |
this.set('year', date.year()); | |
}.on('init'), | |
writeDate: function() { | |
var day = this.get('day'); | |
var month = this.get('month'); | |
var year = this.get('year'); | |
if(day && month && year) { | |
var mom = moment(); | |
mom.date(day); | |
mom.month(month); | |
mom.year(year); | |
var d = mom.format(); | |
if(!this.get('timezone')) { | |
d = d.split("+")[0]; | |
} | |
this.set('date', d); | |
} | |
}.observes('day','month','year') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment