From 889adc748ec9a723bca605dcba45d974ec362999 Mon Sep 17 00:00:00 2001 From: rtz12 Date: Sun, 14 Feb 2016 19:29:11 +0100 Subject: Grils koennen nun sortiert und geloescht werden. TODO: backend diff --git a/assets_src/js/lib/dom.js b/assets_src/js/lib/dom.js index 33845af..bfbeea7 100644 --- a/assets_src/js/lib/dom.js +++ b/assets_src/js/lib/dom.js @@ -5,10 +5,42 @@ export function ready(fn) { } export function closest(el, fn) { + if (!el) { + return null; + } while (el) { if (fn(el)) { return el; } el = el.parentNode } + return null; +} + +export function next(el, fn) { + if (!el) { + return null; + } + el = el.nextSibling; + while (el) { + if (fn(el)) { + return el; + } + el = el.nextSibling; + } + return null; +} + +export function previous(el, fn) { + if (!el) { + return null; + } + el = el.previousSibling; + while (el) { + if (fn(el)) { + return el; + } + el = el.previousSibling; + } + return null; } diff --git a/assets_src/js/list.js b/assets_src/js/list.js index 413f517..8246950 100644 --- a/assets_src/js/list.js +++ b/assets_src/js/list.js @@ -19,11 +19,40 @@ async function resultClicked(grilId) { document.getElementById('gril-list').innerHTML += response; } +function listButtonHandler(e) { + let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; + let item = dom.closest(e.target, liFilter); + let pItem = dom.previous(item, liFilter), + nItem = dom.next(dom.next(item, liFilter), liFilter); + switch (e.target.classList[0]) { + case 'gril-sort-up': + //TODO: backend + item.parentNode.insertBefore(item, pItem); + break; + case 'gril-sort-down': + //TODO: backend + if (nItem) { + item.parentNode.insertBefore(item, nItem); + } else { + item.parentNode.appendChild(item); + } + break; + case 'gril-delete': + //TODO: backend + item.parentNode.removeChild(item); + break; + } +} + function main() { let is = new search.InstantSearch( document.getElementById('gril-add-search'), document.getElementById('search-results')); is.resultClicked = resultClicked; + document.getElementById('gril-list').addEventListener( + 'click', + listButtonHandler, + true); } dom.ready(main); diff --git a/views/includes/list_gril.html b/views/includes/list_gril.html index f719dae..57694aa 100644 --- a/views/includes/list_gril.html +++ b/views/includes/list_gril.html @@ -15,19 +15,19 @@
- keyboard_arrow_up - keyboard_arrow_down + keyboard_arrow_up + keyboard_arrow_down
- delete + delete
- keyboard_arrow_up - keyboard_arrow_down - delete + keyboard_arrow_up + keyboard_arrow_down + delete
@@ -35,4 +35,4 @@ -{{ end }} \ No newline at end of file +{{ end }} -- cgit v0.10.1