diff --git a/apps/note/static/note/js/consos.js b/apps/note/static/note/js/consos.js index 6f9dc61e..199a0a19 100644 --- a/apps/note/static/note/js/consos.js +++ b/apps/note/static/note/js/consos.js @@ -258,3 +258,39 @@ function consume (source, source_alias, dest, quantity, amount, reason, type, ca }) }) } + +const searchbar = document.getElementById("search-input") +const search_results = document.getElementById("search-results") + +var old_pattern = null; +var firstMatch = null; +/** + * Updates the button search tab + * @param force Forces the update even if the pattern didn't change + */ +function updateSearch(force = false) { + let pattern = searchbar.value + if (pattern === "") + firstMatch = null; + if ((pattern === old_pattern || pattern === "") && !force) + return; + firstMatch = null; + const re = new RegExp(pattern, "i"); + Array.from(search_results.children).forEach(function(b) { + if (re.test(b.innerText)) { + b.hidden = false; + if (firstMatch === null) { + firstMatch = b; + } + } else + b.hidden = true; + }); +} + +searchbar.addEventListener("input", function (e) { + debounce(updateSearch)() +}); +searchbar.addEventListener("keyup", function (e) { + if (firstMatch && e.key === "Enter") + firstMatch.click() +}); diff --git a/apps/note/templates/note/conso_form.html b/apps/note/templates/note/conso_form.html index 5d9007d4..25015c90 100644 --- a/apps/note/templates/note/conso_form.html +++ b/apps/note/templates/note/conso_form.html @@ -211,41 +211,5 @@ SPDX-License-Identifier: GPL-3.0-or-later }); {% endif %} {% endfor %} - - const searchbar = document.getElementById("search-input") - const search_results = document.getElementById("search-results") - - var old_pattern = null; - var firstMatch = null; - /** - * Updates the button search tab - * @param force Forces the update even if the pattern didn't change - */ - function updateSearch(force = false) { - let pattern = searchbar.value - if (pattern === "") - firstMatch = null; - if ((pattern === old_pattern || pattern === "") && !force) - return; - firstMatch = null; - const re = new RegExp(pattern, "i"); - Array.from(search_results.children).forEach(function(b) { - if (re.test(b.innerText)) { - b.hidden = false; - if (firstMatch === null) { - firstMatch = b; - } - } else - b.hidden = true; - }); - } - - searchbar.addEventListener("input", function (e) { - debounce(updateSearch)() - }); - searchbar.addEventListener("keyup", function (e) { - if (firstMatch && e.key === "Enter") - firstMatch.click() - }); {% endblock %}