1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-02-25 17:36:31 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nicomarg
1ab63cbc92 Merge branch 'search-conso' into 'main'
Added a search tab for the conso page, fixes #58

Closes #58

See merge request bde/nk20!224
2023-10-26 13:24:31 +02:00
Nicolas Margulies
08b2fabe07 Removing jquery means changing the event API... 2023-10-26 00:22:51 +02:00
Nicolas Margulies
405479e5ad Execute script to add behavior to searched buttons 2023-10-26 00:10:56 +02:00

View File

@ -182,7 +182,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<script type="text/javascript">
{% for button in highlighted %}
{% if button.display %}
$("#highlighted_button{{ button.id }}").click(function() {
document.getElementById("highlighted_button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
@ -193,7 +193,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% for category in categories %}
{% for button in category.templates_filtered %}
{% if button.display %}
$("#button{{ button.id }}").click(function() {
document.getElementById("button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
@ -202,15 +202,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endfor %}
{% endfor %}
{% for button in search_results %}
{% if button.display %}
$("#search_button{{ button.id }}").click(function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
});
{% endif %}
{% endfor %}
searchbar = document.getElementById("search-input")
const parser = new DOMParser();
@ -224,8 +215,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
xhr.open("GET", location.pathname + "?search=" +
encodeURI(pattern) + "#search", true)
xhr.onload = () => {
let newdoc = parser.parseFromString(xhr.responseText, "text/html");
document.getElementById("search-results").innerHTML =
parser.parseFromString(xhr.responseText, "text/html").getElementById("search-results").innerHTML
newdoc.getElementById("search-results").innerHTML;
eval(newdoc.getElementById("search-script").text);
};
xhr.send();
}
@ -234,4 +227,15 @@ SPDX-License-Identifier: GPL-3.0-or-later
debounce(updateSearch)()
});
</script>
<script type="text/javascript" id="search-script">
{% for button in search_results %}
{% if button.display %}
document.getElementById("search_button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
});
{% endif %}
{% endfor %}
</script>
{% endblock %}