aboutsummaryrefslogtreecommitdiff
path: root/assets_src
diff options
context:
space:
mode:
authorJan C <jan@ruken.pw>2016-02-15 08:13:46 (UTC)
committerJan C <jan@ruken.pw>2016-02-15 08:13:46 (UTC)
commite0676fb384b1a0f634025156db1233f51b5819e7 (patch)
tree1b86c6cbdcbcbbad38c090a08db6c4332b75d54a /assets_src
parent889adc748ec9a723bca605dcba45d974ec362999 (diff)
grils können nun auch im backend herumgeworfen werden. sobald die datenbankfunktion funktioniert geht das auch so richtig.
Diffstat (limited to 'assets_src')
-rw-r--r--assets_src/js/list.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/assets_src/js/list.js b/assets_src/js/list.js
index 8246950..b3541e0 100644
--- a/assets_src/js/list.js
+++ b/assets_src/js/list.js
@@ -19,18 +19,36 @@ async function resultClicked(grilId) {
19 document.getElementById('gril-list').innerHTML += response; 19 document.getElementById('gril-list').innerHTML += response;
20} 20}
21 21
22function listButtonHandler(e) { 22async function updateGrilOrder(gril, pos) {
23 return await ajax.post(
24 `${window.location}/order`,
25 `gril=${gril}&pos=${pos}`,
26 { headers: {
27 'Content-Type': 'application/x-www-form-urlencoded',
28 } });
29}
30
31async function listButtonHandler(e) {
23 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; 32 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li';
24 let item = dom.closest(e.target, liFilter); 33 let item = dom.closest(e.target, liFilter);
25 let pItem = dom.previous(item, liFilter), 34 let pItem = dom.previous(item, liFilter),
26 nItem = dom.next(dom.next(item, liFilter), liFilter); 35 nItem = dom.next(dom.next(item, liFilter), liFilter);
27 switch (e.target.classList[0]) { 36 switch (e.target.classList[0]) {
28 case 'gril-sort-up': 37 case 'gril-sort-up':
29 //TODO: backend 38 try {
39 await updateGrilOrder(item.id, -1);
40 } catch(e) {
41 alert(e.message);
42 }
30 item.parentNode.insertBefore(item, pItem); 43 item.parentNode.insertBefore(item, pItem);
31 break; 44 break;
32 case 'gril-sort-down': 45 case 'gril-sort-down':
33 //TODO: backend 46 try {
47 await updateGrilOrder(item.id, 1);
48 } catch(e) {
49 alert(e.message);
50 }
51
34 if (nItem) { 52 if (nItem) {
35 item.parentNode.insertBefore(item, nItem); 53 item.parentNode.insertBefore(item, nItem);
36 } else { 54 } else {