+{% block script %}
+const PATH_FILE_JSON = `/{{page_names.file_json}}/` + "{{file.digest.b64}}";
+
+async function update_file_data() {
+ const file_data = await wrapped_fetch(PATH_FILE_JSON).then((response) => response.json());
+ document.getElementById("sync_checkbox").checked = ! file_data.flags.includes("do not sync");
+ Array.from(document.getElementsByClassName("listed_tags")).forEach((row) => row.remove());
+ file_data.tags_showable.forEach((tag) => {
+ const tr = new_child_to("tr", document.getElementById("tags_table"));
+ tr.classList.add("listed_tags");
+ td_checkbox = new_child_to("td", tr);
+ td_checkbox.classList.add("tag_checkboxes");
+ const input = new_child_to("input", td_checkbox);
+ input.type = "checkbox";
+ input.checked = true;
+ {% if not allow_edit %}input.disabled = true;{% endif %}
+ input.onclick = send_update;
+ const a = new_child_to("a", new_child_to("td", new_child_to("td", tr)));
+ a.href = "/{{page_names.files}}?needed_tag={{tag|urlencode}}";
+ a.textContent = tag;
+ });
+ document.getElementById("added_tag").value = "";
+ const datalist = document.getElementById("unused_tags");
+ datalist.innerHTML = "";
+ file_data.unused_tags.forEach((tag) => { new_child_to("option", datalist, tag); });
+ td_present = document.getElementById("presence");
+ td_present.innerHTML = "";
+ if (file_data.present) {
+ const a = new_child_to("a", td_present, "yes");
+ a.href = "/{{page_names.download}}/{{file.yt_id}}";
+ const button = new_child_to("button", td_present, "inject");
+ button.onclick = function() { player_command("inject_{{file.digest.b64}}"); }
+ } else {
+ td_present.textContent = "no";
+ }
+}
+
+async function send_update(button) {
+ let tags = []
+ Array.from(document.getElementsByClassName("listed_tags")).forEach((tr) => {
+ if (tr.children[0].children[0].checked) {
+ tags.push(tr.children[1].children[0].textContent);
+ }
+ });
+ const added_tag = document.getElementById("added_tag").value;
+ if (added_tag.length > 0 && button == document.getElementById("add_tag_button")) {
+ tags.push(added_tag);
+ }
+ let flags = []
+ if (! document.getElementById("sync_checkbox").checked) {
+ flags.push("do not sync");
+ }
+ await wrapped_post(PATH_FILE_JSON, {
+ flags: flags,
+ tags: tags,
+ delete_locally: button == document.getElementById("unlink_button")
+ });
+ update_file_data();
+}
+
+window.addEventListener('load', update_file_data);
+{% endblock %}
+
+