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

23 lines
938 B
JavaScript
Raw Normal View History

import { displayEvents, displayErrorMessage } from './events-displayer.js'
import * as GraphqlWrapper from './graphql-wrapper.js'
2021-01-08 14:08:40 +01:00
const NAME = '<wordpress-name>'
2021-01-08 14:08:40 +01:00
document.addEventListener('DOMContentLoaded', () => {
const eventLists = document.getElementsByClassName(NAME + '_events-list')
2021-11-01 20:57:34 +01:00
for (const 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
}
}
})