aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js
diff options
context:
space:
mode:
authorJan C <jan@ruken.pw>2016-02-15 08:44:09 (UTC)
committerJan C <jan@ruken.pw>2016-02-15 08:44:09 (UTC)
commitf01703339943c432c4f47113983d90e118b7ff2c (patch)
treea9d213b142127c2e58f15028f71142c713a10df7 /assets_src/js
parent75a81729f53efccdc4a54851355a8863a2bdfb7d (diff)
grils werden jetzt nicht mehr mit der differenzpos sondern der TOTALEN position reordert, spart datenbankgedöns.
Diffstat (limited to 'assets_src/js')
-rw-r--r--assets_src/js/list.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/assets_src/js/list.js b/assets_src/js/list.js
index b3541e0..be7f007 100644
--- a/assets_src/js/list.js
+++ b/assets_src/js/list.js
@@ -28,6 +28,18 @@ async function updateGrilOrder(gril, pos) {
28 } }); 28 } });
29} 29}
30 30
31function getCurrentOrder(gril) {
32 const els = document.querySelectorAll('#gril-list > li')
33
34 for (let i = 0; i < els.length; i++) {
35 if (els[i].id === gril) {
36 console.log(i);
37 return i;
38 }
39 }
40 return -1;
41}
42
31async function listButtonHandler(e) { 43async function listButtonHandler(e) {
32 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; 44 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li';
33 let item = dom.closest(e.target, liFilter); 45 let item = dom.closest(e.target, liFilter);
@@ -36,7 +48,7 @@ async function listButtonHandler(e) {
36 switch (e.target.classList[0]) { 48 switch (e.target.classList[0]) {
37 case 'gril-sort-up': 49 case 'gril-sort-up':
38 try { 50 try {
39 await updateGrilOrder(item.id, -1); 51 await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1);
40 } catch(e) { 52 } catch(e) {
41 alert(e.message); 53 alert(e.message);
42 } 54 }
@@ -44,7 +56,7 @@ async function listButtonHandler(e) {
44 break; 56 break;
45 case 'gril-sort-down': 57 case 'gril-sort-down':
46 try { 58 try {
47 await updateGrilOrder(item.id, 1); 59 await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1);
48 } catch(e) { 60 } catch(e) {
49 alert(e.message); 61 alert(e.message);
50 } 62 }