From 7c4229f1faae74a19c8acbda33300b3389d22c1b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 28 Jun 2020 17:54:16 -0700 Subject: [PATCH] Use dot notation instead of subscript for response. --- .../etiquette_flask/templates/album.html | 4 +-- .../etiquette_flask/templates/bookmarks.html | 8 ++--- .../etiquette_flask/templates/clipboard.html | 30 ++++++++----------- .../etiquette_flask/templates/login.html | 5 ++-- .../etiquette_flask/templates/photo.html | 14 ++++----- frontends/etiquette_flask/templates/tags.html | 28 ++++++++--------- 6 files changed, 42 insertions(+), 47 deletions(-) diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 6397c55..a061198 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -338,9 +338,9 @@ function on_save(ed, edit_element_map, display_element_map) { function callback(response) { - if (response["meta"]["status"] != 200) + if (response.meta.status != 200) { - ed.show_error("Status: " + response["meta"]["status"]); + ed.show_error("Status: " + response.meta.status); return; } diff --git a/frontends/etiquette_flask/templates/bookmarks.html b/frontends/etiquette_flask/templates/bookmarks.html index cef376e..4a242cd 100644 --- a/frontends/etiquette_flask/templates/bookmarks.html +++ b/frontends/etiquette_flask/templates/bookmarks.html @@ -119,15 +119,15 @@ function on_save(ed, edit_element_map, display_element_map) { function callback(response) { - if (response["meta"]["status"] != 200) + if (response.meta.status != 200) { - ed.show_error("Status: " + response["meta"]["status"]); + ed.show_error("Status: " + response.meta.status); return; } ed.save(); - display_element_map["title"].href = response["data"]["url"]; - display_element_map["url"].href = response["data"]["url"]; + display_element_map["title"].href = response.data.url; + display_element_map["url"].href = response.data.url; } edit_element_map["url"].value = edit_element_map["url"].value.trim(); diff --git a/frontends/etiquette_flask/templates/clipboard.html b/frontends/etiquette_flask/templates/clipboard.html index 4500128..4c07952 100644 --- a/frontends/etiquette_flask/templates/clipboard.html +++ b/frontends/etiquette_flask/templates/clipboard.html @@ -194,15 +194,14 @@ function request_more_divs() data.append("photo_ids", photo_ids); function callback(response) { - if (response["meta"]["status"] !== 200) + if (response.meta.status !== 200) { return; } - response = response["data"]; var holder = document.getElementById("photo_card_holder"); - for (photo_id in response) + for (photo_id in response.data) { - photo_div = common.html_to_element(response[photo_id]); + photo_div = common.html_to_element(response.data[photo_id]); divs[photo_id] = photo_div; needed.delete(photo_id) holder.appendChild(photo_div); @@ -238,20 +237,19 @@ function add_remove_tag(action, tagname) } function add_remove_tag_callback(response) { - response = response["data"]; - var tagname = response["tagname"]; + var tagname = response.data.tagname; var message_area = document.getElementById("message_area"); var message_positivity; var message_text; - if ("error_type" in response) + if ("error_type" in response.data) { message_positivity = "message_negative"; - message_text = response["error_message"]; + message_text = response.data.error_message; } - else if ("action" in response) + else if ("action" in response.data) { - var action = response["action"]; + var action = response.data.action; message_positivity = "message_positive"; if (action == "add") {message_text = "Added tag " + tagname;} @@ -286,7 +284,7 @@ function remove_tag_form() function download_zip_callback(response) { - var zip_token = response["data"]["zip_token"]; + var zip_token = response.data.zip_token; var url = `/batch/photos/download_zip/${zip_token}.zip`; window.location.href = url; } @@ -308,13 +306,12 @@ var refresh_metadata_button = document.getElementById("refresh_metadata_button") function refresh_metadata_callback(response) { - response = response["data"]; window[refresh_metadata_button.dataset.spinnerCloser](); - if ("error_type" in response) + if ("error_type" in response.data) { var message_area = document.getElementById("message_area"); var message_positivity = "message_negative"; - var message_text = response["error_message"]; + var message_text = response.data.error_message; common.create_message_bubble(message_area, message_positivity, message_text, 8000); } else @@ -342,14 +339,13 @@ function refresh_metadata_form() function set_unset_searchhidden_callback(response) { - response = response["data"]; var message_area = document.getElementById("message_area"); var message_positivity; var message_text; - if ("error_type" in response) + if ("error_type" in response.data) { message_positivity = "message_negative"; - message_text = response["error_message"]; + message_text = response.data.error_message; } else { diff --git a/frontends/etiquette_flask/templates/login.html b/frontends/etiquette_flask/templates/login.html index 2aec498..e6761a4 100644 --- a/frontends/etiquette_flask/templates/login.html +++ b/frontends/etiquette_flask/templates/login.html @@ -118,10 +118,9 @@ function register_form(event) function login_register_callback(response) { - response = response["data"]; - if ("error_type" in response) + if ("error_type" in response.data) { - common.create_message_bubble(message_area, "message_negative", response["error_message"]); + common.create_message_bubble(message_area, "message_negative", response.data.error_message); return; } else diff --git a/frontends/etiquette_flask/templates/photo.html b/frontends/etiquette_flask/templates/photo.html index 274faf1..e525cd4 100644 --- a/frontends/etiquette_flask/templates/photo.html +++ b/frontends/etiquette_flask/templates/photo.html @@ -302,21 +302,21 @@ function add_remove_photo_tag_callback(response) { var message_text; var message_positivity; - var tagname = response["data"]["tagname"]; - if ("error_type" in response["data"]) + var tagname = response.data.tagname; + if ("error_type" in response.data) { message_positivity = "message_negative"; - message_text = response["data"]["error_message"]; + message_text = response.data.error_message; } else { var action; message_positivity = "message_positive"; - if (response["meta"]["request_url"].includes("add_tag")) + if (response.meta.request_url.includes("add_tag")) { message_text = "Added tag " + tagname; } - else if (response["meta"]["request_url"].includes("remove_tag")) + else if (response.meta.request_url.includes("remove_tag")) { message_text = "Removed tag " + tagname; } @@ -330,13 +330,13 @@ function add_remove_photo_tag_callback(response) function generate_thumbnail_callback(response) { - if (response["meta"]["status"] == 200) + if (response.meta.status == 200) { common.create_message_bubble(message_area, "message_positive", "Thumbnail captured", 8000); } else { - common.create_message_bubble(message_area, "message_negative", response["data"]["error_message"], 8000); + common.create_message_bubble(message_area, "message_negative", response.data.error_message, 8000); } generate_thumbnail_button = document.getElementById("generate_thumbnail_button"); window[generate_thumbnail_button.dataset.spinnerCloser](); diff --git a/frontends/etiquette_flask/templates/tags.html b/frontends/etiquette_flask/templates/tags.html index 0d4d54e..350196e 100644 --- a/frontends/etiquette_flask/templates/tags.html +++ b/frontends/etiquette_flask/templates/tags.html @@ -246,25 +246,25 @@ function easybake_form() function tag_action_callback(response) { - responses = response["data"]; - if (!(responses instanceof Array)) + datas = response.data; + if (!(datas instanceof Array)) { - responses = [responses]; + datas = [datas]; } - for (var index = 0; index < responses.length; index += 1) + for (var index = 0; index < datas.length; index += 1) { - var response = responses[index]; - var tagname = response["tagname"]; + var data = datas[index]; + var tagname = data.tagname; var message_positivity; var message_text; - if ("error_type" in response) + if ("error_type" in data) { message_positivity = "message_negative"; - message_text = response["error_message"]; + message_text = data.error_message; } - else if ("action" in response) + else if ("action" in data) { - var action = response["action"]; + var action = data.action; message_positivity = "message_positive"; if (action == "new_tag") {message_text = `Created tag ${tagname}`;} @@ -285,7 +285,7 @@ function tag_action_callback(response) {message_text = `Deleted tag ${tagname}`;} else if (action == "delete_synonym") - {message_text = `Deleted synonym ${response["synonym"]}`;} + {message_text = `Deleted synonym ${data.synonym}`;} else if (action == "remove_child") {message_text = `Unlinked tags ${tagname}`;} @@ -308,10 +308,10 @@ function on_save(ed, edit_element_map, display_element_map) { console.log(response); ed.hide_spinner(); - if (response["meta"]["status"] == 200) + if (response.meta.status == 200) { - var new_name = response["data"]["name"]; - var new_description = response["data"]["description"]; + var new_name = response.data.name; + var new_description = response.data.description; document.title = new_name + " | Tags"; window.history.replaceState(null, null, "/tag/" + new_name); name_editor.value = new_name;