aboutsummaryrefslogtreecommitdiff
path: root/html/dialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/dialog.js')
-rw-r--r--html/dialog.js33
1 files changed, 25 insertions, 8 deletions
diff --git a/html/dialog.js b/html/dialog.js
index 6345b2d..22e8aa9 100644
--- a/html/dialog.js
+++ b/html/dialog.js
@@ -42,7 +42,7 @@
*/
#FROM html/DOM_helpers.js IMPORT clone_template
-#FROM common/lock.js IMPORT make_lock, lock, unlock
+#FROM common/lock.js IMPORT make_lock, lock, try_lock, unlock
function make(on_dialog_show, on_dialog_hide)
{
@@ -68,9 +68,15 @@ function make(on_dialog_show, on_dialog_hide)
function close_dialog(dialog_context, event)
{
+ if (event && event.target.parentElement.classList.contains("hide"))
+ return;
+
+ const result = event ? event.target.haketilo_dialog_result : undefined;
+
if (dialog_context.queue > 0)
- dialog_context.callback(event.target.haketilo_dialog_result);
+ dialog_context.callback(result);
}
+#EXPORT close_dialog AS close
async function show_dialog(dialog_context, shown_buts_id, msg)
{
@@ -81,11 +87,19 @@ async function show_dialog(dialog_context, shown_buts_id, msg)
dialog_context.on_dialog_show();
}
- await lock(dialog_context.lock);
-
- dialog_context.msg.innerText = msg;
+ /*
+ * We want the dialog to be ready for calling close() right after
+ * show_dialog() gets called. For this, we want locking to happen
+ * synchronously if possible. If impossible (lock taken), this means dialog
+ * is already open, hence it's also ready for close()'ing.
+ */
+ if (!try_lock(dialog_context.lock))
+ await lock(dialog_context.lock);
+
+ [...dialog_context.msg.childNodes].forEach(n => n.remove());
+ dialog_context.msg.append(...msg);
for (const buts_id of ["ask_buts", "conf_buts"]) {
- const action = buts_id == shown_buts_id ? "remove" : "add";
+ const action = buts_id === shown_buts_id ? "remove" : "add";
dialog_context[buts_id].classList[action]("hide");
}
@@ -101,12 +115,15 @@ async function show_dialog(dialog_context, shown_buts_id, msg)
return result;
}
-const error = (ctx, msg) => show_dialog(ctx, "conf_buts", msg);
+const error = (ctx, ...msg) => show_dialog(ctx, "conf_buts", msg);
#EXPORT error
/* info() and error() are the same for now, we might later change that. */
const info = error;
#EXPORT info
-const ask = (ctx, msg) => show_dialog(ctx, "ask_buts", msg);
+const ask = (ctx, ...msg) => show_dialog(ctx, "ask_buts", msg);
#EXPORT ask
+
+const loader = (ctx, ...msg) => show_dialog(ctx, null, msg);
+#EXPORT loader