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)
|
||||
{
|
||||
var text = request.responseText;
|
||||
var response = JSON.parse(text);
|
||||
response["_request_url"] = url;
|
||||
response["_status"] = request.status;
|
||||
var response = {
|
||||
"data": JSON.parse(text),
|
||||
"meta": {}
|
||||
};
|
||||
response["meta"]["request_url"] = url;
|
||||
response["meta"]["status"] = request.status;
|
||||
callback(response);
|
||||
}
|
||||
}
|
||||
|
@ -293,9 +296,9 @@ function create_album_and_follow(parent)
|
|||
}
|
||||
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
|
||||
{
|
||||
|
|
|
@ -131,13 +131,15 @@ function _paste_unpaste_photo_clipboard(add_or_remove)
|
|||
var url = "/album/{{album.id}}/" + add_or_remove;
|
||||
var data = new FormData();
|
||||
data.append("photo_id", photo_ids);
|
||||
var callback = function(response){
|
||||
if (response["_status"] === 200)
|
||||
var callback = function(response)
|
||||
{
|
||||
if (response["meta"]["status"] !== 200)
|
||||
{
|
||||
return;
|
||||
}
|
||||
photo_clipboard.clear();
|
||||
save_photo_clipboard();
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
post(url, data, callback);
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ function submit_register()
|
|||
}
|
||||
function receive_callback(response)
|
||||
{
|
||||
response = response["data"];
|
||||
if ("error_type" in response)
|
||||
{
|
||||
create_message_bubble(message_area, "message_negative", response["error_message"], 8000);
|
||||
|
|
|
@ -281,21 +281,21 @@ function receive_callback(response)
|
|||
{
|
||||
var message_text;
|
||||
var message_positivity;
|
||||
var tagname = response["tagname"];
|
||||
if ("error_type" in response)
|
||||
var tagname = response["data"]["tagname"];
|
||||
if ("error_type" in response["data"])
|
||||
{
|
||||
message_positivity = "message_negative";
|
||||
message_text = response["error_message"];
|
||||
message_text = response["data"]["error_message"];
|
||||
}
|
||||
else
|
||||
{
|
||||
var action;
|
||||
message_positivity = "message_positive";
|
||||
if (response["_request_url"].includes("add_tag"))
|
||||
if (response["meta"]["request_url"].includes("add_tag"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -192,8 +192,9 @@ function 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))
|
||||
{
|
||||
responses = [responses];
|
||||
|
@ -256,10 +257,10 @@ function on_save(editor, edit_element_map, display_element_map)
|
|||
{
|
||||
console.log(response);
|
||||
editor.hide_spinner();
|
||||
if (response["_status"] == 200)
|
||||
if (response["meta"]["status"] == 200)
|
||||
{
|
||||
var new_name = response["name"];
|
||||
var new_description = response["description"];
|
||||
var new_name = response["data"]["name"];
|
||||
var new_description = response["data"]["description"];
|
||||
document.title = "Tag " + new_name;
|
||||
window.history.replaceState(null, null, "/tag/" + new_name);
|
||||
name_editor.value = new_name;
|
||||
|
|
Loading…
Reference in a new issue