2018-12-29 01:27:37 +01:00
|
|
|
import { inject as service } from '@ember/service';
|
2023-10-15 17:32:11 +02:00
|
|
|
import { action } from '@ember/object';
|
2018-12-29 01:27:37 +01:00
|
|
|
import Controller from '@ember/controller';
|
2023-10-15 17:32:11 +02:00
|
|
|
import { TrackedSet } from 'tracked-built-ins';
|
2016-08-14 22:57:10 +02:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
export default class CreateController extends Controller {
|
|
|
|
@service
|
|
|
|
router;
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
get canEnterMetaStep() {
|
2020-01-13 17:13:23 +01:00
|
|
|
return this.visitedSteps.has('meta') && this.model.pollType;
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
get canEnterOptionsStep() {
|
2020-01-13 17:13:23 +01:00
|
|
|
let { title } = this.model;
|
|
|
|
return this.visitedSteps.has('options') &&
|
|
|
|
typeof title === 'string' && title.length >= 2;
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
get canEnterOptionsDatetimeStep() {
|
2020-01-13 17:13:23 +01:00
|
|
|
return this.visitedSteps.has('options-datetime') && this.model.options.length >= 1;
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2016-08-14 22:57:10 +02:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
get canEnterSettingsStep() {
|
2020-01-13 17:13:23 +01:00
|
|
|
return this.visitedSteps.has('settings') && this.model.options.length >= 1;
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
get isFindADate() {
|
2020-01-13 17:13:23 +01:00
|
|
|
return this.model.pollType === 'FindADate';
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@action
|
|
|
|
updateVisitedSteps() {
|
2020-01-13 17:13:23 +01:00
|
|
|
let { currentRouteName } = this.router;
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-13 17:13:23 +01:00
|
|
|
// currentRouteName might not be defined in some edge cases
|
|
|
|
if (!currentRouteName) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-13 17:13:23 +01:00
|
|
|
let step = currentRouteName.split('.').pop();
|
|
|
|
this.visitedSteps.add(step);
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2019-10-29 08:42:00 +01:00
|
|
|
|
2020-01-13 17:13:23 +01:00
|
|
|
listenForStepChanges() {
|
2023-10-15 17:32:11 +02:00
|
|
|
this.set('visitedSteps', new TrackedSet());
|
2020-01-13 17:13:23 +01:00
|
|
|
|
|
|
|
this.router.on('routeDidChange', this.updateVisitedSteps);
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
2020-01-13 17:13:23 +01:00
|
|
|
|
|
|
|
clearListenerForStepChanges() {
|
|
|
|
this.router.off('routeDidChange', this.updateVisitedSteps);
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|
|
|
|
}
|