Summary Files Commits Branches @commit @diff @stats
path: root / checklist.html
diff options
context:
space:
mode:
Commit26b979b7a51d711fd34359bec5a3552f7324e705 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-06-23 09:52:22 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-06-23 09:52:22 +0300
Filesa542d32e175656aa50d37059c3509e58fe362706 /checklist.html
small-web-utilities-26b979b7a51d711fd34359bec5a3552f7324e705.tar
small-web-utilities-26b979b7a51d711fd34359bec5a3552f7324e705.tar.gz
small-web-utilities-26b979b7a51d711fd34359bec5a3552f7324e705.zip
Parentfde7863e53632094c8131394ffc2e57326a58ce6 (diff)
[checklist] Updated information, made import and export work without db, changed .onclick to addEventListener, added a field for db error info, added more comments
1 files changed, 95 insertions, 58 deletions
-rw-r--r--checklist.html153
diff --git a/checklist.html b/checklist.html
index a9e4a39..3e10a63 100644
--- a/checklist.html
+++ b/checklist.html
@@ -24,6 +24,12 @@
min-height: calc(100vh - 16px);
}
+#db-error {
+ background-color: red;
+ color: white;
+ font-weight: bold;
+}
+
.list-controls:hover + .list-item, .list-item > input:hover {
background-color: lightgray;
}
@@ -77,12 +83,20 @@ span {
<header>
<h2>Checklists</h2>
<p>
- With plus you add an item to the bottom of a checklist.
- With minus you remove it. With "Lock" you can select to only be able to check and uncheck items.
- "U" and "C" buttons correspond to uncheck and check functionality.
- "Export" creates and puts a string, representing the whole checklist and what items are checked, in the text box on the right, as well as in the current link.
- This means that, after pressing "Export", you can copy the link of the current page and share it, or you can copy the text itself (double-click to select all).
- "Import" reads the checklist data from the link if the text input is empty, otherwise it reads from the text input on the right.
+ Every checklist has a name and string representation.
+ Next to the "Import" and "Export" buttons there are two input fields.
+ With "Import" you load and store locally the checklist with the given name and string representation (if there is already one with that name, it is overridden).
+ With "Export", the name and string representation of the currently opened checklist is put into those two fields (and is stored locally, <b>export also functions as a save button</b>).
+ Sharing your checklists is done by exporting the current checklist and sharing the string representation, no collaborative support is implemented or planned.
+ <br>
+ From the drop-down menu below, you can select any one of your locally stored checklists, and either load them with "Open" or remove them with "Delete".
+ <br>
+ Below that is the name of the currently opened checklist.
+ Renaming a checklist is done by opening it, changing the name, exporting it and deleting the old named one.
+ With "+" you add an item to the bottom of a checklist.
+ With "-" you remove it.
+ With "Lock" you disable all editing.
+ "U" and "C" uncheck and check all items on the checklist or sub-items of an item.
</p>
<a href="/">Home</a>
<span id="notice">&emsp; Made by <a href="https://syndamia.com">Syndamia</a>, licensed under <a href="https://gitlab.com/Syndamia/small-web-utilities/-/blob/main/LICENSE">GNU GPLv3</a></span>
@@ -92,18 +106,21 @@ span {
<p>
<input type="button" value="Import" id="import-btn">
<input type="button" value="Export" id="export-btn">
- <input type="text" id="ei-name">
- <input type="text" id="ei-value">
+ <input type="text" id="ei-name" placeholder="Checklist name">
+ <input type="text" id="ei-value" placeholder="String representation">
</p>
<p>
<input type="button" value="Open" id="open-btn">
- <select id="db-lists"></select>
+ <select id="db-lists">
+ <option selected disabled>No locally stored checklists</option>
+ </select>
<input type="button" value="Delete" id="delete-btn">
+ <span id="db-error"></span>
</p>
<br>
<div id="single-checklist">
<h3>
- <input type="text" id="name">
+ <input type="text" id="name" placeholder="Name of opened checklist">
<input type="button" value="Uncheck all" id="uncheck-all">
<input type="button" value="Check all" id="check-all">
<input type="button" value="Lock" id="lock-items">
@@ -113,11 +130,13 @@ span {
<article id="lists"></article>
</div>
<script>
+ /* Normal checklist functionality */
+
const lists = document.getElementById('lists');
const stylesheetLocked = document.getElementById('stylesheet-locked');
stylesheetLocked.disabled = true;
- /* Item functionality */
+ /* Checklist item functions */
function get_checkBox(container) {
return container.children[1].children[0];
@@ -143,6 +162,8 @@ span {
get_children(current).forEach((child) => changeCheck(child, check));
}
+ /* General checklist functions */
+
function changeCheckLists(check) {
for (var i = 0; i < lists.children.length; i++) {
changeCheck(lists.children[i], check);
@@ -167,9 +188,9 @@ span {
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
- checkbox.onclick = function () {
+ checkbox.addEventListener('click', function () {
text.classList.toggle('checked');
- };
+ });
input.appendChild(checkbox);
input.appendChild(text);
@@ -178,34 +199,34 @@ span {
add.type = 'button';
add.value = '+';
add.classList.add('item-add');
- add.onclick = function () {
+ add.addEventListener('click', function () {
input.appendChild(newBlankItem());
- }
+ });
controls.appendChild(add);
var sub = document.createElement('input');
sub.type = 'button';
sub.value = '-';
sub.classList.add('item-remove');
- sub.onclick = function () {
+ sub.addEventListener('click', function () {
holder.remove();
- }
+ });
controls.appendChild(sub);
var uncheck = document.createElement('input');
uncheck.type = 'button';
uncheck.value = 'U';
- uncheck.onclick = function () {
+ uncheck.addEventListener('click', function () {
changeCheck(holder, false);
- }
+ });
controls.appendChild(uncheck);
var check = document.createElement('input');
check.type = 'button';
check.value = 'C';
- check.onclick = function () {
+ check.addEventListener('click', function () {
changeCheck(holder, true);
- }
+ });
controls.appendChild(check);
if (initialText) text.innerText = initialText;
@@ -214,47 +235,33 @@ span {
return holder;
}
- document.getElementById('article-add-item').onclick = function () {
+ document.getElementById('article-add-item').addEventListener('click', function () {
lists.appendChild(newBlankItem());
- }
+ });
- document.getElementById('article-sub-item').onclick = function () {
+ document.getElementById('article-sub-item').addEventListener('click', function () {
lists.innerHTML = "";
- }
+ });
- document.getElementById('lock-items').onclick = function () {
+ document.getElementById('lock-items').addEventListener('click', function () {
stylesheetLocked.disabled = !stylesheetLocked.disabled;
this.value = (this.value == 'Lock') ? 'Unlock' : 'Lock';
- }
+ });
- document.getElementById('uncheck-all').onclick = function () {
+ document.getElementById('uncheck-all').addEventListener('click', function () {
changeCheckLists(false);
- }
+ });
- document.getElementById('check-all').onclick = function () {
+ document.getElementById('check-all').addEventListener('click', function () {
changeCheckLists(true);
- }
+ });
</script>
<script>
- /* Import-export */
-
- const dropdown = document.getElementById('db-lists');
const eiName = document.getElementById('ei-name');
const eiValue = document.getElementById('ei-value');
const name = document.getElementById('name');
- const dbRequest = window.indexedDB.open('checklist', 1);
- var db = '', store = '';
-
- dbRequest.onupgradeneeded = function() {
- db = dbRequest.result;
- store = db.createObjectStore('CheckLists', { keyPath: 'name' });
- store.createIndex('name', 'name', { unique: true });
- store.createIndex('data', 'data');
- }
- dbRequest.onerror = function() {
- console.log('Error ', dbRequest.error);
- }
+ /* String representation of checklist */
function stringify(current) {
var str = "";
@@ -324,10 +331,42 @@ span {
}
}
+ // Open the currently imported checklist
+ document.getElementById('import-btn').addEventListener('click', function () {
+ name.value = eiName.value;
+ lists.innerHTML = '';
+ parse(eiValue.value, lists);
+ });
+
+ // Put checklist name and string representation in input boxes
+ document.getElementById('export-btn').addEventListener('click', function () {
+ eiName.value = name.value;
+ eiValue.value = stringify().substring(1);
+ });
+
+ /* Local database management (longterm storage) */
+
+ const dropdown = document.getElementById('db-lists');
+ const dbRequest = window.indexedDB.open('checklist', 1);
+ var db = '';
+
+ dbRequest.onupgradeneeded = function() {
+ db = dbRequest.result;
+ // Create "table"
+ var store = db.createObjectStore('CheckLists', { keyPath: 'name' });
+ // Create fields/columns of that table
+ store.createIndex('name', 'name', { unique: true });
+ store.createIndex('data', 'data');
+ }
+ dbRequest.onerror = function() {
+ console.log('Database error ', dbRequest.error);
+ document.getElementById('db-error').innerText = 'Got a database error, local storage won\'t work!';
+ }
+
dbRequest.onsuccess = function() {
db = dbRequest.result;
- document.getElementById('open-btn').onclick = function () {
+ document.getElementById('open-btn').addEventListener('click', function () {
const listName = dropdown.options[dropdown.selectedIndex].text;
var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
@@ -337,11 +376,12 @@ span {
lists.innerHTML = '';
parse(val.result.value, lists);
}
- }
+ });
var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
var all = store.getAll();
all.onsuccess = function() {
+ dropdown.innerHTML = '';
all.result.forEach(function (l) {
var nop = document.createElement('option');
nop.value = l.name;
@@ -351,26 +391,23 @@ span {
document.getElementById('open-btn').click();
}
- document.getElementById('delete-btn').onclick = function () {
+ document.getElementById('delete-btn').addEventListener('click', function () {
const listName = dropdown.options[dropdown.selectedIndex].text;
var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
store.delete(listName);
dropdown.remove(dropdown.selectedIndex);
- }
+ });
- document.getElementById('import-btn').onclick = function () {
+ document.getElementById('import-btn').addEventListener('click', function () {
var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
store.put({ name: eiName.value, value: eiValue.value });
- }
-
- document.getElementById('export-btn').onclick = function () {
- eiName.value = name.value;
- eiValue.value = stringify().substring(1);
+ });
+ document.getElementById('export-btn').addEventListener('click', function () {
var store = db.transaction('CheckLists', 'readwrite').objectStore('CheckLists');
- store.put({ name: eiName.value, value: eiValue.value });
- }
+ store.put({ name: name.value, value: stringify().substring(1) });
+ });
}
</script>
</body>