Add spinner.BAIL for cancelling spinner without launching callback.
This commit is contained in:
		
							parent
							
								
									0518765f33
								
							
						
					
					
						commit
						98fae96a8a
					
				
					 2 changed files with 27 additions and 7 deletions
				
			
		|  | @ -1,5 +1,17 @@ | |||
| var spinner = {}; | ||||
| 
 | ||||
| /* | ||||
| In general, spinners are used for functions that launch a callback, and the | ||||
| callback will close the spinner after it runs. But, if your initial function | ||||
| decides not to launch the callback (insufficient parameters, failed clientside | ||||
| checks, etc.), you can have it return spinner.BAIL and the spinners will close | ||||
| immediately. Of course, you're always welcome to use | ||||
| window[button.dataset.spinnerCloser](), but this return value means you don't | ||||
| need to pull the button into a variable, as long as you weren't using the | ||||
| return value anyway. | ||||
| */ | ||||
| spinner.BAIL = "spinner.BAIL"; | ||||
| 
 | ||||
| spinner.Spinner = | ||||
| function Spinner(element) | ||||
| { | ||||
|  | @ -32,10 +44,12 @@ function Spinner(element) | |||
| 
 | ||||
| spinner.spinner_button_index = 0; | ||||
| spinner.button_spinner_groups = {}; | ||||
| // When a group member is closing, it will call the closer on all other members
 | ||||
| // in the group. Of course, this would recurse forever without some kind of
 | ||||
| // flagging, so this dict will hold group_id:true if a close is in progress,
 | ||||
| // and be empty otherwise.
 | ||||
| /* | ||||
| When a group member is closing, it will call the closer on all other members | ||||
| in the group. Of course, this would recurse forever without some kind of | ||||
| flagging, so this dict will hold group_id:true if a close is in progress, | ||||
| and be empty otherwise. | ||||
| */ | ||||
| spinner.spinner_group_closing = {}; | ||||
| 
 | ||||
| spinner.add_to_spinner_group = | ||||
|  | @ -161,7 +175,12 @@ function init_button_with_spinner() | |||
|             { | ||||
|                 window[button.dataset.spinnerOpener](); | ||||
|             } | ||||
|             return wrapped_onclick(); | ||||
|             const ret = wrapped_onclick(); | ||||
|             if (ret === spinner.BAIL) | ||||
|             { | ||||
|                 window[button.dataset.spinnerCloser](); | ||||
|             } | ||||
|             return ret; | ||||
|         } | ||||
| 
 | ||||
|         spinner.spinner_button_index += 1; | ||||
|  |  | |||
|  | @ -76,10 +76,11 @@ common.bind_box_to_button(box, button); | |||
| 
 | ||||
| function add_channel_form() | ||||
| { | ||||
|     if (box.value !== "") | ||||
|     if (box.value === "") | ||||
|     { | ||||
|         api.channels.add_channel(box.value, add_channel_callback); | ||||
|         return spinner.BAIL; | ||||
|     } | ||||
|     api.channels.add_channel(box.value, add_channel_callback); | ||||
| } | ||||
| function add_channel_callback(response) | ||||
| { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue