decide.nolog.cz/app/models/option.js

44 lines
956 B
JavaScript
Raw Normal View History

2015-10-13 11:29:51 +02:00
import DS from 'ember-data';
import Ember from 'ember';
import {
validator, buildValidations
}
from 'ember-cp-validations';
2015-11-20 11:31:40 +01:00
/* global MF */
2015-10-13 11:29:51 +02:00
2016-01-28 23:48:14 +01:00
const Validations = buildValidations({
title: [
validator('iso8601', {
active() {
return this.get('model.poll.isFindADate');
},
validFormats: [
'YYYY-MM-DD',
'YYYY-MM-DDTHH:mmZ',
'YYYY-MM-DDTHH:mm:ssZ',
'YYYY-MM-DDTHH:mm:ss.SSSZ'
],
dependentKeys: ['i18n.locale']
}),
validator('presence', {
presence: true,
dependentKeys: ['i18n.locale']
}),
2016-05-20 21:49:29 +02:00
validator('unique', {
parent: 'poll',
attributeInParent: 'options',
dependentKeys: ['poll.options.[]', 'poll.options.@each.title', 'i18n.locale']
2016-05-20 21:49:29 +02:00
})
]
});
export default MF.Fragment.extend(Validations, {
poll: MF.fragmentOwner(),
title: DS.attr('string'),
i18n: Ember.inject.service(),
init() {
this.get('i18n.locale');
}
});