Skip to content
Snippets Groups Projects
newEvent.js 5.07 KiB
Newer Older
Hermann's avatar
Hermann committed
import m from 'mithril';
Hermann's avatar
Hermann committed
import { Button, Checkbox, RadioGroup, IconButton, SVG, TextField } from 'polythene-mithril';
aneff's avatar
aneff committed
import { styler } from 'polythene-core-css';
Hermann's avatar
Hermann committed
import EditView from '../views/editView';
import { icons, textInput, datetimeInput } from '../views/elements';
aneff's avatar
aneff committed

const style = [
  {
    '.mywrapper': {
      padding: '10px',
    },
  },
];
styler.add('event-add', style);

Hermann's avatar
Hermann committed

export default class newEvent extends EditView {
  constructor(vnode) {
aneff's avatar
aneff committed
    super(vnode, 'events', {});
aneff's avatar
aneff committed
    this.currentpage = 1;
  }

  addOne() {
    this.currentpage = this.currentpage + 1;
Hermann's avatar
Hermann committed
    if (this.currentpage === 5) {
      this.currentpage = 4;
aneff's avatar
aneff committed
  subOne() {
    this.currentpage = this.currentpage - 1;
    if (this.currentpage === 0) {
      this.currentpage = 1;
    }
  }

aneff's avatar
aneff committed
  view() {
aneff's avatar
aneff committed
    if (!this.currentpage) return '';

Hermann's avatar
Hermann committed
    const firstTableInputs = {
      title_en: {
        label: 'English Event Title',
      },
      catchphrase_en: {
        label: 'English Catchphrase',
      },
      description_en: {
        label: 'English Description',
        multiLine: true,
        rows: 5,
      },
      title_de: {
        label: 'German Event Title',
      },
      catchphrase_de: {
        label: 'German Catchphrase',
      },
      description_de: {
        label: 'German Description',
        multiLine: true,
        rows: 5,
      },
    };
Hermann's avatar
Hermann committed
    const thirdTableInputs = {
      spots: {
        label: 'Number of Spots',
        help: '0 for open event',
        focusHelp: true,
aneff's avatar
aneff committed
      },
Hermann's avatar
Hermann committed
      price: {
        label: 'Price',
aneff's avatar
aneff committed
      },
Hermann's avatar
Hermann committed
      time_register_start: {
        label: 'Start of Registration',
aneff's avatar
aneff committed
      },
Hermann's avatar
Hermann committed
      time_register_end: {
        label: 'End of Registration',
aneff's avatar
aneff committed
      },
Hermann's avatar
Hermann committed
    };
Hermann's avatar
Hermann committed
    const forthTableInputs = {
      time_advertising_start: {
        label: 'Start of Advertisement',
        type: 'datetime',
        required: true,
aneff's avatar
aneff committed
      },
Hermann's avatar
Hermann committed
      time_advertising_end: {
        label: 'End of Advertisement',
        required: true,
      },
      priority: {
        label: 'Priority',
      }
    };
aneff's avatar
aneff committed

    const iconRight = m(
      IconButton, { events: { onclick: () => { this.addOne(); } } },
      m(SVG, m.trust(icons.ArrowRight)),
    );

    const iconLeft = m(
      IconButton, { events: { onclick: () => { this.subOne(); } } },
      m(SVG, m.trust(icons.ArrowLeft)),
    );

    const checkboxAnnounce = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise in Announce?',
      value: '100',
    });

    const checkboxWebsite = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise on Website?',
      value: '100',
    });

    const checkboxInfoScreen = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise on Infoscreen?',
      value: '100',
    });

    const checkboxAllowMail = m(Checkbox, {
      defaultChecked: false,
      label: 'Allow non AMIV Members?',
      value: '100',
    });

    const radioButtonSelectionMode = m(RadioGroup, {
      name: 'Selection Mode',
      buttons: [
        {
          value: 'fcfs',
          label: 'First come, first serve',
        },
        {
          value: 'manual',
          label: 'Selection made by organizer',
        },
      ],
    });

Hermann's avatar
Hermann committed
    const title = [
      'Create an Event', 'When and Where?', 'Signups', 'Advertisement'
    ][this.currentpage - 1];
aneff's avatar
aneff committed
    // checks currentPage and selects the fitting page
Hermann's avatar
Hermann committed
    return m('div.mywrapper', [
      m('h1', title),
      m('br'),
      iconLeft,
      iconRight,
      m('br'),
      m('div', {
        style: {
          display: (this.currentpage === 1) ? 'block' : 'none',
        },
      }, Object.keys(firstTableInputs).map((key) => {
        const attrs = firstTableInputs[key];
        const attributes = Object.assign({}, attrs);
        attributes.name = key;
        attributes.floatingLabel = true;
        return m(textInput, this.bind(attributes));
      })),
      m('div', {
        style: {
          display: (this.currentpage === 2) ? 'block' : 'none',
        },
      }, [
        m(datetimeInput, this.bind({
          name: 'time_start',
          label: 'Event Start Time',
        })),
        m(datetimeInput, this.bind({
          name: 'time_end',
          label: 'Event End Time',
        })),
        m(textInput, this.bind({
          name: 'location',
          label: 'Location',
          floatingLabel: true,
        })),
      ]),
Hermann's avatar
Hermann committed
      m('div', {
        style: {
          display: (this.currentpage === 3) ? 'block' : 'none',
        },
      }, Object.keys(thirdTableInputs).map((key) => {
        const attrs = thirdTableInputs[key];
        const attributes = Object.assign({}, attrs);
        attributes.name = key;
        attributes.floatingLabel = true;
        return m(textInput, this.bind(attributes));
      })),
      m('div', {
        style: {
          display: (this.currentpage === 4) ? 'block' : 'none',
        },
      }, Object.keys(forthTableInputs).map((key) => {
        const attrs = forthTableInputs[key];
        const attributes = Object.assign({}, attrs);
        attributes.name = key;
        attributes.floatingLabel = true;
        return m(textInput, this.bind(attributes));
      })),
    ]);