Split HTTP response dict into ["meta"] and ["data"].
This commit is contained in:
parent
f4756d97e4
commit
ef5bbf5fc3
5 changed files with 26 additions and 19 deletions
|
@ -245,9 +245,12 @@ function _request(method, url, callback)
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
{
|
{
|
||||||
var text = request.responseText;
|
var text = request.responseText;
|
||||||
var response = JSON.parse(text);
|
var response = {
|
||||||
response["_request_url"] = url;
|
"data": JSON.parse(text),
|
||||||
response["_status"] = request.status;
|
"meta": {}
|
||||||
|
};
|
||||||
|
response["meta"]["request_url"] = url;
|
||||||
|
response["meta"]["status"] = request.status;
|
||||||
callback(response);
|
callback(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,9 +296,9 @@ function create_album_and_follow(parent)
|
||||||
}
|
}
|
||||||
function receive_callback(response)
|
function receive_callback(response)
|
||||||
{
|
{
|
||||||
if (response["_status"] == 200 && response["id"])
|
if (response["meta"]["status"] == 200 && response["data"]["id"])
|
||||||
{
|
{
|
||||||
window.location.href = "/album/" + response["id"];
|
window.location.href = "/album/" + response["data"]["id"];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,13 +131,15 @@ function _paste_unpaste_photo_clipboard(add_or_remove)
|
||||||
var url = "/album/{{album.id}}/" + add_or_remove;
|
var url = "/album/{{album.id}}/" + add_or_remove;
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append("photo_id", photo_ids);
|
data.append("photo_id", photo_ids);
|
||||||
var callback = function(response){
|
var callback = function(response)
|
||||||
if (response["_status"] === 200)
|
|
||||||
{
|
{
|
||||||
|
if (response["meta"]["status"] !== 200)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
photo_clipboard.clear();
|
photo_clipboard.clear();
|
||||||
save_photo_clipboard();
|
save_photo_clipboard();
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
post(url, data, callback);
|
post(url, data, callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,7 @@ function submit_register()
|
||||||
}
|
}
|
||||||
function receive_callback(response)
|
function receive_callback(response)
|
||||||
{
|
{
|
||||||
|
response = response["data"];
|
||||||
if ("error_type" in response)
|
if ("error_type" in response)
|
||||||
{
|
{
|
||||||
create_message_bubble(message_area, "message_negative", response["error_message"], 8000);
|
create_message_bubble(message_area, "message_negative", response["error_message"], 8000);
|
||||||
|
|
|
@ -281,21 +281,21 @@ function receive_callback(response)
|
||||||
{
|
{
|
||||||
var message_text;
|
var message_text;
|
||||||
var message_positivity;
|
var message_positivity;
|
||||||
var tagname = response["tagname"];
|
var tagname = response["data"]["tagname"];
|
||||||
if ("error_type" in response)
|
if ("error_type" in response["data"])
|
||||||
{
|
{
|
||||||
message_positivity = "message_negative";
|
message_positivity = "message_negative";
|
||||||
message_text = response["error_message"];
|
message_text = response["data"]["error_message"];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var action;
|
var action;
|
||||||
message_positivity = "message_positive";
|
message_positivity = "message_positive";
|
||||||
if (response["_request_url"].includes("add_tag"))
|
if (response["meta"]["request_url"].includes("add_tag"))
|
||||||
{
|
{
|
||||||
message_text = "Added tag " + tagname;
|
message_text = "Added tag " + tagname;
|
||||||
}
|
}
|
||||||
else if (response["_request_url"].includes("remove_tag"))
|
else if (response["meta"]["request_url"].includes("remove_tag"))
|
||||||
{
|
{
|
||||||
message_text = "Removed tag " + tagname;
|
message_text = "Removed tag " + tagname;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,8 +192,9 @@ function create_tag(tagname, callback)
|
||||||
return edit_tags("create_tag", tagname, callback);
|
return edit_tags("create_tag", tagname, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function receive_callback(responses)
|
function receive_callback(response)
|
||||||
{
|
{
|
||||||
|
responses = response["data"];
|
||||||
if (!(responses instanceof Array))
|
if (!(responses instanceof Array))
|
||||||
{
|
{
|
||||||
responses = [responses];
|
responses = [responses];
|
||||||
|
@ -256,10 +257,10 @@ function on_save(editor, edit_element_map, display_element_map)
|
||||||
{
|
{
|
||||||
console.log(response);
|
console.log(response);
|
||||||
editor.hide_spinner();
|
editor.hide_spinner();
|
||||||
if (response["_status"] == 200)
|
if (response["meta"]["status"] == 200)
|
||||||
{
|
{
|
||||||
var new_name = response["name"];
|
var new_name = response["data"]["name"];
|
||||||
var new_description = response["description"];
|
var new_description = response["data"]["description"];
|
||||||
document.title = "Tag " + new_name;
|
document.title = "Tag " + new_name;
|
||||||
window.history.replaceState(null, null, "/tag/" + new_name);
|
window.history.replaceState(null, null, "/tag/" + new_name);
|
||||||
name_editor.value = new_name;
|
name_editor.value = new_name;
|
||||||
|
|
Loading…
Reference in a new issue