Commit c832dc37 authored by Christian H's avatar Christian H
Browse files

The Clone Event button implemented for present & past events

parent 422799f1
......@@ -5,6 +5,7 @@ import { styler } from 'polythene-core-css';
// eslint-disable-next-line import/extensions
import { apiUrl } from 'networkConfig';
import EditView from '../views/editView';
import { colors } from '../style';
const style = [
......@@ -34,7 +35,7 @@ export default class newEvent extends EditView {
// if it is 0 however, that would mean that there actually is a price that
// you can edit
this.hasprice = 'price' in this.form.data && this.form.data.price !== null;
this.hasregistration = 'time_advertising_start' in this.form.data;
this.hasregistration = 'spots' in this.form.data || 'time_registration_start' in this.form.data;
}
beforeSubmit() {
......@@ -150,17 +151,46 @@ export default class newEvent extends EditView {
value: this.selection_strategy,
});
const title = [
const keysPages = [
['title_en', 'catchphrase_en', 'description_en', 'title_de', 'catchphrase_de', 'description_de'],
['time_start', 'time_end', 'location'],
['price', 'spots', 'time_register_start', 'time_register_end' ],
['time_advertising_start', 'time_advertising_end'],
[],
]
const errorPages = keysPages.map(keysOfOnePage => keysOfOnePage.map((key) => {
if (this.form.errors && key in this.form.errors) return this.form.errors[key].length > 0
else return false;
}).includes(true));
const titles = [
'Event Description', 'When and Where?', 'Signups', 'Advertisement', 'Images',
][this.currentpage - 1];
];
// checks currentPage and selects the fitting page
return this.layout([
m('h3', title),
buttonLeft,
m.trust(' '),
buttonRight,
m('br'),
// new developed navigation bar
// all pages are displayed, current is highlighted, validation errors are shown per page by red icon-background
m('div',
{ style: { display: 'flex', 'justify-content': 'space-around', 'flex-wrap': 'wrap' } },
[...titles.entries()].map(numAndTitle => m('div',
m('div', {
style: {
border: (this.currentpage === numAndTitle[0]+1) ? '2px solid black' : '2px solid #888888',
color: (this.currentpage === numAndTitle[0]+1) ? 'black' : '#888888',
'background-color': errorPages[numAndTitle[0]] ? '#ff7a56' : 'white',
'border-radius':'20px',
height: '40px',
'margin-bottom': '7px',
padding: '12px',
'font-size': '20px',
'line-height': '11px',
},
onclick: () => {this.currentpage = numAndTitle[0]+1;},
}, numAndTitle[1]))
)
),
m('div', {
style: { display: (this.currentpage === 1) ? 'block' : 'none' },
}, this.form.renderPage({
......
......@@ -5,6 +5,7 @@ import {
ToolbarTitle,
Card,
TextField,
Button,
} from 'polythene-mithril';
import { styler } from 'polythene-core-css';
import { DropdownCard } from 'amiv-web-ui-components';
......@@ -17,6 +18,7 @@ import RelationlistController from '../relationlistcontroller';
import { dateFormatter } from '../utils';
import { icons, Property, chip } from '../views/elements';
import { ResourceHandler } from '../auth';
import { colors } from '../style';
const viewLayout = [
{
......@@ -148,6 +150,41 @@ export default class viewEvent extends ItemView {
});
}
cloneEvent() {
const event = Object.assign({}, this.data);
console.log(event);
const eventInfoToDelete = [
'_id',
'_created',
'_etag',
'_links',
'_updated',
'signup_count',
'__proto__',
];
const now = new Date();
console.log(`${now.toISOString().slice(0, -5)}Z`);
if (event.time_end < `${now.toISOString().slice(0, -5)}Z`) {
eventInfoToDelete.push(...[
'time_advertising_end',
'time_advertising_start',
'time_end',
'time_register_end',
'time_register_end',
'time_register_start',
'time_start']);
}
eventInfoToDelete.forEach((key) => {
delete event[key];
});
console.log(event);
this.controller.changeModus('new');
this.controller.data = event;
}
view() {
let displaySpots = '-';
const stdMargin = { margin: '5px' };
......@@ -274,6 +311,29 @@ export default class viewEvent extends ItemView {
]),
]),
], [
m(Button, {
label: 'Clone Event',
border: true,
style: {
color: colors.light_blue,
'border-color': colors.light_blue,
},
events: {
// opens 'new event' ,
// coping All information but the 'event_id', past dates and API generated properties
onclick: () => this.cloneEvent(),
},
}),
]);
}
}
/*
m(Button, {
element: 'div',
className: 'itemView-edit-button',
label: `Edit ${this.resource.charAt(0).toUpperCase()}${this.resource.slice(1, -1)}`,
events: { onclick: () => { this.controller.changeModus('edit'); } },
}),
*/
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