4 changed files with 94 additions and 18 deletions
@ -0,0 +1,58 @@
|
||||
function logError(s) { |
||||
console.log(s); |
||||
let error_box = document.querySelector('#js_errors'); |
||||
let p = document.createElement('p'); |
||||
p.appendChild(document.createTextNode(s)); |
||||
error_box.appendChild(p); |
||||
error_box.style.display = 'block'; |
||||
} |
||||
|
||||
function fetchJSON(url, responseFunc, event) { |
||||
fetch(url) |
||||
.then(function(response) { |
||||
console.log('Response.url: ', response.url) |
||||
if (!response.ok) |
||||
throw Error(response.statusText); |
||||
|
||||
return response.json(); |
||||
}) |
||||
.then(function(json) { |
||||
responseFunc(json, event); |
||||
}) |
||||
.catch(function(error) { |
||||
logError('fetch error: ' + error); |
||||
return null; |
||||
}); |
||||
} |
||||
|
||||
function parseResponse(json, event) { |
||||
if (json.errors.length > 0) { |
||||
for (let err of json.errors) |
||||
logError(err); |
||||
} else { |
||||
for (let path of json.paths) { |
||||
console.log(event); |
||||
} |
||||
} |
||||
} |
||||
|
||||
window.onload = function() { |
||||
document.querySelector('#noscript').style.display = 'none'; |
||||
let error_box = document.querySelector('#js_errors'); |
||||
error_box.style.display = 'none'; |
||||
|
||||
if (!('fetch' in window)) { |
||||
logError('Unsupported Browser, No fetch API'); |
||||
return; |
||||
} |
||||
|
||||
// replace top level links with event listeners that fetch json directory listings
|
||||
for (let link of document.querySelectorAll('#videolist > li > a')) { |
||||
let href = link.getAttribute('href') |
||||
|
||||
link.addEventListener('click', function(e) { |
||||
e.preventDefault(); |
||||
fetchJSON(window.location + href, parseResponse, e); |
||||
}); |
||||
} |
||||
} |
||||
@ -1,21 +1,33 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block extra_js %} |
||||
<script type="text/javascript" src="{{ url_for('static', filename='file_listing.js') }}"></script> |
||||
{% endblock %} |
||||
|
||||
{% block header %} |
||||
<h1>{% block title %}File Listing{% endblock %}</h1> |
||||
<h1>{% block title %}File Listing{% endblock %}</h1> |
||||
{% endblock %} |
||||
|
||||
{% block content %} |
||||
<ul> |
||||
{% for path in paths%} |
||||
<li> |
||||
{% if path.is_dir %} |
||||
<a href="{{ url_for('file_listing.getFolderJSON', subpath=path.rel_path) }}"> |
||||
{{ path.base_name }}</a> |
||||
{% else %} |
||||
<a href="{{ url_for('tmdb.query_movie', query=path.base_name, rel_path=path.rel_path) }}"> |
||||
{{ path.base_name }}</a> |
||||
{% endif %} |
||||
</li> |
||||
{% endfor %} |
||||
</ul> |
||||
<p id="noscript" class="flash">Javascript needs to be enabled for this page</p> |
||||
<div id="js_errors" class="flash"></div> |
||||
|
||||
<ul id="videolist"> |
||||
{% for path in paths%} |
||||
<li> |
||||
{% if path.is_dir %} |
||||
<a class="folder" href="{{ path.rel_path }}">{{ path.base_name }}</a> |
||||
{% else %} |
||||
<a class="file" href="{{ |
||||
url_for('tmdb.query_movie', query=path.base_name, rel_path=path.rel_path) }}"> |
||||
{{ path.base_name }}</a> |
||||
{% endif %} |
||||
</li> |
||||
{% endfor %} |
||||
</ul> |
||||
|
||||
<template id="path_info"> |
||||
<li><a href=""></a></li> |
||||
</template> |
||||
{% endblock %} |
||||
|
||||
|
||||
Loading…
Reference in new issue