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) | ||||
|     { | ||||
|         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; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -209,6 +209,7 @@ function request_more_divs() | |||
|     { | ||||
|         if (response.meta.status !== 200) | ||||
|         { | ||||
|             alert(JSON.stringify(response)); | ||||
|             return; | ||||
|         } | ||||
|         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) | ||||
| { | ||||
|     if (! response.meta.json_ok) | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
|     const tagname = response.data.tagname; | ||||
|     const message_area = document.getElementById("message_area"); | ||||
|     let message_positivity; | ||||
|  | @ -309,6 +315,11 @@ const refresh_metadata_button = document.getElementById("refresh_metadata_button | |||
| function refresh_metadata_callback(response) | ||||
| { | ||||
|     window[refresh_metadata_button.dataset.spinnerCloser](); | ||||
|     if (! response.meta.json_ok) | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
|     if ("error_type" in response.data) | ||||
|     { | ||||
|         const message_area = document.getElementById("message_area"); | ||||
|  | @ -337,6 +348,11 @@ function refresh_metadata_form() | |||
| 
 | ||||
| function set_unset_searchhidden_callback(response) | ||||
| { | ||||
|     if (! response.meta.json_ok) | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
|     const message_area = document.getElementById("message_area"); | ||||
|     let message_positivity; | ||||
|     let message_text; | ||||
|  |  | |||
|  | @ -124,6 +124,11 @@ function register_form(event) | |||
| 
 | ||||
| function login_register_callback(response) | ||||
| { | ||||
|     if (! response.json_ok) | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
|     if ("error_type" in response.data) | ||||
|     { | ||||
|         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) | ||||
| { | ||||
|     add_remove_photo_tag_callback(response); | ||||
|     if (response.meta.status !== 200) | ||||
|     const abort = add_remove_photo_tag_callback(response); | ||||
|     if (abort) | ||||
|     { | ||||
|         return; | ||||
|     } | ||||
|  | @ -335,8 +335,8 @@ function remove_photo_tag_form(photo_id, tagname) | |||
| 
 | ||||
| function remove_photo_tag_callback(response) | ||||
| { | ||||
|     add_remove_photo_tag_callback(response); | ||||
|     if (response.meta.status !== 200) | ||||
|     const abort = add_remove_photo_tag_callback(response); | ||||
|     if (abort) | ||||
|     { | ||||
|         return; | ||||
|     } | ||||
|  | @ -353,12 +353,19 @@ function 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_positivity; | ||||
|     let abort; | ||||
|     if ("error_type" in response.data) | ||||
|     { | ||||
|         message_positivity = "message_negative"; | ||||
|         message_text = response.data.error_message; | ||||
|         abort = true; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|  | @ -373,12 +380,10 @@ function add_remove_photo_tag_callback(response) | |||
|         { | ||||
|             message_text = "Removed tag " + tagname; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|         abort = false; | ||||
|     } | ||||
|     common.create_message_bubble(message_area, message_positivity, message_text, 8000); | ||||
|     return abort; | ||||
| } | ||||
| 
 | ||||
| function delete_photo_form() | ||||
|  | @ -400,20 +405,26 @@ function generate_thumbnail_for_video_form() | |||
| 
 | ||||
| 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) | ||||
|     { | ||||
|         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); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
|     const generate_thumbnail_button = document.getElementById("generate_thumbnail_button"); | ||||
|     window[generate_thumbnail_button.dataset.spinnerCloser](); | ||||
| } | ||||
| 
 | ||||
| function refresh_metadata_form() | ||||
|  |  | |||
|  | @ -329,6 +329,12 @@ function remove_synonym_form(event) | |||
| 
 | ||||
| function tag_action_callback(response) | ||||
| { | ||||
|     if (response.meta.status !== 200) | ||||
|     { | ||||
|         alert(JSON.stringify(response)); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     let datas = response.data; | ||||
|     if (!Array.isArray(datas)) | ||||
|     { | ||||
|  | @ -387,23 +393,25 @@ function rename_ed_on_save(ed, edit_element_map, display_element_map) | |||
| { | ||||
|     function callback(response) | ||||
|     { | ||||
|         console.log(response); | ||||
|         ed.hide_spinner(); | ||||
|         if (response.meta.status == 200) | ||||
|         if (response.meta.status !== 200) | ||||
|         { | ||||
|             const new_name = response.data.name; | ||||
|             const new_description = response.data.description; | ||||
|             document.title = new_name + " | Tags"; | ||||
|             SPECIFIC_TAG = new_name; | ||||
|             window.history.replaceState(null, null, "/tag/" + new_name); | ||||
|             name_editor.value = new_name; | ||||
|             name_display.href = "/search?tag_musts=" + new_name; | ||||
|             description_editor.value = new_description; | ||||
|             ed.save(); | ||||
|             if (new_description === "") | ||||
|             { | ||||
|                 description_display.classList.add("hidden"); | ||||
|             } | ||||
|             alert(JSON.stringify(response)); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const new_name = response.data.name; | ||||
|         const new_description = response.data.description; | ||||
|         document.title = new_name + " | Tags"; | ||||
|         SPECIFIC_TAG = new_name; | ||||
|         window.history.replaceState(null, null, "/tag/" + new_name); | ||||
|         name_editor.value = new_name; | ||||
|         name_display.href = "/search?tag_musts=" + new_name; | ||||
|         description_editor.value = new_description; | ||||
|         ed.save(); | ||||
|         if (new_description === "") | ||||
|         { | ||||
|             description_display.classList.add("hidden"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue