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

96 lines
1.8 KiB
JavaScript
Raw Normal View History

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