Add alertresponse to a lot of callback functions.
This commit is contained in:
		
							parent
							
								
									0a31dad196
								
							
						
					
					
						commit
						12ee2adedf
					
				
					 5 changed files with 75 additions and 28 deletions
				
			
		|  | @ -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; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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; | ||||||
|  |  | ||||||
|  | @ -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); | ||||||
|  |  | ||||||
|  | @ -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() | ||||||
|  |  | ||||||
|  | @ -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,10 +393,13 @@ 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) | ||||||
|         { |         { | ||||||
|  |             alert(JSON.stringify(response)); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         const new_name = response.data.name; |         const new_name = response.data.name; | ||||||
|         const new_description = response.data.description; |         const new_description = response.data.description; | ||||||
|         document.title = new_name + " | Tags"; |         document.title = new_name + " | Tags"; | ||||||
|  | @ -405,7 +414,6 @@ function rename_ed_on_save(ed, edit_element_map, display_element_map) | ||||||
|             description_display.classList.add("hidden"); |             description_display.classList.add("hidden"); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     const name_display = display_element_map["name"]; |     const name_display = display_element_map["name"]; | ||||||
|     const name_editor = edit_element_map["name"]; |     const name_editor = edit_element_map["name"]; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue