decide.nolog.cz/app/controllers/create/index.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

import Ember from 'ember';
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({
pollType: [
validator('presence', {
presence: true,
dependentKeys: ['i18n.locale']
}),
validator('inclusion', {
in: ['FindADate', 'MakeAPoll'],
dependentKeys: ['i18n.locale']
})
]
});
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
});
export default Ember.Controller.extend(Validations, {
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
}
},
2015-11-20 02:18:19 +01:00
i18n: Ember.inject.service(),
init() {
this.get('i18n.locale');
},
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
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
}),
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
})
];
2016-01-28 23:48:14 +01:00
})
2015-04-07 13:17:45 +02:00
});