decide.nolog.cz/app/views/datepicker.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-10-30 21:44:22 +01:00
import Ember from "ember";
export default Ember.View.extend({
2014-07-06 19:22:38 +02:00
classNames: ['datepicker'],
didInsertElement: function() {
var self = this,
selectedDates = [];
2014-07-06 19:22:38 +02:00
this._super();
2014-11-01 18:00:46 +01:00
Ember.$('.datepicker').datepicker({
2014-07-06 19:22:38 +02:00
format: "yyyy-mm-dd hh:mm:ss",
multidate: true,
multidateSeparator: ";",
calendarWeeks: true,
todayHighlight: true,
2014-11-06 21:17:48 +01:00
language: this.get('controller.language.selected')
2014-07-06 19:22:38 +02:00
})
// bind date changes to dates option array in model
2014-07-06 19:22:38 +02:00
.on('changeDate', function(e){
var dates = e.dates,
newDates = [];
2014-07-06 19:22:38 +02:00
// sort dates
dates.sort(function(a,b){
return new Date(a) - new Date(b);
2014-07-06 19:22:38 +02:00
});
// get array in correct form
dates.forEach(function(option) {
newDates.pushObject({title: option});
2014-07-06 19:22:38 +02:00
});
// set options
self.set('_parentView.controller.optionsDates', newDates);
2014-07-06 19:22:38 +02:00
});
// get selected dates in a simple array of date objects
this.get('controller.optionsDates').forEach(function(date){
console.log(date.title);
selectedDates.push( new Date(date.title) );
});
if(selectedDates.length > 0) {
// set selected dates on init
Ember.$('#' + this.elementId).datepicker('setDates', selectedDates);
}
2014-07-06 19:22:38 +02:00
}
2014-07-06 17:37:54 +02:00
});