Newer
Older
import {
Switch,
Button,
Card,
TextField,

Kai Ott
committed
Icon,
} from 'polythene-mithril';
import { styler } from 'polythene-core-css';
import { apiUrl } from 'networkConfig';
import { eventsignups as signupConfig } from '../resourceConfig.json';
import TableView from '../views/tableView';
import DatalistController from '../listcontroller';
import { dateFormatter } from '../utils';
import { icons, DropdownCard, Property } from '../views/elements';
import { ResourceHandler } from '../auth';
const viewLayout = [
display: 'grid',
'grid-template-columns': '40% 55%',
'grid-gap': '50px',
width: '30px',
height: '20px',
float: 'left',
'background-color': 'rgb(031,045,084)',
'border-radius': '10px',
'text-align': 'center',
'line-height': '20px',
color: 'rgb(255,255,255)',
'margin-right': '10px',
'font-size': '11px',
'margin-top': '0px',
];
styler.add('eventView', viewLayout);
// small helper class to display both German and English content together, dependent
// on which content is available.
view({ attrs: { title, de, en } }) {
// TODO Lang indicators should be smaller and there should be less margin
// between languages
return m(
Property,
{ title },
de ? m('div', [
m('div', { className: 'propertyLangIndicator' }, 'DE'),
m('p', de),
]) : '',
en ? m('div', [
m('div', { className: 'propertyLangIndicator' }, 'EN'),
m('p', en),
]) : '',
);
}
// Helper class to either display the signed up participants or those on the
// waiting list.
class ParticipantsTable {
constructor({ attrs: { where } }) {
this.ctrl = new DatalistController('eventsignups', {
embedded: { user: 1 },
where,
}, ['email', 'user.firstname', 'user.lastname'], false);
}
getItemData(data) {
// TODO list should not have hardcoded size outside of stylesheet
return [
m('div', { style: { width: '9em' } }, dateFormatter(data._created)),
m('div', { style: { width: '9em' } }, data.user.lastname),
m('div', { style: { width: '9em' } }, data.user.firstname),
m('div', { style: { width: '9em' } }, data.email),
];
}
view() {
return m(Card, {
style: { height: '300px' },
content: m(TableView, {
controller: this.ctrl,
keys: signupConfig.tableKeys,
tileContent: this.getItemData,
titles: [
{ text: 'Date of Signup', width: '9em' },
{ text: 'Name', width: '9em' },
{ text: 'First Name', width: '9em' },
{ text: 'Email', width: '9em' },
],
}),
});
}
}
view({ attrs: { list } }) {
const emails = list.toString().replace(/,/g, '; ');
return m(Card, {
content: m(TextField, { value: emails, label: '', multiLine: true }, ''),
});
}
constructor() {
super('events');
this.signupHandler = new ResourceHandler('eventsignups');

Kai Ott
committed
this.advertisement = false;
this.registration = false;
this.emailAdresses = false;
this.emaillist = [''];
this.showAllEmails = false;
}
oninit() {
this.handler.getItem(this.id, this.embedded).then((item) => {
this.data = item;
m.redraw();
});
this.setUpEmailList(this.showAllEmails);
}
// setup where query
const where = { event: this.id };
// only show accepted
where.accepted = true;
this.signupHandler.get({ where }).then((data) => {
this.emaillist = (data._items.map(item => item.email));
m.redraw();
});
view({ attrs: { onEdit } }) {
if (!this.data) return '';
let displaySpots = '-';
if (this.data.spots !== 0) {
displaySpots = this.data.spots;
}
return m('div', {
style: { height: '100%', 'overflow-y': 'scroll', padding: '10px' },
}, [
m(Button, {
element: 'div',
label: 'Update Event',
events: { onclick: onEdit },
}),
this.data.img_thumbnail ? m('img', {

Hermann
committed
src: `${apiUrl}${this.data.img_thumbnail.file}`,
height: '50px',
style: { float: 'left' },
}) : '',
m('h1', { style: { 'margin-top': '0px', 'margin-bottom': '0px' } }, [this.data.title_de || this.data.title_en]),
this.data.signup_count ? m(Property, {
style: { float: 'left', 'margin-right': '20px' },
title: 'Signups',
}, `${this.data.signup_count} / ${displaySpots}`) : m.trust(' '),
this.data.location ? m(Property, {
style: { float: 'left', 'margin-right': '20px' },
title: 'Location',
}, `${this.data.location}`) : m.trust(' '),
this.data.time_start ? m(Property, {
title: 'Time',
}, `${dateFormatter(this.data.time_start)} - ${dateFormatter(this.data.time_end)}`) : m.trust(' '),
// everything else is not listed in DropdownCards, which open only on request
m('div.eventViewContainer', { style: { 'margin-top': '50px' } }, [
m('div.eventViewLeft', [
m(DropdownCard, { title: 'description' }, [
title: 'Catchphrase',
de: this.data.catchphrase_de,
en: this.data.catchphrase_en,
title: 'Description',
de: this.data.description_de,
en: this.data.description_en,
}),
]),
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
m(DropdownCard, { title: 'advertisement' }, [
[
m(Icon, {
style: { float: 'left' },
svg: m.trust(this.data.show_annonce ? icons.checked : icons.clear),
}),
m('span', { style: { float: 'left' } }, 'annonce'),
m(Icon, {
style: { float: 'left' },
svg: m.trust(this.data.show_infoscreen ? icons.checked : icons.clear),
}),
m('span', { style: { float: 'left' } }, 'infoscreen'),
m(Icon, {
style: { float: 'left' },
svg: m.trust(this.data.show_website ? icons.checked : icons.clear),
}),
m('span', { style: { float: 'left' } }, 'website'),
],
this.data.time_advertising_start ? m(
Property,
'Advertising Time',
`${dateFormatter(this.data.time_advertising_start)} - ${dateFormatter(this.data.time_advertising_end)}`,
) : '',
this.data.priority ? m(
Property,
{ title: 'Priority' },
`${this.data.priority}`,
) : '',
]),
m(DropdownCard, { title: 'Registration' }, [
this.data.price ? m(Property, 'Price', `${this.data.price}`) : '',
this.data.time_register_start ? m(
Property,
{ title: 'Registration Time' },
`${dateFormatter(this.data.time_register_start)} - ${dateFormatter(this.data.time_register_end)}`,
) : '',
this.data.selection_strategy ? m(
Property,
{ title: 'Selection Mode' },
m.trust(this.data.selection_strategy),
) : '',
this.data.allow_email_signup ? m(Property, 'non AMIV-Members allowed') : '',
]),
// a list of email adresses of all participants, easy to copy-paste
m(DropdownCard, { title: 'Email Adresses' }, [
m(Switch, {
defaultChecked: false,
label: 'show unaccepted',
onChange: () => {
this.showAllEmails = !this.showAllEmails;
this.setUpEmailList(this.showAllEmails);
},
}),
m(EmailList, { list: this.emaillist }),
]),
]),
m('div.eventViewRight', [
m('h4', 'Accepted Participants'),
m(ParticipantsTable, { where: { accepted: true, event: this.data._id } }),
m('p', ''),
m('h4', 'Participants on Waiting List'),
m(ParticipantsTable, { where: { accepted: false, event: this.data._id } }),
]),
]),
]);
}