2016-11-29 04:18:44 +00:00
|
|
|
<!DOCTYPE html5>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
{% import "header.html" as header %}
|
|
|
|
<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">
|
|
|
|
<script src="/static/js/common.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>
|
2017-02-05 02:30:02 +00:00
|
|
|
#bookmarks
|
|
|
|
{
|
|
|
|
display: flex;
|
|
|
|
flex: 0 0 auto;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
2017-07-14 06:13:34 +00:00
|
|
|
.bookmark_card,
|
|
|
|
.new_bookmark_card
|
2017-02-05 02:30:02 +00:00
|
|
|
{
|
|
|
|
display: inline-flex;
|
|
|
|
flex: 0 0 auto;
|
|
|
|
flex-direction: column;
|
2017-03-31 02:34:39 +00:00
|
|
|
align-items: baseline;
|
|
|
|
|
2017-02-05 02:30:02 +00:00
|
|
|
padding: 8px;
|
|
|
|
margin: 8px;
|
2018-02-18 03:36:48 +00:00
|
|
|
width: 500px;
|
|
|
|
max-width: 500px;
|
2017-03-31 02:34:39 +00:00
|
|
|
|
2017-02-05 02:30:02 +00:00
|
|
|
border-radius: 8px;
|
2017-02-25 06:07:59 +00:00
|
|
|
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.25);
|
2017-03-31 02:34:39 +00:00
|
|
|
|
|
|
|
background-color: #ffffd4;
|
2017-02-05 02:30:02 +00:00
|
|
|
}
|
|
|
|
.bookmark_card .bookmark_url
|
|
|
|
{
|
|
|
|
color: #aaa;
|
|
|
|
}
|
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">
|
2017-02-05 02:30:02 +00:00
|
|
|
<div id="bookmarks">
|
|
|
|
{% for bookmark in bookmarks %}
|
2017-07-14 06:13:34 +00:00
|
|
|
<div class="bookmark_card" data-bookmark-id="{{bookmark.id}}">
|
2018-07-28 22:17:18 +00:00
|
|
|
<a
|
|
|
|
href="{{bookmark.url}}"
|
2017-07-14 06:13:34 +00:00
|
|
|
class="bookmark_title"
|
|
|
|
data-editor-id="title"
|
2018-02-18 03:36:48 +00:00
|
|
|
data-editor-placeholder="title (optional)"
|
2018-07-28 22:17:18 +00:00
|
|
|
data-editor-empty-text="{{bookmark.id}}"
|
|
|
|
>
|
|
|
|
{%- if bookmark.title -%}
|
|
|
|
{{bookmark.title}}
|
|
|
|
{%- else -%}
|
|
|
|
{{bookmark.id}}
|
|
|
|
{%- endif -%}
|
2017-02-05 02:30:02 +00:00
|
|
|
</a>
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2018-07-28 22:17:18 +00:00
|
|
|
<a
|
|
|
|
href="{{bookmark.url}}"
|
2017-07-14 06:13:34 +00:00
|
|
|
class="bookmark_url"
|
|
|
|
data-editor-id="url"
|
2018-07-28 22:17:18 +00:00
|
|
|
data-editor-placeholder="url"
|
|
|
|
>
|
|
|
|
{{-bookmark.url-}}
|
2017-07-14 06:13:34 +00:00
|
|
|
</a>
|
2018-07-29 07:36:50 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="red_button button_with_confirm"
|
|
|
|
data-onclick="delete_bookmark('{{bookmark.id}}')"
|
|
|
|
data-prompt="Delete Bookmark?"
|
|
|
|
data-confirm-class="red_button"
|
|
|
|
data-cancel-class="gray_button"
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</button>
|
2017-02-05 02:30:02 +00:00
|
|
|
</div>
|
|
|
|
{% endfor %}
|
2018-07-29 07:36:50 +00:00
|
|
|
|
2017-07-10 02:40:14 +00:00
|
|
|
<div class="new_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">
|
|
|
|
<button id="new_bookmark_button" class="green_button" onclick="submit_bookmark_form()">Create</button>
|
|
|
|
</div>
|
2017-02-05 02:30:02 +00:00
|
|
|
</div>
|
2016-11-29 04:18:44 +00:00
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2017-07-10 02:40:14 +00:00
|
|
|
function submit_bookmark_form()
|
|
|
|
{
|
|
|
|
var url = document.getElementById("new_bookmark_url").value.trim();
|
|
|
|
var title = document.getElementById("new_bookmark_title").value.trim();
|
|
|
|
if (!url)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return create_bookmark(url, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_bookmark(url, title)
|
|
|
|
{
|
|
|
|
var api_url = "/bookmarks/create_bookmark";
|
|
|
|
var data = new FormData();
|
|
|
|
data.append("url", url);
|
|
|
|
if (title)
|
|
|
|
{
|
|
|
|
data.append("title", title);
|
|
|
|
}
|
|
|
|
var callback = function(){location.reload();};
|
2018-07-23 02:12:08 +00:00
|
|
|
common.post(api_url, data, callback);
|
2017-07-10 02:40:14 +00:00
|
|
|
}
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2018-07-29 07:36:50 +00:00
|
|
|
function delete_bookmark(bookmark_id)
|
|
|
|
{
|
|
|
|
var url = `/bookmark/${bookmark_id}/delete`
|
|
|
|
var callback = function(){location.reload();};
|
|
|
|
common.post(url, null, callback);
|
|
|
|
}
|
|
|
|
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2018-07-28 22:17:18 +00:00
|
|
|
function on_open(ed, edit_element_map)
|
2017-07-17 00:26:34 +00:00
|
|
|
{
|
2018-07-28 22:17:18 +00:00
|
|
|
ed.open();
|
2017-07-17 00:26:34 +00:00
|
|
|
edit_element_map["title"].focus();
|
|
|
|
}
|
|
|
|
|
2018-07-29 07:43:12 +00:00
|
|
|
function on_save(ed, edit_element_map, display_element_map)
|
2017-07-14 06:13:34 +00:00
|
|
|
{
|
2017-07-17 00:26:34 +00:00
|
|
|
var title_editor = edit_element_map["title"];
|
|
|
|
var url_editor = edit_element_map["url"];
|
2018-02-18 03:36:48 +00:00
|
|
|
url_editor.value = url_editor.value.trim();
|
|
|
|
if (!url_editor.value)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-07-14 06:13:34 +00:00
|
|
|
|
2018-07-28 22:17:18 +00:00
|
|
|
ed.show_spinner();
|
2018-07-29 07:43:12 +00:00
|
|
|
function callback(response)
|
2017-07-14 06:13:34 +00:00
|
|
|
{
|
2018-07-28 22:17:18 +00:00
|
|
|
ed.hide_spinner();
|
|
|
|
ed.save();
|
2018-07-29 07:43:12 +00:00
|
|
|
display_element_map["title"].href = response["data"]["url"];
|
|
|
|
display_element_map["url"].href = response["data"]["url"];
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-28 22:17:18 +00:00
|
|
|
var url = "/bookmark/" + ed.misc_data["bookmark_id"] + "/edit";
|
2017-07-14 06:13:34 +00:00
|
|
|
var data = new FormData();
|
|
|
|
data.append("title", title_editor.value);
|
|
|
|
data.append("url", url_editor.value);
|
2018-07-23 02:12:08 +00:00
|
|
|
common.post(url, data, callback);
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
on_cancel = undefined;
|
|
|
|
|
|
|
|
function create_editors()
|
|
|
|
{
|
|
|
|
var cards = document.getElementsByClassName("bookmark_card");
|
|
|
|
for (var index = 0; index < cards.length; index += 1)
|
|
|
|
{
|
|
|
|
var card = cards[index];
|
|
|
|
var title_div = card.getElementsByClassName("bookmark_title")[0];
|
|
|
|
var url_div = card.getElementsByClassName("bookmark_url")[0];
|
2018-07-28 22:17:18 +00:00
|
|
|
ed = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel);
|
|
|
|
ed.misc_data["bookmark_id"] = card.dataset.bookmarkId;
|
2017-07-14 06:13:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
create_editors();
|
2016-11-29 04:18:44 +00:00
|
|
|
</script>
|
|
|
|
</html>
|