2021-06-22 20:38:08 +00:00
|
|
|
<!DOCTYPE html>
|
2016-11-29 04:18:44 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
{% import "header.html" as header %}
|
2021-01-20 00:33:34 +00:00
|
|
|
{% import "cards.html" as cards %}
|
2016-11-29 04:18:44 +00:00
|
|
|
<title>Bookmarks</title>
|
|
|
|
<meta charset="UTF-8">
|
2017-07-21 06:10:48 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
2018-02-24 20:51:36 +00:00
|
|
|
<link rel="stylesheet" href="/static/css/common.css">
|
2020-09-03 18:50:16 +00:00
|
|
|
<link rel="stylesheet" href="/static/css/etiquette.css">
|
2021-01-08 21:41:49 +00:00
|
|
|
<link rel="stylesheet" href="/static/css/cards.css">
|
2019-08-14 20:43:35 +00:00
|
|
|
{% if theme %}<link rel="stylesheet" href="/static/css/theme_{{theme}}.css">{% endif %}
|
2018-02-24 20:51:36 +00:00
|
|
|
<script src="/static/js/common.js"></script>
|
2018-09-23 22:43:42 +00:00
|
|
|
<script src="/static/js/api.js"></script>
|
2021-05-03 01:37:28 +00:00
|
|
|
<script src="/static/js/cards.js"></script>
|
2019-04-27 22:42:02 +00:00
|
|
|
<script src="/static/js/spinner.js"></script>
|
2018-02-24 08:46:55 +00:00
|
|
|
<script src="/static/js/editor.js"></script>
|
2016-11-29 04:18:44 +00:00
|
|
|
|
|
|
|
<style>
|
2018-09-23 21:57:25 +00:00
|
|
|
#bookmark_list
|
2017-02-05 02:30:02 +00:00
|
|
|
{
|
|
|
|
display: flex;
|
|
|
|
flex: 0 0 auto;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
2016-11-29 04:18:44 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2016-12-18 13:12:14 +00:00
|
|
|
{{header.make_header(session=session)}}
|
2016-11-29 04:18:44 +00:00
|
|
|
<div id="content_body">
|
2018-09-23 21:57:25 +00:00
|
|
|
<div id="bookmark_list">
|
|
|
|
<h2>Bookmarks</h2>
|
2017-02-05 02:30:02 +00:00
|
|
|
{% for bookmark in bookmarks %}
|
2021-01-20 00:33:34 +00:00
|
|
|
{{cards.create_bookmark_card(bookmark, add_delete_button=True)}}
|
2017-02-05 02:30:02 +00:00
|
|
|
{% endfor %}
|
2018-07-29 07:36:50 +00:00
|
|
|
|
2021-05-03 01:36:10 +00:00
|
|
|
<div id="new_bookmark_card" class="bookmark_card">
|
2018-02-18 03:36:48 +00:00
|
|
|
<input id="new_bookmark_title" type="text" placeholder="title (optional)">
|
2017-07-10 02:40:14 +00:00
|
|
|
<input id="new_bookmark_url" type="text" placeholder="url">
|
2021-01-08 21:41:49 +00:00
|
|
|
<div class="bookmark_toolbox">
|
|
|
|
<button id="new_bookmark_button" class="green_button" onclick="return create_bookmark_form();">Create</button>
|
|
|
|
</div>
|
2017-07-10 02:40:14 +00:00
|
|
|
</div>
|
2017-02-05 02:30:02 +00:00
|
|
|
</div>
|
2016-11-29 04:18:44 +00:00
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2018-07-29 08:25:53 +00:00
|
|
|
function create_bookmark_form()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const url = document.getElementById("new_bookmark_url").value.trim();
|
|
|
|
const title = document.getElementById("new_bookmark_title").value.trim();
|
2018-07-29 08:25:53 +00:00
|
|
|
if (!url)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-05-03 01:37:28 +00:00
|
|
|
return api.bookmarks.create(url, title, create_bookmark_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_bookmark_callback(response)
|
|
|
|
{
|
|
|
|
if (! (response.meta.status === 200 && response.meta.json_ok))
|
|
|
|
{
|
|
|
|
alert(JSON.stringify(response));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const bookmark = response.data;
|
|
|
|
const add_delete_button = true;
|
|
|
|
const bookmark_card = cards.bookmarks.create(bookmark, add_delete_button);
|
|
|
|
create_editor(bookmark_card);
|
|
|
|
|
|
|
|
const bookmark_list = document.getElementById("bookmark_list");
|
|
|
|
const new_bookmark_card = document.getElementById("new_bookmark_card");
|
|
|
|
bookmark_list.insertBefore(bookmark_card, new_bookmark_card);
|
|
|
|
|
|
|
|
document.getElementById("new_bookmark_url").value = "";
|
|
|
|
document.getElementById("new_bookmark_title").value = "";
|
2018-07-29 07:36:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 04:28:21 +00:00
|
|
|
function delete_bookmark_form(event)
|
2020-09-18 01:14:07 +00:00
|
|
|
{
|
2021-01-09 02:28:02 +00:00
|
|
|
const card = event.target.closest(".bookmark_card");
|
|
|
|
const id = card.dataset.id;
|
|
|
|
function callback(response)
|
|
|
|
{
|
|
|
|
if (response.meta.status !== 200)
|
|
|
|
{
|
|
|
|
alert(JSON.stringify(response));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
card.parentElement.removeChild(card);
|
|
|
|
}
|
|
|
|
api.bookmarks.delete(id, callback);
|
2020-09-18 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 03:46:06 +00:00
|
|
|
ed_on_open = undefined;
|
2017-07-17 00:26:34 +00:00
|
|
|
|
2021-01-02 03:46:06 +00:00
|
|
|
function ed_on_save(ed)
|
2017-07-14 06:13:34 +00:00
|
|
|
{
|
2018-07-29 07:43:12 +00:00
|
|
|
function callback(response)
|
2017-07-14 06:13:34 +00:00
|
|
|
{
|
2021-01-02 03:46:06 +00:00
|
|
|
ed.hide_spinner();
|
|
|
|
|
2020-06-29 00:54:16 +00:00
|
|
|
if (response.meta.status != 200)
|
2019-01-13 23:05:03 +00:00
|
|
|
{
|
2020-06-29 00:54:16 +00:00
|
|
|
ed.show_error("Status: " + response.meta.status);
|
2019-01-13 23:05:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-02 03:46:06 +00:00
|
|
|
// The data coming back from the server will have been normalized.
|
|
|
|
ed.elements["title"].edit.value = response.data.title;
|
|
|
|
|
2018-07-28 22:17:18 +00:00
|
|
|
ed.save();
|
2021-01-02 03:46:06 +00:00
|
|
|
|
|
|
|
ed.elements["title"].display.href = response.data.url;
|
|
|
|
ed.elements["url"].display.href = response.data.url;
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
2019-01-13 23:05:03 +00:00
|
|
|
|
2021-01-02 03:46:06 +00:00
|
|
|
ed.elements["url"].edit.value = ed.elements["url"].edit.value.trim();
|
|
|
|
if (! ed.elements["url"].edit.value)
|
2018-09-23 22:43:42 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2020-09-15 01:33:53 +00:00
|
|
|
const bookmark_id = ed.misc_data["bookmark_id"];
|
2021-01-02 03:46:06 +00:00
|
|
|
const title = ed.elements["title"].edit.value;
|
|
|
|
const url = ed.elements["url"].edit.value;
|
2018-09-23 22:43:42 +00:00
|
|
|
|
|
|
|
ed.show_spinner();
|
|
|
|
api.bookmarks.edit(bookmark_id, title, url, callback);
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 03:46:06 +00:00
|
|
|
ed_on_cancel = undefined;
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2021-05-03 01:36:10 +00:00
|
|
|
function create_editor(bookmark_card)
|
|
|
|
{
|
|
|
|
const ed_elements = [
|
|
|
|
{
|
|
|
|
"id": "title",
|
|
|
|
"element": bookmark_card.getElementsByClassName("bookmark_title")[0],
|
|
|
|
"placeholder": "title (optional)",
|
|
|
|
"empty_text": bookmark_card.dataset.id,
|
|
|
|
"autofocus": true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "url",
|
|
|
|
"element": bookmark_card.getElementsByClassName("bookmark_url")[0],
|
|
|
|
"placeholder": "url",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
ed = new editor.Editor(ed_elements, ed_on_open, ed_on_save, ed_on_cancel);
|
|
|
|
ed.misc_data["bookmark_id"] = bookmark_card.dataset.id;
|
|
|
|
}
|
|
|
|
|
2017-07-14 06:13:34 +00:00
|
|
|
function create_editors()
|
|
|
|
{
|
2020-09-15 01:33:53 +00:00
|
|
|
const cards = document.getElementsByClassName("bookmark_card");
|
2020-09-03 22:33:37 +00:00
|
|
|
for (const card of cards)
|
2017-07-14 06:13:34 +00:00
|
|
|
{
|
2021-05-03 01:36:10 +00:00
|
|
|
if (card.id == "new_bookmark_card")
|
2021-01-08 21:41:49 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-03 01:36:10 +00:00
|
|
|
create_editor(card);
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 22:43:42 +00:00
|
|
|
|
|
|
|
function on_pageload()
|
|
|
|
{
|
|
|
|
create_editors();
|
|
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", on_pageload);
|
2016-11-29 04:18:44 +00:00
|
|
|
</script>
|
|
|
|
</html>
|