+{% block script %}
+{{ macros.js_new_child_to() }}
+
+const all_tags = {{showable_tags|tojson|safe}};
+var needed_tags = {{needed_tags|tojson|safe}};
+
+function select_tag() {
+ if (tags_select.selectedIndex < 1) {
+ return;
+ }
+ const chosen_tag = document.getElementById('tags_select').value;
+ needed_tags.push(chosen_tag);
+ reload_selector();
+}
+
+function reload_selector() {
+ const tags_select = document.getElementById('tags_select');
+ while (tags_select.options.length > 0) {
+ tags_select.remove(0);
+ }
+ new_child_to('option', tags_select, 'add tag');
+ all_tags.forEach((tag) => {
+ if (needed_tags.includes(tag)) {
+ return;
+ }
+ const option = new_child_to('option', tags_select, tag);
+ });
+ const tags_div = document.getElementById("tags");
+ tags_div.innerHTML = '';
+ needed_tags.forEach((chosen_tag) => {
+ const tag_text_node = document.createTextNode(` ${chosen_tag} `);
+ tags_div.appendChild(tag_text_node);
+ const btn_del = new_child_to('button', tags_div, 'x');
+ btn_del.onclick = function() {
+ tag_text_node.remove();
+ btn_del.remove();
+ needed_tags = needed_tags.filter(tag => tag !== chosen_tag);
+ reload_selector();
+ };
+ const input = new_child_to('input', tags_div);
+ input.type = 'hidden';
+ input.name = 'needed_tag';
+ input.value = chosen_tag;
+ });
+}
+
+window.addEventListener('load', reload_selector);
+{% endblock %}
+
+