Skip to content
Snippets Groups Projects
viewEvent.js 16.3 KiB
Newer Older
Hermann's avatar
Hermann committed
import m from 'mithril';
import {
  Switch,
  Button,
  Card,
  TextField,
  IconButton,
  Toolbar,
  ToolbarTitle,
} from 'polythene-mithril';
import { styler } from 'polythene-core-css';
Hermann's avatar
Hermann committed
import ItemView from '../views/itemView';
import { eventsignups as signupConfig } from '../config.json';
import TableView from '../views/tableView';
import DatalistController from '../listcontroller';
import { dateFormatter } from '../utils';
carol's avatar
carol committed
import { icons } from '../views/elements';
import { ResourceHandler } from '../auth';
Hermann's avatar
Hermann committed
import { apiUrl } from '../config';
    '.eventViewContainer': {
Hermann's avatar
Hermann committed
        display: 'grid',
        'grid-template-columns': '40% 55%',
        'grid-gap': '50px',
    },
    '.propertyTitle': {
        color: 'rgba(0, 0, 0, 0.54)',
    },
    '.propertyText': {
        color: 'rgba(0, 0, 0, 0.87)',
    },
    '.propertyLangIndicator': {
        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',
    },
    '.eventInfoCard': {
      padding: '10px',
        'font-size': '15sp',
    },
    '.eventViewLeft': {
Hermann's avatar
Hermann committed
        'grid-column': 1,
    },
    '.eventViewRight': {
Hermann's avatar
Hermann committed
        'grid-column': 2,
    },
    '.eventViewRight h4': {
Hermann's avatar
Hermann committed
            'margin-top': '0px',
class PropertyInfo {
    view({ attrs: { title, de, en } }) {
        //const text = '';

        if(de && en) {
            return m('div',
                m('p.propertyTitle', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [title]),
                m('div', [
                    m('div', { className: 'propertyLangIndicator' }, 'DE'),
                    m('p.propertyText', de),
                ]),
                m('div', [
                    m('div', { className: 'propertyLangIndicator' }, 'EN'),
                    m('p.propertyText', en ),
                ]),
            )
        } else if(de) {
            return m('div',
                m('p.propertyTitle', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [title]),
                m('div', [
                    m('div', { className: 'propertyLangIndicator' }, 'DE'),
                    m('p.propertyText', de),
                ]),
            )
        } else if(en) {
            return m('div',
                m('p.propertyTitle', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [title]),
                m('div', [
                    m('div', { className: 'propertyLangIndicator' }, 'EN'),
                    m('p.propertyText', en),
                ]),
            )
        }
    }
}
class ParticipantsTable {
  constructor({ attrs: { where } }) {
Hermann's avatar
Hermann committed
    this.ctrl = new DatalistController(
      'eventsignups', {
        embedded: { user: 1 },
        where,
      },
      [
        'email',
        'user.firstname',
        'user.lastname',
      ],
      false,
    );
  }

  getItemData(data) {
    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, {
Hermann's avatar
Hermann committed
      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' },
        ],
      }),
    });
  }
}

Kai Ott's avatar
Kai Ott committed
class EmailList {
  view({ attrs: { list } }) {
    const emails = list.toString().replace(/,/g, '; ');
    return m(Card, {
      content: m(TextField, { value: emails, label: '', multiLine: true }, ''),
    });
  }
Hermann's avatar
Hermann committed
export default class viewEvent extends ItemView {
  constructor() {
    super('events');
    this.signupHandler = new ResourceHandler('eventsignups');
carol's avatar
carol committed
    this.description = false;
    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);
  }
  setUpEmailList(showAll) {
    if (!showAll) {
      this.signupHandler.get({ where: { accepted: true } }).then((data) => {
        this.emaillist = (data._items.map(item => item.email));
Kai Ott's avatar
Kai Ott committed
        m.redraw();
      });
    } else {
      this.signupHandler.get({}).then((data) => {
        this.emaillist = (data._items.map(item => item.email));
        m.redraw();
      });
carol's avatar
carol committed
    }
carol's avatar
carol committed

    view({ attrs: { onEdit } }) {
carol's avatar
carol committed
        if (!this.data) return '';
        console.log(Object.keys(this));
        console.log(this['data']);

carol's avatar
carol committed
        let displayDescriptionButton = m(Toolbar, { compact: true, events: { onclick: () => this.description = !this.description } }, [
            m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }),
            m(ToolbarTitle, { text: "description" }),
        ]);
        let displayAdvertisementButton = m(Toolbar, { compact: true, events: { onclick: () => this.advertisement = !this.advertisement } }, [
carol's avatar
carol committed
            m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }),
            m(ToolbarTitle, { text: "advertisement" }),
        ]);
        let displayRegistrationButton = m(Toolbar, { compact: true, events: { onclick: () => this.registration = !this.registration } }, [
            m(IconButton, { icon: { svg: m.trust(icons.ArrowRight) } }),
            m(ToolbarTitle, { text: "registration" }),
carol's avatar
carol committed
        ]);
        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" }),
