import 'babel-polyfill'; import * as dom from './lib/dom'; import * as ajax from './lib/ajax'; dom.ready(() => { $('.modal-trigger').leanModal({ async ready() { const el = document.getElementById('modal-add-gril-content'); el.innerHTML = `
`; let data = {}; try { data = JSON.parse(await ajax.get('/api/lists/user')); } catch(e) { console.error(e); } el.innerHTML = ''; data.forEach(d => { const element = document.createElement('a'); element.innerHTML = d.Name; element.className = 'collection-item purple-text text-lighten-2'; element.addEventListener('click', async () => { try { await ajax.post( `/list/${d.ID}`, 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1], { headers: { 'Content-type': 'application/x-www-form-urlencoded' } }); $('#modal_add_gril').closeModal(); } catch(e) { console.error(e); } return true; }); el.appendChild(element); }); }, }); });