aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js/gril.js
blob: 561c221e58b2d0b8b1973d4f650ddabe8571dd79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 = `
                <div class="progress">
                    <div class="indeterminate"></div>
                </div>`;
                
            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);
            });
        },
    });
});