From 0e17350d846a13573d4097f3b70891f038773261 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 13 Jul 2017 23:13:34 -0700 Subject: [PATCH] Add Editor elements for bookmarks. --- frontends/etiquette_flask/static/common.js | 2 + .../etiquette_flask/templates/bookmarks.html | 56 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/frontends/etiquette_flask/static/common.js b/frontends/etiquette_flask/static/common.js index d5327e7..23f4c6e 100644 --- a/frontends/etiquette_flask/static/common.js +++ b/frontends/etiquette_flask/static/common.js @@ -94,6 +94,8 @@ function Editor(elements, on_open, on_save, on_cancel) this.can_use_element_map = true; this.edit_element_map = {}; + this.misc_data = {}; + for (var index = 0; index < elements.length; index += 1) { var display_element = elements[index]; diff --git a/frontends/etiquette_flask/templates/bookmarks.html b/frontends/etiquette_flask/templates/bookmarks.html index 4a5fde1..0c1da8b 100644 --- a/frontends/etiquette_flask/templates/bookmarks.html +++ b/frontends/etiquette_flask/templates/bookmarks.html @@ -14,7 +14,8 @@ flex: 0 0 auto; flex-direction: column; } -.bookmark_card +.bookmark_card, +.new_bookmark_card { display: inline-flex; flex: 0 0 auto; @@ -42,15 +43,25 @@
{% for bookmark in bookmarks %} -
- + {% endfor %}
@@ -87,5 +98,42 @@ function create_bookmark(url, title) var callback = function(){location.reload();}; post(api_url, data, callback); } + + +function on_save(editor, edit_element_map) +{ + var title_editor = edit_element_map['title']; + var url_editor = edit_element_map['url']; + + editor.show_spinner(); + function callback() + { + editor.hide_spinner(); + editor.save(); + } + + var url = "/bookmark/" + editor.misc_data["bookmark_id"] + "/edit"; + var data = new FormData(); + data.append("title", title_editor.value); + data.append("url", url_editor.value); + post(url, data, callback); +} + +on_open = undefined; +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]; + editor = new Editor([title_div, url_div], on_open, on_save, on_cancel); + editor.misc_data["bookmark_id"] = card.dataset.bookmarkId; + } +} +create_editors();