2016-01-22 00:19:46 +01:00
|
|
|
import Ember from 'ember';
|
2015-11-16 14:28:00 +01:00
|
|
|
import {
|
|
|
|
validator, buildValidations
|
|
|
|
}
|
|
|
|
from 'ember-cp-validations';
|
2014-10-30 21:44:22 +01:00
|
|
|
|
2016-01-28 22:49:14 +01:00
|
|
|
const Validations = buildValidations({
|
2015-11-16 14:28:00 +01:00
|
|
|
pollType: [
|
2016-05-23 12:42:47 +02:00
|
|
|
validator('presence', {
|
|
|
|
presence: true,
|
|
|
|
dependentKeys: ['i18n.locale']
|
|
|
|
}),
|
2015-11-16 14:28:00 +01:00
|
|
|
validator('inclusion', {
|
2016-05-23 12:42:47 +02:00
|
|
|
in: ['FindADate', 'MakeAPoll'],
|
|
|
|
dependentKeys: ['i18n.locale']
|
2015-11-16 14:28:00 +01:00
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2016-01-28 22:49:14 +01:00
|
|
|
const TranslateableObject = Ember.Object.extend({
|
2015-11-20 02:18:19 +01:00
|
|
|
i18n: Ember.inject.service(),
|
2015-11-24 00:53:03 +01:00
|
|
|
label: Ember.computed('labelTranslation', 'i18n.locale', function() {
|
2015-11-20 02:18:19 +01:00
|
|
|
return this.get('i18n').t(this.get('labelTranslation'));
|
|
|
|
}),
|
|
|
|
labelTranslation: undefined
|
|
|
|
});
|
|
|
|
|
2015-11-16 14:28:00 +01:00
|
|
|
export default Ember.Controller.extend(Validations, {
|
2014-07-06 18:56:51 +02:00
|
|
|
actions: {
|
2016-01-28 23:48:14 +01:00
|
|
|
submit() {
|
2015-11-20 23:02:35 +01:00
|
|
|
if (this.get('validations.isValid')) {
|
|
|
|
this.transitionToRoute('create.meta');
|
|
|
|
}
|
2014-07-06 17:37:54 +02:00
|
|
|
}
|
2014-07-06 18:56:51 +02:00
|
|
|
},
|
|
|
|
|
2015-11-20 02:18:19 +01:00
|
|
|
i18n: Ember.inject.service(),
|
|
|
|
|
2016-05-23 12:42:47 +02:00
|
|
|
init() {
|
|
|
|
this.get('i18n.locale');
|
|
|
|
},
|
|
|
|
|
2015-11-16 14:28:00 +01:00
|
|
|
pollType: Ember.computed.alias('model.pollType'),
|
|
|
|
|
2016-01-28 23:48:14 +01:00
|
|
|
pollTypes: Ember.computed('', function() {
|
|
|
|
const container = this.get('container');
|
2015-11-20 02:18:19 +01:00
|
|
|
|
2014-07-06 18:56:51 +02:00
|
|
|
return [
|
2015-11-20 02:18:19 +01:00
|
|
|
TranslateableObject.create({
|
2016-01-28 23:48:14 +01:00
|
|
|
id: 'FindADate',
|
|
|
|
labelTranslation: 'pollTypes.findADate.label',
|
2015-11-20 02:18:19 +01:00
|
|
|
container
|
2014-07-06 18:56:51 +02:00
|
|
|
}),
|
2015-11-20 02:18:19 +01:00
|
|
|
TranslateableObject.create({
|
2016-01-28 23:48:14 +01:00
|
|
|
id: 'MakeAPoll',
|
|
|
|
labelTranslation: 'pollTypes.makeAPoll.label',
|
2015-11-20 02:18:19 +01:00
|
|
|
container
|
2014-07-06 18:56:51 +02:00
|
|
|
})
|
|
|
|
];
|
2016-01-28 23:48:14 +01:00
|
|
|
})
|
2015-04-07 13:17:45 +02:00
|
|
|
});
|