From 2c5617207a27c07ecaa0f7e9ab987b05d564e3e9 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 16 Jul 2017 17:29:14 -0700 Subject: [PATCH] Add name and description editor. --- frontends/etiquette_flask/templates/tags.html | 70 ++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/frontends/etiquette_flask/templates/tags.html b/frontends/etiquette_flask/templates/tags.html index 9b89326..9103e69 100644 --- a/frontends/etiquette_flask/templates/tags.html +++ b/frontends/etiquette_flask/templates/tags.html @@ -3,7 +3,7 @@ {% import "header.html" as header %} {% import "tag_object.html" as tag_object %} - {% if specific is none %} + {% if specific_tag is none %} Tags {% else %} Tag {{specific_tag.name}} @@ -42,6 +42,12 @@ body background-color: rgba(0, 0, 0, 0.1); } +#description_text +{ + font-family: initial; + padding: 8px; + background-color: rgba(0, 0, 0, 0.1); +} #editor_area { display: flex; @@ -73,8 +79,23 @@ body
{% if specific_tag is not none %} -

{{specific_tag.name}}

-

{{specific_tag.description}}

+

+ + {{-specific_tag.name-}} + +

+
+                {{-specific_tag.description-}}
+            
{% endif %}
    {% for tag in tags %} @@ -182,5 +203,48 @@ function receive_callback(responses) create_message_bubble(message_area, message_positivity, message_text, 8000); } } + +{% if specific_tag is not none %} +function on_open(editor, edit_element_map) +{ + editor.open(); + edit_element_map["name"].focus(); +} + +function on_save(editor, edit_element_map, display_element_map) +{ + var name_display = display_element_map["name"]; + var name_editor = edit_element_map["name"]; + var description_editor = edit_element_map["description"]; + + editor.show_spinner(); + function callback(response) + { + console.log(response); + editor.hide_spinner(); + if (response["_status"] == 200) + { + var new_name = response["name"]; + var new_description = response["description"]; + document.title = "Tag " + new_name; + window.history.replaceState(null, null, "/tag/" + new_name); + name_editor.value = new_name; + description_editor.value = new_description; + editor.save(); + } + } + + var url = "/tag/" + name_display.innerText + "/edit"; + var data = new FormData(); + data.append("name", name_editor.value); + data.append("description", description_editor.value); + post(url, data, callback); +} +on_cancel = undefined; + +var name_text = document.getElementById("name_text"); +var description_text = document.getElementById("description_text"); +var editor = new Editor([name_text, description_text], on_open, on_save, on_cancel); +{% endif %}