2016-02-16 02:26:27 +01:00
|
|
|
import Ember from 'ember';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
2016-08-02 01:55:48 +02:00
|
|
|
const { computed, Controller } = Ember;
|
|
|
|
|
|
|
|
export default Controller.extend({
|
2016-02-16 02:26:27 +01:00
|
|
|
actions: {
|
|
|
|
nextPage() {
|
|
|
|
this.normalizeOptions();
|
|
|
|
|
|
|
|
this.transitionToRoute('create.settings');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
normalizeOptions() {
|
|
|
|
const options = this.get('options');
|
2016-02-18 12:06:54 +01:00
|
|
|
|
|
|
|
// remove all days from options which haven't a time but there is atleast
|
|
|
|
// one option with time for that day
|
2016-02-16 02:26:27 +01:00
|
|
|
const daysWithTime = options.map((option) => {
|
|
|
|
if (moment(option.get('title'), 'YYYY-MM-DD', true).isValid()) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return moment(option.get('title')).format('YYYY-MM-DD');
|
|
|
|
}
|
|
|
|
}).uniq().filter((option) => option !== null);
|
|
|
|
const removeObjects = options.filter((option) => {
|
|
|
|
return daysWithTime.indexOf(option.get('title')) !== -1;
|
|
|
|
});
|
|
|
|
options.removeObjects(
|
|
|
|
removeObjects
|
|
|
|
);
|
2016-02-18 12:06:54 +01:00
|
|
|
|
|
|
|
// sort options
|
|
|
|
// ToDo: Find a better way without reseting the options
|
|
|
|
this.set('options', options.sortBy('title'));
|
2016-02-16 02:26:27 +01:00
|
|
|
},
|
2016-08-02 01:55:48 +02:00
|
|
|
options: computed.alias('model.options')
|
2016-02-16 02:26:27 +01:00
|
|
|
});
|