Add spinner.BAIL for cancelling spinner without launching callback.

master
voussoir 2020-09-04 11:25:11 -07:00
parent 7f48c3e97c
commit 139998172f
2 changed files with 25 additions and 7 deletions

View File

@ -1,5 +1,17 @@
var spinner = {}; 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 = spinner.Spinner =
function Spinner(element) function Spinner(element)
{ {
@ -32,10 +44,12 @@ function Spinner(element)
spinner.spinner_button_index = 0; spinner.spinner_button_index = 0;
spinner.button_spinner_groups = {}; 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 When a group member is closing, it will call the closer on all other members
// flagging, so this dict will hold group_id:true if a close is in progress, in the group. Of course, this would recurse forever without some kind of
// and be empty otherwise. flagging, so this dict will hold group_id:true if a close is in progress,
and be empty otherwise.
*/
spinner.spinner_group_closing = {}; spinner.spinner_group_closing = {};
spinner.add_to_spinner_group = spinner.add_to_spinner_group =
@ -161,7 +175,12 @@ function init_button_with_spinner()
{ {
window[button.dataset.spinnerOpener](); 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; spinner.spinner_button_index += 1;

View File

@ -330,8 +330,7 @@ function refresh_metadata_form()
{ {
if (photo_clipboard.clipboard.size == 0) if (photo_clipboard.clipboard.size == 0)
{ {
window[refresh_metadata_button.dataset.spinnerCloser](); return spinner.BAIL;
return;
} }
let photo_ids = Array.from(photo_clipboard.clipboard); let photo_ids = Array.from(photo_clipboard.clipboard);