Commit cf332885 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Fix language issues with event model

parent c5e41b6b
import m from 'mithril';
import { apiUrl } from 'config';
import { getToken, getUserId, isLoggedIn } from '../auth';
import { currentLanguage } from '../language';
/**
* Event class
......@@ -20,6 +21,21 @@ export default class Event {
});
}
getTitle() {
const otherLanguage = currentLanguage() === 'en' ? 'de' : 'en';
return this[`title_${currentLanguage()}`] || this[`title_${otherLanguage}`];
}
getCatchphrase() {
const otherLanguage = currentLanguage() === 'en' ? 'de' : 'en';
return this[`catchphrase_${currentLanguage()}`] || this[`catchphrase_${otherLanguage}`];
}
getDescription() {
const otherLanguage = currentLanguage() === 'en' ? 'de' : 'en';
return this[`description_${currentLanguage()}`] || this[`description_${otherLanguage}`];
}
/**
* Load the signup data of the authenticated user.
*
......
import m from 'mithril';
import { apiUrl } from 'config';
import { getToken } from '../auth';
import { currentLanguage } from '../language';
import EventListController from './EventListController';
import Event from './Event';
......@@ -123,7 +122,6 @@ export default class EventController {
* @param {String} eventId
*/
async loadEvent(eventId) {
const otherLanguage = currentLanguage() === 'en' ? 'de' : 'en';
const event = await m.request({
method: 'GET',
url: `${apiUrl}/events/${eventId}`,
......@@ -134,9 +132,6 @@ export default class EventController {
if (!event.show_website) {
throw new Error('Event not found');
}
event.getTitle = () => event[`title_${currentLanguage()}`] || event[`title_${otherLanguage}`];
event.getDescription = () =>
event[`description_${currentLanguage()}`] || event[`description_${otherLanguage}`];
this._selectedEvent = new Event(event);
return this._selectedEvent;
}
......
import { currentLanguage } from '../language';
import PaginationController from '../pagination';
import Query from '../query';
import Event from './Event';
......@@ -15,14 +14,6 @@ export default class EventListController extends PaginationController {
async _loadData(query) {
const items = await super._loadData(query);
return items.map(event => {
const otherLanguage = currentLanguage() === 'en' ? 'de' : 'en';
const newEvent = Object.assign({}, event);
newEvent.getTitle = () =>
newEvent[`title_${currentLanguage()}`] || newEvent[`title_${otherLanguage}`];
newEvent.getDescription = () =>
newEvent[`description_${currentLanguage()}`] || newEvent[`description_${otherLanguage}`];
return new Event(newEvent);
});
return items.map(event => new Event(event));
}
}
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