2020-01-08 15:58:52 +01:00
|
|
|
import Model, { hasMany, attr } from '@ember-data/model';
|
2019-04-20 23:29:59 +02:00
|
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { equal } from '@ember/object/computed';
|
2016-08-12 19:19:19 +02:00
|
|
|
|
|
|
|
export default Model.extend({
|
2015-08-23 06:18:35 +02:00
|
|
|
/*
|
|
|
|
* relationships
|
|
|
|
*/
|
2016-08-12 19:19:19 +02:00
|
|
|
users: hasMany('user', { async: false }),
|
2015-11-20 00:18:09 +01:00
|
|
|
|
2015-08-23 06:18:35 +02:00
|
|
|
/*
|
|
|
|
* properties
|
|
|
|
*/
|
|
|
|
// Is participation without user name possibile?
|
2016-08-12 19:19:19 +02:00
|
|
|
anonymousUser: attr('boolean'),
|
2015-11-20 00:18:09 +01:00
|
|
|
|
2015-08-23 06:18:35 +02:00
|
|
|
// array of possible answers
|
2016-08-12 19:19:19 +02:00
|
|
|
answers: fragmentArray('answer'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// YesNo, YesNoMaybe or Freetext
|
2016-08-12 19:19:19 +02:00
|
|
|
answerType: attr('string'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// ISO-8601 combined date and time string in UTC
|
2016-08-12 19:19:19 +02:00
|
|
|
creationDate: attr('date'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// polls description
|
2016-08-12 19:19:19 +02:00
|
|
|
description: attr('string', {
|
2015-08-22 23:47:31 +02:00
|
|
|
defaultValue: ''
|
|
|
|
}),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
2015-08-23 16:13:52 +02:00
|
|
|
// ISO 8601 date + time string in UTC
|
2016-08-12 19:19:19 +02:00
|
|
|
expirationDate: attr('string', {
|
2015-08-23 16:13:52 +02:00
|
|
|
includePlainOnCreate: 'serverExpirationDate'
|
|
|
|
}),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// Must all options been answered?
|
2016-08-12 19:19:19 +02:00
|
|
|
forceAnswer: attr('boolean'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// array of polls options
|
2016-08-12 19:19:19 +02:00
|
|
|
options: fragmentArray('option'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// FindADate or MakeAPoll
|
2016-08-12 19:19:19 +02:00
|
|
|
pollType: attr('string'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// timezone poll got created in (like "Europe/Berlin")
|
2016-08-12 19:19:19 +02:00
|
|
|
timezone: attr('string'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// polls title
|
2016-08-12 19:19:19 +02:00
|
|
|
title: attr('string'),
|
2015-08-23 06:18:35 +02:00
|
|
|
|
|
|
|
// Croodle version poll got created with
|
2016-08-12 19:19:19 +02:00
|
|
|
version: attr('string', {
|
2015-08-23 06:18:35 +02:00
|
|
|
encrypted: false
|
|
|
|
}),
|
2015-11-20 00:18:09 +01:00
|
|
|
|
2015-08-23 06:18:35 +02:00
|
|
|
/*
|
|
|
|
* computed properties
|
|
|
|
*/
|
2019-04-20 23:29:59 +02:00
|
|
|
hasTimes: computed('options.[]', function() {
|
|
|
|
if (this.isMakeAPoll) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.options.any((option) => {
|
|
|
|
let dayStringLength = 10; // 'YYYY-MM-DD'.length
|
|
|
|
return option.title.length > dayStringLength;
|
|
|
|
});
|
2016-05-20 23:43:05 +02:00
|
|
|
}),
|
2015-11-20 00:18:09 +01:00
|
|
|
|
2019-04-20 23:29:59 +02:00
|
|
|
isFindADate: equal('pollType', 'FindADate'),
|
|
|
|
isFreeText: equal('answerType', 'FreeText'),
|
|
|
|
isMakeAPoll: equal('pollType', 'MakeAPoll'),
|
2015-06-20 19:04:19 +02:00
|
|
|
});
|