Newer
Older
import { Button, Checkbox, RadioGroup, IconButton, SVG, TextField } from 'polythene-mithril';
import { icons, textInput, datetimeInput } from '../views/elements';
const style = [
{
'.mywrapper': {
padding: '10px',
},
},
];
styler.add('event-add', style);
export default class newEvent extends EditView {
constructor(vnode) {
this.food = false;
this.sbbAbo = false;

Lionel Trebuchon
committed
this.data = {};
}
addOne() {
this.currentpage = this.currentpage + 1;
if (this.currentpage === 5) {
this.currentpage = 4;
if (this.currentpage === 6) {
this.currentpage = 6;
}
subOne() {
this.currentpage = this.currentpage - 1;
if (this.currentpage === 0) {
this.currentpage = 1;
}
if (this.currentpage === 6) {
this.currentpage = 6;
}
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,
},
};
const thirdTableInputs = {
spots: {
label: 'Number of Spots',
help: '0 for open event',
focusHelp: true,
time_register_start: {
label: 'Start of Registration',
time_register_end: {
label: 'End of Registration',
const forthTableInputs = {
time_advertising_start: {
label: 'Start of Advertisement',
type: 'datetime',
required: true,
time_advertising_end: {
label: 'End of Advertisement',
required: true,
},
priority: {
label: 'Priority',

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

Lionel Trebuchon
committed
IconButton,
{ events: { onclick: () => { this.subOne(); } } },
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);
},
});
const checkboxWebsite = m(Checkbox, {
defaultChecked: false,
label: 'Advertise on Website?',
value: '100',
onChange: (state) => {
this.show_website = state.checked;
},
});
const checkboxInfoScreen = m(Checkbox, {
defaultChecked: false,
label: 'Advertise on Infoscreen?',
value: '100',
onChange: (state) => {
this.show_infoscreen = state.checked;
},
});
const checkboxAllowMail = m(Checkbox, {
defaultChecked: false,
label: 'Allow non AMIV Members?',
value: '100',
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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,
});
const radioButtonSelectionMode = m(RadioGroup, {
name: 'Selection Mode',
buttons: [
{
value: 'fcfs',
label: 'First come, first serve',
},
{
value: 'manual',
label: 'Selection made by organizer',
},
],

Lionel Trebuchon
committed
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,
197
198
199
200
201
202
203
204
205
206
207
208
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
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');
},
},
});
'Create an Event', 'When and Where?', 'Signups', 'Advertisement',
// checks currentPage and selects the fitting page
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,
})),
]),
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,
]),
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!',
]),