diff options
Diffstat (limited to 'assets_src')
-rw-r--r-- | assets_src/js/list.js | 24 |
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 | ||
22 | function listButtonHandler(e) { | 22 | async 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 | |||
31 | async 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 { |