diff --git a/src/eventTool.js b/src/eventTool.js index 2cdf9fa59ef35f55b9cf7a5e64c1ba79d6b3205b..92d9af899a075f1dc27822e2377ff4380d5b7028 100644 --- a/src/eventTool.js +++ b/src/eventTool.js @@ -164,14 +164,3 @@ export class EventModal { ]); } } - -export class EventTable { - view() { - return m(TableView, { - resource: 'events', - keys: config.tableKeys, - titles: config.tableKeys.map(key => config.keyDescriptors[key] || key), - onAdd: () => { m.route.set('/newevent'); }, - }); - } -} diff --git a/src/events/newEvent.js b/src/events/newEvent.js index 4f808126d9eebd096179510361d817272e9e1d65..d553ff6ca89881c7edf2e4a5ca38ac6c400a137e 100644 --- a/src/events/newEvent.js +++ b/src/events/newEvent.js @@ -1,5 +1,5 @@ import m from 'mithril'; -import { Button, Checkbox, RadioGroup, IconButton, SVG } from 'polythene-mithril'; +import { Button, Checkbox, RadioGroup, IconButton, SVG, TextField } from 'polythene-mithril'; import { styler } from 'polythene-core-css'; import EditView from '../views/editView'; import { icons, textInput } from '../views/elements'; @@ -22,10 +22,9 @@ export default class newEvent extends EditView { addOne() { this.currentpage = this.currentpage + 1; - if (this.currentpage === 4) { - this.currentpage = 3; + if (this.currentpage === 5) { + this.currentpage = 4; } - //m.redraw(); } subOne() { @@ -33,166 +32,84 @@ export default class newEvent extends EditView { if (this.currentpage === 0) { this.currentpage = 1; } - //m.redraw(); } view() { if (!this.currentpage) return ''; - // German and English Information - const fieldTitleEn = m(textInput, this.bind({ - name: 'title_en', - label: 'Event Title [EN]', - required: true, - floatingLabel: true, - })); - const fieldCatchphraseEn = m(textInput, this.bind({ - name: 'catchphrase_en', - label: 'Catchphrase [EN]', - floatingLabel: true, - help: 'Fun description to make your event look more interesting than it is', - focusHelp: true, - })); - - const fieldDescriptionEn = m(textInput, this.bind({ - name: 'description_en', - label: 'Description [EN]', - required: true, - floatingLabel: true, - multiLine: true, - rows: 6, - })); - - const fieldTitleDe = m(textInput, this.bind({ - name: 'title_de', - label: 'Event Title [DE]', - floatingLabel: true, - })); - - const fieldCatchphraseDe = m(textInput, this.bind({ - name: 'catchphrase_de', - label: 'Catchphrase [DE]', - floatingLabel: true, - help: 'Fun description to make your event look more interesting than it is', - focusHelp: true, - })); - - const fieldDescriptionDe = m(textInput, this.bind({ - name: 'description_de', - label: 'Description [DE]', - floatingLabel: true, - multiLine: true, - rows: 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, + }, + }; - // Start of relevant data + const secondTableInputs = { + location: { + label: 'Location', + }, + time_start: { + label: 'Event Start [Date and Time]:', + help: 'Format: 01.01.1970-18:00', + focusHelp: true, + }, + time_end: { + label: 'Event End [Date and Time]:', + help: 'Format: 01.01.1970-1800', + focusHelp: true, + }, - const fieldPrice = m(textInput, this.bind({ - name: 'price', - label: 'Price:', - type: 'number', - help: 'In Rappen/Cents', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldStartDate = m(textInput, this.bind({ - name: 'time_start', - label: 'Event Start[Date and Time]:', - help: 'Format: 01.01.1970-18:00', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldEndDate = m(textInput, this.bind({ - name: 'time_end', - label: 'Event End[Date and Time]:', - help: 'Format: 01.01.1970-1800', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldStartRegDate = m(textInput, this.bind({ - name: 'time_register_start', - label: 'Registration Start[Date and Time]:', - help: 'Format: 01.01.1970-18:00', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldEndRegDate = m(textInput, this.bind({ - name: 'time_register_end', - label: 'Registration End[Date and Time]:', - help: 'Format: 01.01.1970-1800', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldLocation = m(textInput, this.bind({ - name: 'location', - label: 'Location:', - floatingLabel: true, - required: true, - })); - const fieldNumberOfParticipants = m(textInput, this.bind({ - name: 'spots', - label: 'Number of open spots:', - type: 'number', - floatingLabel: true, - required: true, - })); - const fieldAdvStart = m(textInput, this.bind({ - name: 'time_advertising_start', - label: 'Registration Start[Date and Time]:', - type: 'datetime', - help: 'Format: 01.01.1970-18:00', - focusHelp: true, - floatingLabel: true, - required: true, - })); - const fieldAdvEnd = m(textInput, this.bind({ - name: 'time_advertising_end', - label: 'Registration End[Date and Time]:', - help: 'Format: 01.01.1970-1800', - focusHelp: true, - floatingLabel: true, - required: true, - })); + }; - const buttonBannerUp = m(Button, { - label: 'Select Banner File', - events: { - onclick: () => console.log('click'), + const thirdTableInputs = { + spots: { + label: 'Number of Spots', + help: '0 for open event', + focusHelp: true, }, - }); - - const buttonInfoUp = m(Button, { - label: 'Select Infoscreen File', - events: { - onclick: () => console.log('click'), + price: { + label: 'Price', }, - }); - - const buttonPosterUp = m(Button, { - label: 'Select Poster File', - events: { - onclick: () => console.log('click'), + time_register_start: { + label: 'Start of Registration', }, - }); - - const buttonThumbUp = m(Button, { - label: 'Select Thumbnail File', - events: { - onclick: () => console.log('click'), + time_register_end: { + label: 'End of Registration', }, - }); + }; - const buttonUploadAll = m(Button, { - label: 'Upload', - events: { - onclick: () => console.log('click'), + 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', + } + }; const iconRight = m( IconButton, { events: { onclick: () => { this.addOne(); } } }, @@ -242,43 +159,61 @@ export default class newEvent extends EditView { ], }); - function layoutWith(page) { - return m('div.mywrapper', page); - } + const title = [ + 'Create an Event', 'When and Where?', 'Signups', 'Advertisement' + ][this.currentpage - 1]; - const page1 = { - view: function () { - return layoutWith(m( - 'h1', 'Event description:', m('br'), iconLeft, iconRight, m('br'), - fieldTitleEn, fieldCatchphraseEn, fieldDescriptionEn, fieldTitleDe, - )); - }, - }; - const page2 = { - view: function () { - return layoutWith(m( - 'h1', 'Critical Information:', m('br'), iconLeft, iconRight, m('br'), fieldStartDate, fieldEndDate, fieldStartRegDate, - fieldEndRegDate, fieldLocation, fieldPrice, fieldNumberOfParticipants, - )); - }, - }; - const page3 = { - view: function () { - return layoutWith(m( - 'h1', 'Advertise Information', m('br'), iconLeft, iconRight, m('br'), fieldAdvStart, fieldAdvEnd, checkboxWebsite, - checkboxAnnounce, checkboxInfoScreen, m('br'), buttonBannerUp, buttonInfoUp, buttonPosterUp, - buttonThumbUp, m('br'), buttonUploadAll, m('br'), checkboxAllowMail, radioButtonSelectionMode, - )); - }, - }; // checks currentPage and selects the fitting page - if (this.currentpage === 1) { - return m(page1); - } else if (this.currentpage === 2) { - return m(page2); - } else if (this.currentpage === 3) { - return m(page3); - } - return layoutWith(m('')); + 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', + }, + }, Object.keys(secondTableInputs).map((key) => { + const attrs = secondTableInputs[key]; + const attributes = Object.assign({}, attrs); + attributes.name = key; + attributes.floatingLabel = true; + return m(textInput, this.bind(attributes)); + })), + 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)); + })), + ]); } } diff --git a/src/views/editView.js b/src/views/editView.js index 180a82c00f8f76d044c88723343365cbfba1973f..4b2c4b0badfccf4ae7f8afb03279c977c30e3823 100644 --- a/src/views/editView.js +++ b/src/views/editView.js @@ -57,8 +57,16 @@ export default class EditView extends ItemView { m.request(`${apiUrl}docs/api-docs`).then((schema) => { const objectSchema = schema.definitions[ objectNameForResource[this.resource]]; - console.log(schema); - //this.ajv.addSchema(objectSchema, 'schema'); + console.log(objectSchema); + // filter out any field that is of type media and replace with type + // object + Object.keys(objectSchema.properties).forEach((property) => { + if (objectSchema.properties[property].type === 'media' || + objectSchema.properties[property].type === 'json_schema_object') { + objectSchema.properties[property].type = 'object'; + } + }); + this.ajv.addSchema(objectSchema, 'schema'); }); } @@ -73,10 +81,10 @@ export default class EditView extends ItemView { // bind changed data this.data[name] = value; - //console.log(this.data); + console.log(this.data); // validate against schema - /*const validate = this.ajv.getSchema('schema'); + const validate = this.ajv.getSchema('schema'); this.valid = validate(this.data); console.log(validate.schema); @@ -92,7 +100,7 @@ export default class EditView extends ItemView { `.${field}` === error.dataPath); this.errors[field] = errors.map(error => error.message); }); - }*/ + } }, getErrors: () => this.errors[attrs.name], value: this.data[attrs.name],