2018-12-29 01:27:37 +01:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-01-18 10:13:50 +01:00
|
|
|
import { action } from '@ember/object';
|
2018-12-29 01:27:37 +01:00
|
|
|
import Component from '@ember/component';
|
2016-01-19 04:56:51 +01:00
|
|
|
import {
|
|
|
|
validator, buildValidations
|
|
|
|
}
|
|
|
|
from 'ember-cp-validations';
|
|
|
|
|
2016-01-20 02:52:21 +01:00
|
|
|
let Validations = buildValidations({
|
2016-01-19 04:56:51 +01:00
|
|
|
options: [
|
|
|
|
validator('collection', true),
|
|
|
|
validator('length', {
|
2020-01-30 00:23:12 +01:00
|
|
|
dependentKeys: ['model.options.[]', 'model.intl.locale'],
|
2016-05-21 17:17:08 +02:00
|
|
|
min: 1,
|
2016-06-27 13:04:20 +02:00
|
|
|
// it's impossible to delete all text options so this case could be ignored
|
|
|
|
// for validation error message
|
2020-01-30 00:23:12 +01:00
|
|
|
descriptionKey: 'create.options.error.notEnoughDates'
|
2016-01-19 04:56:51 +01:00
|
|
|
}),
|
|
|
|
validator('valid-collection', {
|
2018-12-28 22:26:34 +01:00
|
|
|
dependentKeys: ['model.options.[]', 'model.options.@each.title']
|
2016-01-19 04:56:51 +01:00
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
export default class CreateOptionsComponent extends Component.extend(Validations) {
|
|
|
|
shouldShowErrors = false;
|
|
|
|
|
2016-05-21 17:17:08 +02:00
|
|
|
// consumed by validator
|
2020-01-30 00:23:12 +01:00
|
|
|
@service intl;
|
2020-01-18 10:13:50 +01:00
|
|
|
|
|
|
|
@action
|
|
|
|
previousPage() {
|
|
|
|
this.onPrevPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
submit() {
|
|
|
|
if (this.get('validations.isValid')) {
|
|
|
|
this.onNextPage();
|
|
|
|
} else {
|
|
|
|
this.set('shouldShowErrors', true);
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 00:23:12 +01:00
|
|
|
|
|
|
|
init() {
|
|
|
|
super.init(...arguments);
|
|
|
|
|
|
|
|
this.intl.locale;
|
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|