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

75 lines
1.7 KiB
JavaScript
Raw Normal View History

import Model, { hasMany, attr } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
export default Model.extend({
/*
* relationships
*/
users: hasMany('user', { async: false }),
2015-11-20 00:18:09 +01:00
/*
* properties
*/
// Is participation without user name possibile?
anonymousUser: attr('boolean'),
2015-11-20 00:18:09 +01:00
// array of possible answers
answers: fragmentArray('answer'),
// YesNo, YesNoMaybe or Freetext
answerType: attr('string'),
// ISO-8601 combined date and time string in UTC
creationDate: attr('date'),
// polls description
description: attr('string', {
2015-08-22 23:47:31 +02:00
defaultValue: ''
}),
// ISO 8601 date + time string in UTC
expirationDate: attr('string', {
includePlainOnCreate: 'serverExpirationDate'
}),
// Must all options been answered?
forceAnswer: attr('boolean'),
// array of polls options
options: fragmentArray('option'),
// FindADate or MakeAPoll
pollType: attr('string'),
// timezone poll got created in (like "Europe/Berlin")
timezone: attr('string'),
// polls title
title: attr('string'),
// Croodle version poll got created with
version: attr('string', {
encrypted: false
}),
2015-11-20 00:18:09 +01:00
/*
* computed properties
*/
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;
});
}),
2015-11-20 00:18:09 +01:00
isFindADate: equal('pollType', 'FindADate'),
isFreeText: equal('answerType', 'FreeText'),
isMakeAPoll: equal('pollType', 'MakeAPoll'),
});