diff --git a/src/events/viewEvent.js b/src/events/viewEvent.js index fece3982ed3b26f8aa780e9ad93dbe527a30b2a1..ec10e36d85312648e80b21cc4ba20520af068d34 100644 --- a/src/events/viewEvent.js +++ b/src/events/viewEvent.js @@ -1,5 +1,5 @@ import m from 'mithril'; -import { Checkbox, Button, Card, TextField, IconButton, Toolbar, ToolbarTitle } from 'polythene-mithril'; +import { Switch, Button, Card, TextField, IconButton, Toolbar, ToolbarTitle, MaterialDesignSpinner as Spinner } from 'polythene-mithril'; import ItemView from '../views/itemView'; import { events as config, eventsignups as signupConfig } from '../config.json'; import TableView from '../views/tableView'; @@ -7,12 +7,13 @@ import DatalistController from '../listcontroller'; import { dateFormatter } from '../utils'; import { icons } from '../views/elements'; import { styler } from 'polythene-core-css'; +import {ResourceHandler} from "../auth"; const viewLayout = [ { '.eventViewContainer': { display: 'grid', - 'grid-template-columns': '50% 50%', + 'grid-template-columns': '40% 55%', 'grid-gap': '50px', }, '.eventViewLeft': { @@ -63,12 +64,40 @@ class ParticipantsTable { } } +class EmailList { + view({ attrs: { list } }) { + const emails = list.toString().replace(/,/g, '; '); + return m(Card, { + content: m(TextField, { value: emails, label: '', multiLine: true }, ''), + }); + } +} + export default class viewEvent extends ItemView { constructor() { super('events'); + this.signupHandler = new ResourceHandler('eventsignups'); this.details = false; - this.waitlist = false; this.emailAdresses = false; + + + this.emaillist = ['']; + this.showAllEmails = false; + this.setUpEmailList(this.showAllEmails); + } + + setUpEmailList(showAll) { + if (!showAll) { + this.signupHandler.get({ where: { accepted: true } }).then((data) => { + this.emaillist = (data._items.map(item => item.email)); + }); + } + else { + this.signupHandler.get({}).then((data) => { + this.emaillist = (data._items.map(item => item.email)); + }); + } + m.redraw(); } view() { @@ -112,10 +141,6 @@ export default class viewEvent extends ItemView { m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }), m(ToolbarTitle, { text: "details" }), ]); - let displayWaitlistButton = m(Toolbar, { compact: true, events: { onclick: () => this.waitlist = !this.waitlist } }, [ - m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }), - m(ToolbarTitle, { text: "waitlist" }), - ]); let displayEmailAdressesButton = m(Toolbar, { compact: true, events: { onclick: () => this.emailAdresses = !this.emailAdresses } }, [ m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }), m(ToolbarTitle, { text: "email adresses" }), @@ -184,40 +209,6 @@ export default class viewEvent extends ItemView { }) } - if (this.waitlist) { - displayWaitlistButton = m(Toolbar, { compact: true, events: { onclick: () => this.waitlist = !this.waitlist } }, [ - m(IconButton, { icon: { svg: m.trust(icons.ArrowDown) } }), - m(ToolbarTitle, { text: "waitlist" }), - ]); - displayWaitlist = m(Card, { - content: [ - { - primary: { - title: "Primary title", - subtitle: "Subtitle" - } - }, - { - actions: { - content: [ - m(Button, { - label: "Action 1" - }), - m(Button, { - label: "Action 2" - }) - ] - } - }, - { - text: { - content: "More text" - } - } - ] - - }) - } if (this.emailAdresses) { displayEmailAdressesButton = m(Toolbar, { compact: true, events: { onclick: () => this.emailAdresses = !this.emailAdresses } }, [ @@ -227,31 +218,28 @@ export default class viewEvent extends ItemView { displayEmailAdresses = m(Card, { content: [ { - primary: { - title: "Primary title", - subtitle: "Subtitle" - } - }, - { - actions: { - content: [ - m(Button, { - label: "Action 1" + any: + { + content: m(Switch, { + defaultChecked: false, + label: 'show unaccepted', + onChange: () => { + this.showAllEmails = !this.showAllEmails; + this.setUpEmailList(this.showAllEmails); + + }, }), - m(Button, { - label: "Action 2" - }) - ] - } + }, }, { - text: { - content: "More text" - } - } - ] + any: + { + content: m(EmailList, { list: this.emaillist }), + } + }, + ], - }) + }); } @@ -266,9 +254,6 @@ export default class viewEvent extends ItemView { displayDetailsButton, displayDetails, - displayWaitlistButton, - displayWaitlist, - displayEmailAdressesButton, displayEmailAdresses, ]),