carol's avatar
carol committed
        ]);
carol's avatar
carol committed
        let displayDescription = null;
        let displayAdvertisement = null;
        let displayRegistration = null;
carol's avatar
carol committed
        let displayEmailAdresses = null;
carol's avatar
carol committed
        if (this.description) {
            displayDescriptionButton = m(Toolbar, { compact: true, events: { onclick: () => this.description = !this.description } }, [
carol's avatar
carol committed
                m(IconButton, { icon: { svg: m.trust(icons.ArrowDown) } }),
carol's avatar
carol committed
                m(ToolbarTitle, { text: "description" }),
carol's avatar
carol committed
            ]);
carol's avatar
carol committed
            displayDescription = m(Card, {
carol's avatar
carol committed
                content: [
                            content: [
                                m(PropertyInfo, {
                                    title: 'Catchphrase',
                                    de: this.data.catchphrase_de,
                                    en: this.data.catchphrase_en,
                                }),
                            ]
carol's avatar
carol committed
                        }
                    },
                    {
carol's avatar
carol committed
                            content: [
                                m(PropertyInfo, {
                                    title: 'Description',
                                    de: this.data.description_de,
                                    en: this.data.description_en,
carol's avatar
carol committed
                                }),
                            ]
                        }
                    },
                ]

            })
        }

        if (this.advertisement) {
            displayAdvertisementButton = m(Toolbar, { compact: true, events: { onclick: () => this.advertisement = !this.advertisement } }, [
                m(IconButton, { icon: { svg: m.trust(icons.ArrowDown) } }),
                m(ToolbarTitle, { text: "advertisement" }),
            ]);
            displayAdvertisement = m(Card, {
                className: 'eventInfoCard',

                content: [
carol's avatar
carol committed
                    {

                                m('p',
                                    [
                                        m('span', { style: { float: 'left'} }, 'annonce:'), this.data.show_annonce ? m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconCheckedSVG) }): m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconClearSVG) }  ),
                                        m('span', { style: {  float: 'left'} }, '    infoscreen:'), this.data.show_infoscreen ? m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconCheckedSVG) }): m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconClearSVG) }  ),
                                        m('span', { style: { float: 'left'} }, '    website:'), this.data.show_website ? m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconCheckedSVG) }): m(Icon, { style: { float: 'left'}, svg: m.trust(icons.iconClearSVG) }  )
                                    ]),
carol's avatar
carol committed
                        }
carol's avatar
carol committed
                    {
                        any: {
                            content: [
                                this.data.time_advertising_start ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'Advertising Time')]) : '',
                                this.data.time_advertising_start ? m('div', m('p.propertyText', ` ${dateFormatter(this.data.time_advertising_start)} - ${dateFormatter(this.data.time_advertising_end)}`)) : '',
                            ]
                        }
                    },
                    {
                        any: {
                            content: [
                                this.data.priority ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'Priority')]) : '',
                                this.data.priority ? m('div', m('p.propertyText', ` ${this.data.priority}`)) : '',
        if (this.registration) {
            displayEmailAdressesButton = m(Toolbar, { compact: true, events: { onclick: () => this.registration = !this.registration } }, [
carol's avatar
carol committed
                m(IconButton, { icon: { svg: m.trust(icons.ArrowDown) } }),
carol's avatar
carol committed
                className: 'eventInfoCard',
                content: [
                    {
                        any: {
                            content: [
                                this.data.price ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'Price')]) : '',
                                this.data.price ? m('div', m('p.propertyText', ` ${this.data.price}`)) : '',
carol's avatar
carol committed
                            ]
                        }
                    },
                    {
                        any: {
                            content: [
                                this.data.time_register_start ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'Registration Time')]) : '',
                                this.data.time_register_start ? m('div', m('p.propertyText', ` ${dateFormatter(this.data.time_register_start)} - ${dateFormatter(this.data.time_register_end)}`)) : '',
                            ]
                        }
                    },
