async function api(action, data) { var url = prefix + '/api/' var key = JSON.stringify([action, data]) if (!cache[key]) { var response = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ action: action, data: data }) }) cache[key] = await response.json() } return cache[key] } async function getCase(value) { var conditions = [ {'key': 'case', 'operator': '==', 'value': value} ] return await api('findDocuments', { "query":{ "conditions":conditions, "operator":"&" }, "range":[0, 10000], "keys": ["title", "date", "case", "id"] }).then(response => { var documents = response.data.items var events = documents.map(data => { var date = data.date.split('-') var event = { "start_date": { "year": date[0], "month": date[1], "day": date[2], "hour": "", "minute": "", "second": "", "millisecond": "", "format": "" }, "end_date": { "year": date[0], "month": date[1], "day": date[2], "hour": "", "minute": "", "second": "", "millisecond": "", "format": "" }, "media": { "caption": data['title'], "credit": "", "url": mediaPrefix + "/documents/" + data.id + "/512p.jpg" }, "text": { "headline": data.title, "text": data.description || data.title }, "unique_id": data.id }; return event }) return {'events': events} }) } async function loadData(value) { return await getCase(value) }