Commit 4e8f8482 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Add signup restrictions to event filter

parent f9f73fac
import m from 'mithril';
import { Button, Checkbox, Dropdown, TextField } from '../components';
import { Button, Checkbox, Dropdown, TextField, RadioGroup } from '../components';
/**
* FilterViewComponent
......@@ -33,6 +33,16 @@ import { Button, Checkbox, Dropdown, TextField } from '../components';
* ],
* },
* {
* type: 'radio',
* key: 'key_radio',
* default: 'value2',
* values: [
* { label: 'Label 1', value: 'value1' },
* { label: 'Label 2', value: 'value2' },
* { label: 'Label 3', value: 'value3' },
* ],
* },
* {
* type: 'dropdown',
* key: 'key3',
* default: 'value2',
......@@ -131,6 +141,30 @@ export default class FilterViewComponent {
});
}
_createRadioGroup(field) {
this.values[field.key] = this.values[field.key] || field.default || [];
const radioValues = JSON.parse(JSON.stringify(field.values));
return m('div.radio', [
field.label ? m('h4', field.label) : m(''),
m(RadioGroup, {
buttons: radioValues.map(value => {
const radioValue = value;
if (this.values[field.key] === value.value) {
radioValue.defaultChecked = true;
}
return radioValue;
}),
name: field.key,
onChange: state => {
this.values[field.key] = state.value;
this.notify();
},
}),
]);
}
_createDropdown(field) {
let data;
this.values[field.key] = this.values[field.key] || field.default || '';
......@@ -183,6 +217,8 @@ export default class FilterViewComponent {
views.push(this._createTextField(field));
} else if (field.type === 'checkbox') {
views.push(this._createCheckboxGroup(field));
} else if (field.type === 'radio') {
views.push(this._createRadioGroup(field));
} else if (field.type === 'dropdown') {
views.push(this._createDropdown(field));
} else if (field.type === 'button') {
......
......@@ -94,6 +94,9 @@
"events.price": "Preis",
"events.free": "Gratis",
"events.small_fee": "Kleine Teilnahmegebühr",
"events.restrictions": "Einschränkungen",
"events.open_for_all": "Offen für alle",
"events.open_for_amiv_members_only": "Nur für AMIV Mitglieder",
"events.not_found": "Event nichr gefunden",
"events.no_selection": "Kein Event ausgewählt",
"events.signed_up": "Du hast dich für diesen Event angemeldet.",
......
......@@ -94,6 +94,9 @@
"events.price": "Price",
"events.free": "Free",
"events.small_fee": "Small fee",
"events.restrictions": "Restrictions",
"events.open_for_all": "Open for everyone",
"events.open_for_amiv_members_only": "For AMIV members only",
"events.not_found": "Event not found",
"events.no_selection": "No event selected",
"events.signed_up": "You signed up for this event.",
......
......@@ -152,6 +152,16 @@ export default class EventList {
{ value: 'small_fee', label: i18n('events.small_fee') },
],
},
{
type: 'radio',
label: i18n('events.restrictions'),
key: 'signup_restrictions',
default: 'members_only',
values: [
{ label: i18n('events.open_for_all'), value: 'all' },
{ label: i18n('events.open_for_amiv_members_only'), value: 'members_only' },
],
},
],
onchange: values => {
const query = {};
......@@ -171,6 +181,10 @@ export default class EventList {
if (conditions.length > 0) {
query.$and = [{ $or: conditions }];
}
} else if (key === 'signup_restrictions') {
if (value === 'all') {
query.allow_email_signup = true;
}
} else if (key === 'title' && value.length > 0) {
query.title_en = { $regex: `^(?i).*${value}.*` };
query.title_de = { $regex: `^(?i).*${value}.*` };
......
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