aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js
diff options
context:
space:
mode:
Diffstat (limited to 'assets_src/js')
-rw-r--r--assets_src/js/list.js35
1 files changed, 16 insertions, 19 deletions
diff --git a/assets_src/js/list.js b/assets_src/js/list.js
index 7af7444..0d865c7 100644
--- a/assets_src/js/list.js
+++ b/assets_src/js/list.js
@@ -8,10 +8,11 @@ async function resultClicked(grilId) {
8 try { 8 try {
9 response = await ajax.post( 9 response = await ajax.post(
10 window.location, 10 window.location,
11 'id=' + grilId, 11 'id=' + grilId, {
12 { headers: { 12 headers: {
13 'Content-type': 'application/x-www-form-urlencoded' 13 'Content-type': 'application/x-www-form-urlencoded'
14 } }); 14 }
15 });
15 } catch (e) { 16 } catch (e) {
16 alert(e.message); 17 alert(e.message);
17 return; 18 return;
@@ -22,8 +23,7 @@ async function resultClicked(grilId) {
22async function updateGrilOrder(gril, pos) { 23async function updateGrilOrder(gril, pos) {
23 return await ajax.post( 24 return await ajax.post(
24 `${window.location}/order`, 25 `${window.location}/order`,
25 `gril=${gril}&pos=${pos}`, 26 `gril=${gril}&pos=${pos}`, {
26 {
27 headers: { 27 headers: {
28 'Content-Type': 'application/x-www-form-urlencoded', 28 'Content-Type': 'application/x-www-form-urlencoded',
29 } 29 }
@@ -44,44 +44,41 @@ function getCurrentOrder(gril) {
44 44
45async function listButtonHandler(e) { 45async function listButtonHandler(e) {
46 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; 46 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li';
47 let item = dom.closest(e.target, liFilter); 47 let cItem = dom.closest(e.target, liFilter);
48 let pItem = dom.previous(item, liFilter), 48 let pItem = dom.previous(cItem, liFilter),
49 nItem = dom.next(dom.next(item, liFilter), liFilter); 49 nItem = dom.next(dom.next(cItem, liFilter), liFilter);
50 switch (e.target.classList[0]) { 50 switch (e.target.classList[0]) {
51 case 'gril-sort-up': 51 case 'gril-sort-up':
52 try { 52 try {
53 await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1); 53 await updateGrilOrder(cItem.id, getCurrentOrder(cItem.id) - 1);
54 } catch(e) { 54 } catch(e) {
55 alert(e.message); 55 alert(e.message);
56 } 56 }
57 item.parentNode.insertBefore(item, pItem); 57 cItem.parentNode.insertBefore(cItem, pItem);
58 break; 58 break;
59 case 'gril-sort-down': 59 case 'gril-sort-down':
60 try { 60 try {
61 await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1); 61 await updateGrilOrder(cItem.id, getCurrentOrder(cItem.id) + 1);
62 } catch(e) { 62 } catch(e) {
63 alert(e.message); 63 alert(e.message);
64 } 64 }
65 65
66 if (nItem) { 66 if (nItem) {
67 item.parentNode.insertBefore(item, nItem); 67 cItem.parentNode.insertBefore(cItem, nItem);
68 } else { 68 } else {
69 item.parentNode.appendChild(item); 69 cItem.parentNode.appendChild(cItem);
70 } 70 }
71 break; 71 break;
72 case 'gril-delete': 72 case 'gril-delete':
73 let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li';
74 let item = dom.closest(e.target, liFilter);
75 try { 73 try {
76 await ajax.del( 74 await ajax.del(
77 `${window.location}/order`, 75 `${window.location}/order`,
78 `gril=${item.id}`, 76 `gril=${cItem.id}`, {
79 {
80 headers: { 77 headers: {
81 'Content-Type': 'application/x-www-form-urlencoded', 78 'Content-Type': 'application/x-www-form-urlencoded',
82 } 79 }
83 }); 80 });
84 item.parentNode.removeChild(item); 81 cItem.parentNode.removeChild(cItem);
85 } catch(e) { 82 } catch(e) {
86 alert(e.message); 83 alert(e.message);
87 } 84 }