aboutsummaryrefslogtreecommitdiff
path: root/html/payload_create.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/payload_create.js')
-rw-r--r--html/payload_create.js31
1 files changed, 21 insertions, 10 deletions
diff --git a/html/payload_create.js b/html/payload_create.js
index db63a82..a5f9854 100644
--- a/html/payload_create.js
+++ b/html/payload_create.js
@@ -48,6 +48,9 @@
#FROM common/sha256.js IMPORT sha256
#FROM common/patterns.js IMPORT deconstruct_url
+const patterns_doc_url =
+ "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns";
+
/* https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid */
/* This is a helper function used by uuidv4(). */
function uuid_replace_num(num)
@@ -85,8 +88,6 @@ function collect_form_data(form_ctx)
try {
deconstruct_url(pattern);
} catch(e) {
- const patterns_doc_url =
- "https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns";
const patterns_doc_link = document.createElement("a");
patterns_doc_link.href = patterns_doc_url;
patterns_doc_link.innerText = "here";
@@ -97,7 +98,7 @@ function collect_form_data(form_ctx)
}
if (pattern in payloads)
- throw `Pattern '${pattern}' soecified multiple times!`;
+ throw `Pattern '${pattern}' specified multiple times!`;
payloads[pattern] = {identifier};
}
@@ -135,6 +136,15 @@ function collect_form_data(form_ctx)
return {identifier, resource, mapping, files: {[hash_key]: script}};
}
+function clear_form(form_ctx)
+{
+ form_ctx.identifier.value = "";
+ form_ctx.long_name.value = "";
+ form_ctx.description.value = "";
+ form_ctx.patterns.value = "https://example.com/***";
+ form_ctx.script.value = `console.log("Hello, World!");`;
+}
+
async function save_payload(saving)
{
const db = await haketilodb.get();
@@ -146,7 +156,7 @@ async function save_payload(saving)
if (!saving[`override_${type}`] &&
(await haketilodb.idb_get(tx_ctx.transaction, store_name,
saving.identifier))) {
- saving.ask_override = "resource";
+ saving.ask_override = type;
return;
}
}
@@ -160,8 +170,8 @@ async function save_payload(saving)
function override_question(saving)
{
return saving.ask_override === "resource" ?
- `Resource '${saving.identifier}' alredy exists. Override?` :
- `Mapping '${saving.identifier}' alredy exists. Override?`;
+ `Resource '${saving.identifier}' already exists. Override?` :
+ `Mapping '${saving.identifier}' already exists. Override?`;
}
async function create_clicked(form_ctx)
@@ -169,16 +179,15 @@ async function create_clicked(form_ctx)
if (form_ctx.dialog_ctx.shown)
return;
- dialog.loader(form_ctx.dialog_ctx, "Saving payload...");
-
try {
var saving = collect_form_data(form_ctx);
} catch(e) {
dialog.error(form_ctx.dialog_ctx, e);
- dialog.close(form_ctx.dialog_ctx);
return;
}
+ dialog.loader(form_ctx.dialog_ctx, "Saving payload...");
+
try {
do {
if (saving.ask_override) {
@@ -197,9 +206,10 @@ async function create_clicked(form_ctx)
} while (saving.ask_override);
dialog.info(form_ctx.dialog_ctx, "Successfully saved payload!");
+ clear_form(form_ctx);
} catch(e) {
console.error(e);
- dialog.error(form_ctx.dialog_ctx, "Failed to save payload :(")
+ dialog.error(form_ctx.dialog_ctx, "Failed to save payload :(");
}
dialog.close(form_ctx.dialog_ctx);
@@ -221,6 +231,7 @@ function payload_create_form()
() => on_show_hide(form_ctx, "form"));
form_ctx.dialog_container.prepend(form_ctx.dialog_ctx.main_div);
+ form_ctx.patterns_link.href = patterns_doc_url;
form_ctx.create_but.addEventListener("click",
() => create_clicked(form_ctx));