Commit 6b82d8eb authored by Christian H's avatar Christian H
Browse files

The 'Propose' feature was Implemented,

parent 8c2929c3
......@@ -119,6 +119,7 @@ export class ResourceHandler {
*/
constructor(resource, searchKeys = false) {
this.resource = resource;
this.rights = [];
// special case for users
if (resource === 'users') this.searchKeys = ['firstname', 'lastname', 'nethz'];
else this.searchKeys = searchKeys || config[resource].searchKeys;
......@@ -203,6 +204,7 @@ export class ResourceHandler {
Snackbar.show({ title: response.data, style: { color: 'red' } });
reject();
} else {
this.rights = response.data._links.self.methods;
resolve(response.data);
}
}).catch((e) => {
......
import m from 'mithril';
import { RaisedButton, RadioGroup, Switch } from 'polythene-mithril';
import { RaisedButton, RadioGroup, Switch, Dialog, Button } from 'polythene-mithril';
import { fileInput } from 'amiv-web-ui-components';
import { styler } from 'polythene-core-css';
// eslint-disable-next-line import/extensions
import { apiUrl } from 'networkConfig';
import { apiUrl, ownUrl } from 'networkConfig';
import EditView from '../views/editView';
const style = [
......@@ -94,24 +94,63 @@ export default class newEvent extends EditView {
delete this.form.data.allow_email_signup;
}
console.log(this.form.data);
if (Object.keys(images).length > 0) {
images._id = this.form.data._id;
images._etag = this.form.data._etag;
// first upload the images as formData, then the rest as JSON
this.controller.handler.patch(images, true).then(({ _etag }) => {
this.form.data._etag = _etag;
// Propose <=> Submit desicion due to rights
if (m.route.get() === '/newevent') {
// Submition tool
if (Object.keys(images).length > 0) {
images._id = this.form.data._id;
images._etag = this.form.data._etag;
// first upload the images as formData, then the rest as JSON
this.controller.handler.patch(images, true).then(({ _etag }) => {
this.form.data._etag = _etag;
this.submit();
});
} else {
this.submit();
});
}
} else {
this.submit();
// Propose tool
Dialog.show({
title: 'Congratulations!',
body: [
m(
'div',
'You sucessfuly setup an event.',
'Please send this link to the respectiv board member for validation.',
),
m('input', {
type: 'text',
style: { width: '335px' },
value: `${ownUrl}/newevent?proposition=${window.btoa(JSON.stringify(this.form.data))}`,
id: 'textId',
}),
],
backdrop: true,
footerButtons: [
m(Button, {
label: 'Copy',
events: {
onclick: () => {
const copyText = document.getElementById('textId');
copyText.select();
document.execCommand('copy');
},
},
}),
],
});
}
}
view() {
const rightSubmit = (m.route.get() === '/newevent');
const titles = ['Event Description', 'When and Where?', 'Signups', 'Advertisement'];
if (rightSubmit) titles.push('Images');
const buttonRight = m(RaisedButton, {
label: 'next',
disabled: this.currentpage === 5,
disabled: this.currentpage === titles.length,
ink: false,
events: {
onclick: () => {
......@@ -146,7 +185,6 @@ export default class newEvent extends EditView {
onChange: (state) => {
this.selection_strategy = state.value;
this.form.data.selection_strategy = state.value;
console.log(this.form.data); // Temp proof of concept.
},
value: this.selection_strategy,
});
......@@ -168,9 +206,6 @@ export default class newEvent extends EditView {
if (this.form.errors && key in this.form.errors) return this.form.errors[key].length > 0;
return false;
}).includes(true));
const titles = [
'Event Description', 'When and Where?', 'Signups', 'Advertisement', 'Images',
];
// checks currentPage and selects the fitting page
return this.layout([
......@@ -342,6 +377,6 @@ export default class newEvent extends EditView {
'padding-top': '20px',
},
}, [buttonLeft, buttonRight]),
]);
], rightSubmit ? 'submit' : 'propose');
}
}
......@@ -46,7 +46,14 @@ export default class EventTable {
}]],
// per default, enable the 'upcoming' filter
initFilterIdxs: [[0, 0]],
onAdd: () => { m.route.set('/newevent'); },
onAdd: (this.handler.rights.length > 0) ?
() => {
if (this.handler.rights.includes('POST')) {
m.route.set('/newevent');
} else {
m.route.set('/proposeevent');
}
} : false,
});
}
}
......@@ -330,4 +330,4 @@ export default class viewEvent extends ItemView {
}),
]);
}
}
\ No newline at end of file
}
......@@ -32,6 +32,7 @@ m.route(root, '/events', {
'/events': layoutWith(EventTable),
'/events/:id': layoutWith(EventItem),
'/newevent': layoutWith(EventItem),
'/proposeevent': layoutWith(EventItem),
'/draftevent': layoutWith(eventDraft),
'/eventwithexport': layoutWith(eventWithExport),
'/groups': layoutWith(GroupList),
......
......@@ -84,7 +84,7 @@ export default class EditView extends ItemView {
this.submit();
}
layout(children) {
layout(children, buttonLabel = 'submit') {
return m('div', { style: { 'background-color': 'white' } }, [
m(Toolbar, { style: { 'background-color': colors.orange } }, [
m(IconButton, {
......@@ -95,7 +95,8 @@ export default class EditView extends ItemView {
` ${this.resource.charAt(0).toUpperCase()}${this.resource.slice(1, -1)}`),
m(Button, {
className: 'blue-button-filled',
label: 'submit',
extraWide: true,
label: buttonLabel,
disabled: !this.form.valid,
events: { onclick: () => { this.beforeSubmit(); } },
}),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment