Skip to content
Snippets Groups Projects
newEvent.js 7.86 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;
    this.food = false;
    this.sbbAbo = false;
aneff's avatar
aneff committed
  }
  addOne() {
    this.currentpage = this.currentpage + 1;
Hermann's avatar
Hermann committed
    if (this.currentpage === 5) {
      this.currentpage = 4;
    if (this.currentpage === 6) {
      this.currentpage = 6;
    }
aneff's avatar
aneff committed
  subOne() {
    this.currentpage = this.currentpage - 1;
    if (this.currentpage === 0) {
      this.currentpage = 1;
    }
    if (this.currentpage === 6) {
      this.currentpage = 6;
    }
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(); } } },
aneff's avatar
aneff committed
      m(SVG, m.trust(icons.ArrowRight)),
    );

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

    const checkboxAnnounce = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise in Announce?',
      value: '100',
      onChange: (state) => {
        this.show_announce = state.checked;
        console.log(this.show_announce);
      },
aneff's avatar
aneff committed
    });

    const checkboxWebsite = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise on Website?',
      value: '100',
      onChange: (state) => {
        this.show_website = state.checked;
      },
aneff's avatar
aneff committed
    });

    const checkboxInfoScreen = m(Checkbox, {
      defaultChecked: false,
      label: 'Advertise on Infoscreen?',
      value: '100',
      onChange: (state) => {
        this.show_infoscreen = state.checked;
      },

aneff's avatar
aneff committed
    });

    const checkboxAllowMail = m(Checkbox, {
      defaultChecked: false,
      label: 'Allow non AMIV Members?',
      value: '100',
      onChange: (state) => {
        this.allow_email_signup = state.checked;
      },
      checked: this.allow_email_signup,
    });

    const addFood = m(Checkbox, {
      defaultChecked: false,
      label: 'Food limitations',
      value: '100',
      onChange: (state) => {
        this.food = state.checked;
        console.log(this.food);
      },
      checked: this.food,
    });

    const addSBB = m(Checkbox, {
      defaultChecked: false,
      label: 'SBB ABO',
      value: '100',
      onChange: (state) => {
        this.sbbAbo = state.checked;
        console.log(this.sbbAbo);
      },
      checked: this.sbbAbo,
aneff's avatar
aneff committed
    });

    const radioButtonSelectionMode = m(RadioGroup, {
      name: 'Selection Mode',
      buttons: [
        {
          value: 'fcfs',
          label: 'First come, first serve',
        },
        {
          value: 'manual',
          label: 'Selection made by organizer',
        },
      ],
      onChange: (state) => {
        this.selection_strategy = state.value;
        this.data.selection_strategy = state.value;
        console.log(this.data); // Temp proof of concept.
      },
      value: this.selection_strategy,
    const buttonFinish = m(Button, {
      label: 'Create event',
      events: {
        onclick: () => {
          const additionalFields = {
            title: 'Additional Fields',
            type: 'object',
            properties: {},
            required: [],
          };
          if (this.sbbAbo) {
            additionalFields.properties.SBB_Abo = {
              type: 'string',
              enum: ['None', 'GA', 'Halbtax', 'Gleis 7'],
            };
            additionalFields.required.push('SBB_Abo');
          }

          if (this.food) {
            additionalFields.properties.Food = {
              type: 'string',
              enum: ['Omnivor', 'Vegi', 'Vegan', 'Other'],
            };
            additionalFields.properties.specialFood = {
              'Special Food Requirements': {
                type: 'string',
              },
            };
            additionalFields.required.push('Food');
          }
          this.data.additional_fields = additionalFields;
          console.log(this.data.additional_fields);
          this.submit('POST');
        },
      },
    });

Hermann's avatar
Hermann committed
    const title = [
      'Create an Event', 'When and Where?', 'Signups', 'Advertisement',
Hermann's avatar
Hermann committed
    ][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));
        }),
        addFood, addSBB, m('br'), checkboxAllowMail, radioButtonSelectionMode,
      ]),
Hermann's avatar
Hermann committed
      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));
        }),
        checkboxWebsite, checkboxAnnounce, checkboxInfoScreen, m('br'), buttonFinish,
      ]),

      m('div', {
        style: {
          display: (this.currentpage === 6) ? 'block' : 'none',
        },
      }, ['Event created!',
      ]),

Hermann's avatar
Hermann committed
    ]);