Rework edit form w/ checkboxes, filter and DB tags

This commit is contained in:
Martin Müller 2017-11-03 16:17:10 +01:00
parent ce7f55771c
commit 80e0ba439b
4 changed files with 64 additions and 43 deletions

View File

@ -94,4 +94,6 @@ def edit(sound):
# TODO: Store changes # TODO: Store changes
return redirect("/edit") return redirect("/edit")
return render_template("edit.html") tags = queryDB("SELECT name FROM tag ORDER BY name COLLATE NOCASE")
return render_template("edit.html", sound=sound, tags=tags)

View File

@ -43,6 +43,35 @@ input {
margin: 5px; margin: 5px;
} }
.editform input[type="text"] {
display: block;
}
.editform input[type="checkbox"] {
display: block;
float: left;
height: 15px;
margin: 5px;
width: 15px;
}
.editform .tags li {
clear: left;
display: block;
line-height: 20px;
vertical-align: middle;
}
.editform .tags li span {
display: inline-block;
line-height: 20px;
vertical-align: middle;
}
.tags {
padding-left: 0;
}
.tags li { .tags li {
display: inline-block; display: inline-block;
list-style-type: none; list-style-type: none;

View File

@ -30,23 +30,8 @@ ready(function() {
var searchfield = document.querySelector("#search"); var searchfield = document.querySelector("#search");
if (searchfield !== null) { filter(searchfield, ".sound", "inline-block");
searchfield.addEventListener("keyup", function() { filter(searchfield, ".tag", "block");
var buttons = document.querySelectorAll(".sound");
buttons.forEach(function(item) {
item.style.display = "inline-block";
});
buttons.forEach(function(item) {
var name = item.firstChild.innerHTML;
if (name.toLowerCase().indexOf(searchfield.value.toLowerCase()) === -1) {
item.style.display = "none";
}
});
});
}
var reset = document.querySelector("#sounds .reset"); var reset = document.querySelector("#sounds .reset");
@ -78,6 +63,27 @@ ready(function() {
} }
}); });
function filter(searchfield, itemSelector, unHideStyle) {
if (searchfield !== null) {
searchfield.addEventListener("keyup", function() {
var items = document.querySelectorAll(itemSelector);
items.forEach(function(item) {
item.style.display = unHideStyle;
});
items.forEach(function(item) {
var name = item.firstChild.innerHTML;
console.log(name);
if (name.toLowerCase().indexOf(searchfield.value.toLowerCase()) === -1) {
item.style.display = "none";
}
});
});
}
}
function hideSections() { function hideSections() {
var sections = document.querySelectorAll("section"); var sections = document.querySelectorAll("section");

View File

@ -3,32 +3,16 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="editform"> <div class="editform">
<h1>Filename</h1> <h1>Edit {{ sound }}</h1>
<form action="{{ request.path }}" method="POST"> <form action="{{ request.path }}" method="POST">
<div class="table-row"> <input type="text" id="search" placeholder="Search Tag" />
<div class="table-cell">
<label for="tags">Tags</label>
</div>
<div class="table-cell">
<input type="input" name="tags" id="tags" />
</div>
</div>
<div class="table-row">
<div class="table-cell"></div>
<div class="table-cell">
<ul class="tags"> <ul class="tags">
<li>Test<span class="reset"></span></li> {% for tag in tags %}
<li class="tag"><span>{{ tag.name }}</span><input type="checkbox" /></li>
{% endfor %}
</ul> </ul>
</div>
</div>
<div class="table-row">
<div class="table-cell">
</div>
<div class="table-cell">
<input type="button" value="Cancel" /> <input type="button" value="Cancel" />
<input type="submit" value="Submit" /> <input type="submit" value="Save" />
</div>
</div>
</form> </form>
</div> </div>
{% endblock %} {% endblock %}