Add alertresponse to a lot of callback functions.

master
voussoir 2020-11-06 22:50:05 -08:00
parent 0a31dad196
commit 12ee2adedf
5 changed files with 75 additions and 28 deletions

View File

@ -329,9 +329,16 @@ function rename_ed_on_save(ed, edit_element_map, display_element_map)
{ {
function callback(response) function callback(response)
{ {
if (response.meta.status != 200) ed.hide_spinner();
if (! response.meta.json_ok)
{ {
ed.show_error("Status: " + response.meta.status); alert(JSON.stringify(response));
return;
}
if ("error_type" in response.data)
{
ed.show_error(response.data.error_message);
return; return;
} }

View File

@ -209,6 +209,7 @@ function request_more_divs()
{ {
if (response.meta.status !== 200) if (response.meta.status !== 200)
{ {
alert(JSON.stringify(response));
return; return;
} }
for (photo_id in response.data) for (photo_id in response.data)
@ -238,6 +239,11 @@ photo_clipboard.on_save_hooks.push(my_clipboard_load_save_hook);
function add_remove_tag_callback(response) function add_remove_tag_callback(response)
{ {
if (! response.meta.json_ok)
{
alert(JSON.stringify(response));
return;
}
const tagname = response.data.tagname; const tagname = response.data.tagname;
const message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
let message_positivity; let message_positivity;
@ -309,6 +315,11 @@ const refresh_metadata_button = document.getElementById("refresh_metadata_button
function refresh_metadata_callback(response) function refresh_metadata_callback(response)
{ {
window[refresh_metadata_button.dataset.spinnerCloser](); window[refresh_metadata_button.dataset.spinnerCloser]();
if (! response.meta.json_ok)
{
alert(JSON.stringify(response));
return;
}
if ("error_type" in response.data) if ("error_type" in response.data)
{ {
const message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
@ -337,6 +348,11 @@ function refresh_metadata_form()
function set_unset_searchhidden_callback(response) function set_unset_searchhidden_callback(response)
{ {
if (! response.meta.json_ok)
{
alert(JSON.stringify(response));
return;
}
const message_area = document.getElementById("message_area"); const message_area = document.getElementById("message_area");
let message_positivity; let message_positivity;
let message_text; let message_text;

View File

@ -124,6 +124,11 @@ function register_form(event)
function login_register_callback(response) function login_register_callback(response)
{ {
if (! response.json_ok)
{
alert(JSON.stringify(response));
return;
}
if ("error_type" in response.data) if ("error_type" in response.data)
{ {
common.create_message_bubble(message_area, "message_negative", response.data.error_message); common.create_message_bubble(message_area, "message_negative", response.data.error_message);

View File

@ -299,8 +299,8 @@ function add_photo_tag_form()
function add_photo_tag_callback(response) function add_photo_tag_callback(response)
{ {
add_remove_photo_tag_callback(response); const abort = add_remove_photo_tag_callback(response);
if (response.meta.status !== 200) if (abort)
{ {
return; return;
} }
@ -335,8 +335,8 @@ function remove_photo_tag_form(photo_id, tagname)
function remove_photo_tag_callback(response) function remove_photo_tag_callback(response)
{ {
add_remove_photo_tag_callback(response); const abort = add_remove_photo_tag_callback(response);
if (response.meta.status !== 200) if (abort)
{ {
return; return;
} }
@ -353,12 +353,19 @@ function remove_photo_tag_callback(response)
function add_remove_photo_tag_callback(response) function add_remove_photo_tag_callback(response)
{ {
if (! response.meta.json_ok)
{
alert(JSON.stringify(response));
return;
}
let message_text; let message_text;
let message_positivity; let message_positivity;
let abort;
if ("error_type" in response.data) if ("error_type" in response.data)
{ {
message_positivity = "message_negative"; message_positivity = "message_negative";
message_text = response.data.error_message; message_text = response.data.error_message;
abort = true;
} }
else else
{ {
@ -373,12 +380,10 @@ function add_remove_photo_tag_callback(response)
{ {
message_text = "Removed tag " + tagname; message_text = "Removed tag " + tagname;
} }
else abort = false;
{
return;
}
} }
common.create_message_bubble(message_area, message_positivity, message_text, 8000); common.create_message_bubble(message_area, message_positivity, message_text, 8000);
return abort;
} }
function delete_photo_form() function delete_photo_form()
@ -400,20 +405,26 @@ function generate_thumbnail_for_video_form()
function generate_thumbnail_callback(response) function generate_thumbnail_callback(response)
{ {
const generate_thumbnail_button = document.getElementById("generate_thumbnail_button");
window[generate_thumbnail_button.dataset.spinnerCloser]();
if (! response.meta.json_ok)
{
alert(JSON.stringify(response));
return;
}
if (response.meta.status == 200) if (response.meta.status == 200)
{ {
common.create_message_bubble(message_area, "message_positive", "Thumbnail captured", 8000); common.create_message_bubble(message_area, "message_positive", "Thumbnail captured", 8000);
} }
else if (response.meta.json_ok) else if ("error_type" in response.data)
{ {
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);
} }
else else
{ {
alert(JSON.stringify(response)); alert(JSON.stringify(response));
return;
} }
const generate_thumbnail_button = document.getElementById("generate_thumbnail_button");
window[generate_thumbnail_button.dataset.spinnerCloser]();
} }
function refresh_metadata_form() function refresh_metadata_form()

View File

@ -329,6 +329,12 @@ function remove_synonym_form(event)
function tag_action_callback(response) function tag_action_callback(response)
{ {
if (response.meta.status !== 200)
{
alert(JSON.stringify(response));
return;
}
let datas = response.data; let datas = response.data;
if (!Array.isArray(datas)) if (!Array.isArray(datas))
{ {
@ -387,23 +393,25 @@ function rename_ed_on_save(ed, edit_element_map, display_element_map)
{ {
function callback(response) function callback(response)
{ {
console.log(response);
ed.hide_spinner(); ed.hide_spinner();
if (response.meta.status == 200) if (response.meta.status !== 200)
{ {
const new_name = response.data.name; alert(JSON.stringify(response));
const new_description = response.data.description; return;
document.title = new_name + " | Tags"; }
SPECIFIC_TAG = new_name;
window.history.replaceState(null, null, "/tag/" + new_name); const new_name = response.data.name;
name_editor.value = new_name; const new_description = response.data.description;
name_display.href = "/search?tag_musts=" + new_name; document.title = new_name + " | Tags";
description_editor.value = new_description; SPECIFIC_TAG = new_name;
ed.save(); window.history.replaceState(null, null, "/tag/" + new_name);
if (new_description === "") name_editor.value = new_name;
{ name_display.href = "/search?tag_musts=" + new_name;
description_display.classList.add("hidden"); description_editor.value = new_description;
} ed.save();
if (new_description === "")
{
description_display.classList.add("hidden");
} }
} }