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