connector-wordpress/source/connector-mobilizon/front/events-loader.js

23 lines
930 B
JavaScript
Raw Normal View History

2021-05-05 10:02:57 +02:00
import { displayEvents, displayErrorMessage } from './events-displayer'
2021-01-08 14:08:40 +01:00
import * as GraphqlWrapper from './graphql-wrapper'
const NAME = '<wordpress-name>'
2021-01-08 14:08:40 +01:00
document.addEventListener('DOMContentLoaded', () => {
const eventLists = document.getElementsByClassName(NAME + '_events-list')
for (let list of eventLists) {
const url = list.getAttribute('data-url') + '/api'
const limit = parseInt(list.getAttribute('data-maximum'))
const groupName = list.getAttribute('data-group-name')
if (groupName) {
GraphqlWrapper.getUpcomingEventsByGroupName({ url, limit, groupName })
2021-05-05 10:02:57 +02:00
.then((data) => displayEvents({ data, document, list }))
.catch((data) => displayErrorMessage({ data, list }))
} else {
GraphqlWrapper.getUpcomingEvents({ url, limit })
2021-05-05 10:02:57 +02:00
.then((data) => displayEvents({ data, document, list }))
.catch((data) => displayErrorMessage({ data, list }))
2021-01-08 14:08:40 +01:00
}
}
})