Skip to content
Snippets Groups Projects
Commit 405479e5 authored by nicomarg's avatar nicomarg
Browse files

Execute script to add behavior to searched buttons

parent 0cc13009
No related branches found
No related tags found
1 merge request!224Added a search tab for the conso page, fixes #58
Pipeline #13088 passed with stages
in 15 minutes and 21 seconds
......@@ -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 }}").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 }}").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 }}").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 %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment