aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-10-03 12:34:36 (UTC)
committerrtz12 <koenig@fagott.pw>2016-10-03 12:34:36 (UTC)
commitc1d895a7db943b758bfbf214c3727569976f85e0 (patch)
tree09d50f05049095b92456c78b3df7fb074fbd53e3 /assets_src/js
parent5997487fc5cc2126fb5afa12b75b67f3985e11d2 (diff)
Formatierung gefixt und go fmt
Ein gewisser jemand sollte endlich mal seinen Editor richtig konfigurieren
Diffstat (limited to 'assets_src/js')
-rw-r--r--assets_src/js/gril.js84
-rw-r--r--assets_src/js/list.js70
2 files changed, 79 insertions, 75 deletions
diff --git a/assets_src/js/gril.js b/assets_src/js/gril.js
index 561c221..7d92b5a 100644
--- a/assets_src/js/gril.js
+++ b/assets_src/js/gril.js
@@ -3,45 +3,45 @@ import * as dom from './lib/dom';
3import * as ajax from './lib/ajax'; 3import * as ajax from './lib/ajax';
4 4
5dom.ready(() => { 5dom.ready(() => {
6 $('.modal-trigger').leanModal({ 6 $('.modal-trigger').leanModal({
7 async ready() { 7 async ready() {
8 const el = document.getElementById('modal-add-gril-content'); 8 const el = document.getElementById('modal-add-gril-content');
9 9
10 el.innerHTML = ` 10 el.innerHTML = `
11 <div class="progress"> 11 <div class="progress">
12 <div class="indeterminate"></div> 12 <div class="indeterminate"></div>
13 </div>`; 13 </div>`;
14 14
15 let data = {}; 15 let data = {};
16 try { 16 try {
17 data = JSON.parse(await ajax.get('/api/lists/user')); 17 data = JSON.parse(await ajax.get('/api/lists/user'));
18 } catch(e) { 18 } catch(e) {
19 console.error(e); 19 console.error(e);
20 } 20 }
21 21
22 el.innerHTML = ''; 22 el.innerHTML = '';
23 23
24 data.forEach(d => { 24 data.forEach(d => {
25 const element = document.createElement('a'); 25 const element = document.createElement('a');
26 element.innerHTML = d.Name; 26 element.innerHTML = d.Name;
27 element.className = 'collection-item purple-text text-lighten-2'; 27 element.className = 'collection-item purple-text text-lighten-2';
28 element.addEventListener('click', async () => { 28 element.addEventListener('click', async () => {
29 try { 29 try {
30 await ajax.post( 30 await ajax.post(
31 `/list/${d.ID}`, 31 `/list/${d.ID}`,
32 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1], 32 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1],
33 { headers: { 33 { headers: {
34 'Content-type': 'application/x-www-form-urlencoded' 34 'Content-type': 'application/x-www-form-urlencoded'
35 } }); 35 } });
36 $('#modal_add_gril').closeModal(); 36 $('#modal_add_gril').closeModal();
37 } catch(e) { 37 } catch(e) {
38 console.error(e); 38 console.error(e);
39 } 39 }
40 40
41 return true; 41 return true;
42 }); 42 });
43 el.appendChild(element); 43 el.appendChild(element);
44 }); 44 });
45 }, 45 },
46 }); 46 });
47}); \ No newline at end of file 47});
diff --git a/assets_src/js/list.js b/assets_src/js/list.js
index 7a4f69e..7af7444 100644
--- a/assets_src/js/list.js
+++ b/assets_src/js/list.js
@@ -20,24 +20,26 @@ async function resultClicked(grilId) {
20} 20}
21 21
22async function updateGrilOrder(gril, pos) { 22async function updateGrilOrder(gril, pos) {
23 return await ajax.post( 23 return await ajax.post(
24 `${window.location}/order`, 24 `${window.location}/order`,
25 `gril=${gril}&pos=${pos}`, 25 `gril=${gril}&pos=${pos}`,
26 { headers: { 26 {
27 'Content-Type': 'application/x-www-form-urlencoded', 27 headers: {
28 } }); 28 'Content-Type': 'application/x-www-form-urlencoded',
29 }
30 });
29} 31}
30 32
31function getCurrentOrder(gril) { 33function getCurrentOrder(gril) {
32 const els = document.querySelectorAll('#gril-list > li') 34 const els = document.querySelectorAll('#gril-list > li')
33 35
34 for (let i = 0; i < els.length; i++) { 36 for (let i = 0; i < els.length; i++) {
35 if (els[i].id === gril) { 37 if (els[i].id === gril) {
36 console.log(i); 38 console.log(i);
37 return i; 39 return i;
38 } 40 }
39 } 41 }
40 return -1; 42 return -1;
41} 43}
42 44
43async function listButtonHandler(e) { 45async function listButtonHandler(e) {
@@ -47,20 +49,20 @@ async function listButtonHandler(e) {
47 nItem = dom.next(dom.next(item, liFilter), liFilter); 49 nItem = dom.next(dom.next(item, liFilter), liFilter);
48 switch (e.target.classList[0]) { 50 switch (e.target.classList[0]) {
49 case 'gril-sort-up': 51 case 'gril-sort-up':
50 try { 52 try {
51 await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1); 53 await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1);
52 } catch(e) { 54 } catch(e) {
53 alert(e.message); 55 alert(e.message);
54 } 56 }
55 item.parentNode.insertBefore(item, pItem); 57 item.parentNode.insertBefore(item, pItem);
56 break; 58 break;
57 case 'gril-sort-down': 59 case 'gril-sort-down':
58 try { 60 try {
59 await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1); 61 await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1);
60 } catch(e) { 62 } catch(e) {
61 alert(e.message); 63 alert(e.message);
62 } 64 }
63 65
64 if (nItem) { 66 if (nItem) {
65 item.parentNode.insertBefore(item, nItem); 67 item.parentNode.insertBefore(item, nItem);
66 } else { 68 } else {
@@ -68,16 +70,18 @@ async function listButtonHandler(e) {
68 } 70 }
69 break; 71 break;
70 case 'gril-delete': 72 case 'gril-delete':
71 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; 73 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li';
72 let item = dom.closest(e.target, liFilter); 74 let item = dom.closest(e.target, liFilter);
73 try { 75 try {
74 await ajax.del( 76 await ajax.del(
75 `${window.location}/order`, 77 `${window.location}/order`,
76 `gril=${item.id}`, 78 `gril=${item.id}`,
77 { headers: { 79 {
78 'Content-Type': 'application/x-www-form-urlencoded', 80 headers: {
79 } }); 81 'Content-Type': 'application/x-www-form-urlencoded',
80 item.parentNode.removeChild(item); 82 }
83 });
84 item.parentNode.removeChild(item);
81 } catch(e) { 85 } catch(e) {
82 alert(e.message); 86 alert(e.message);
83 } 87 }