aboutsummaryrefslogtreecommitdiff
path: root/assets_src
diff options
context:
space:
mode:
Diffstat (limited to 'assets_src')
-rw-r--r--assets_src/js/gril.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/assets_src/js/gril.js b/assets_src/js/gril.js
new file mode 100644
index 0000000..561c221
--- /dev/null
+++ b/assets_src/js/gril.js
@@ -0,0 +1,47 @@
1import 'babel-polyfill';
2import * as dom from './lib/dom';
3import * as ajax from './lib/ajax';
4
5dom.ready(() => {
6 $('.modal-trigger').leanModal({
7 async ready() {
8 const el = document.getElementById('modal-add-gril-content');
9
10 el.innerHTML = `
11 <div class="progress">
12 <div class="indeterminate"></div>
13 </div>`;
14
15 let data = {};
16 try {
17 data = JSON.parse(await ajax.get('/api/lists/user'));
18 } catch(e) {
19 console.error(e);
20 }
21
22 el.innerHTML = '';
23
24 data.forEach(d => {
25 const element = document.createElement('a');
26 element.innerHTML = d.Name;
27 element.className = 'collection-item purple-text text-lighten-2';
28 element.addEventListener('click', async () => {
29 try {
30 await ajax.post(
31 `/list/${d.ID}`,
32 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1],
33 { headers: {
34 'Content-type': 'application/x-www-form-urlencoded'
35 } });
36 $('#modal_add_gril').closeModal();
37 } catch(e) {
38 console.error(e);
39 }
40
41 return true;
42 });
43 el.appendChild(element);
44 });
45 },
46 });
47}); \ No newline at end of file