carol's avatar
carol committed
                    {
                        any: {
                            content: [
                                this.data.selection_strategy ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'Selection strategy')]) : '',
                                this.data.selection_strategy ? m('div', m('p.propertyText', ` ${this.data.selection_strategy}`)) : '',
                            ]
                        }
                    },
                    {
                        any: {
                            content: [
                                this.data.allow_email_signup ? m('div', {style: { 'margin-top': '10px', 'margin-bottom': '3px' } }, [m('span.propertyTitle', 'non AMIV-Members allowed')]) : '',
                            ]
carol's avatar
carol committed

        if (this.emailAdresses) {
carol's avatar
carol committed
            displayEmailAdressesButton = m(Toolbar, { compact: true, events: { onclick: () => this.emailAdresses = !this.emailAdresses } }, [
                m(IconButton, { icon: { svg: m.trust(icons.ArrowDown) } }),
                m(ToolbarTitle, { text: "email adresses" }),
            ]);
carol's avatar
carol committed
            displayEmailAdresses = m(Card, {
carol's avatar
carol committed
                className: 'eventInfoCard',
carol's avatar
carol committed
                content: [
                    {
Kai Ott's avatar
Kai Ott committed
                        any:
                            {
                                content: m(Switch, {
                                    defaultChecked: false,
                                    label: 'show unaccepted',
                                    onChange: () => {
                                        this.showAllEmails = !this.showAllEmails;
                                        this.setUpEmailList(this.showAllEmails);

                                    },
carol's avatar
carol committed
                                }),
carol's avatar
carol committed
                    },
                    {
Kai Ott's avatar
Kai Ott committed
                        any:
                            {
                                content: m(EmailList, { list: this.emaillist }),
                            }
                    },
                ],
carol's avatar
carol committed

carol's avatar
carol committed
        }

carol's avatar
carol committed
        let displaySpots = '-';

        if(this.data.spots !== 0) {
            displaySpots = this.data.spots;
        }

carol's avatar
carol committed

        return m("div", {
            style: { height: '100%', 'overflow-y': 'scroll', padding: '10px'}
carol's avatar
carol committed
            },[
            m(Button, {
              element: 'div',
              label: 'Update Event',
              events: { onclick: onEdit },
            }),
Hermann's avatar
Hermann committed
            m('div', [
              this.data.img_thumbnail ? m('img', {
                src: `${apiUrl.slice(0, -1)}${this.data.img_thumbnail.file}`,
                height: '50px',
                style: { float: 'left' },
              }) : '',
              m("h1", {style: { 'margin-top': '0px', 'margin-bottom': '0px' } }, [this.data.title_de]),
            ]),
            m('div', { style: { float: 'left', 'margin-right': '20px'} }, [
carol's avatar
carol committed
                m('div', this.data.signup_count ? m('span.propertyTitle', `Signups`) : m.trust(' ')),
                m('div', this.data.signup_count ? m('p.propertyText', ` ${this.data.signup_count} / ${displaySpots}`) : m.trust(' ')),
            ]),
            m('div', { style: { float: 'left', 'margin-right': '20px'} }, [
                m('div', this.data.location ? m('span.propertyTitle', `Location`) : m.trust(' ') ),
                m('div', this.data.location ? m('p.propertyText', ` ${this.data.location}`) : m.trust(' ')),
carol's avatar
carol committed
                m('div', this.data.time_start ? m('span.propertyTitle', `Time`): m.trust(' ')),
                m('div', this.data.time_start ? m('p.propertyText', ` ${dateFormatter(this.data.time_start)} - ${dateFormatter(this.data.time_end)}`): m.trust(' ')),
carol's avatar
carol committed

            m('div.eventViewContainer', { style: { 'margin-top': '50px' } }, [
carol's avatar
carol committed
                   displayDescriptionButton,
                   displayDescription,

                   displayAdvertisementButton,
                   displayAdvertisement,

                   displayRegistrationButton,
                   displayRegistration,
carol's avatar
carol committed

                   displayEmailAdressesButton,
                   displayEmailAdresses,
               ]),
               m('div.eventViewRight', [
                   m('h4', 'Accepted Participants'),
Hermann's avatar
Hermann committed
                   m(ParticipantsTable, { where: { accepted: true, event: this.data['_id'] } }),
                   m('p', ''),
                   m('h4', 'Participants on Waiting List'),
Hermann's avatar
Hermann committed
                   m(ParticipantsTable, { where: { accepted: false, event: this.data['_id'] } }),
carol's avatar
carol committed

        ])
Hermann's avatar
Hermann committed
}