a
This commit is contained in:
+46
-1
@@ -266,6 +266,45 @@ function syncResponseCheckUi() {
|
||||
if (adv) adv.classList.toggle("show", !!on);
|
||||
}
|
||||
|
||||
function fillLatchResetForm(lr) {
|
||||
const latchEl = $("#b-latch-enabled");
|
||||
if (!latchEl) return;
|
||||
const enabled = lr ? !!lr.enabled : true;
|
||||
latchEl.checked = enabled;
|
||||
$("#b-reset-url").value = lr?.resetUrl || "";
|
||||
$("#b-success-match").value = lr?.successMatch || "OK";
|
||||
const ffEl = $("#b-fire-and-forget");
|
||||
if (ffEl) ffEl.checked = !!lr?.fireAndForget;
|
||||
syncLatchUi();
|
||||
}
|
||||
|
||||
function readLatchResetFromForm() {
|
||||
if (!$("#b-latch-enabled")?.checked) {
|
||||
return { enabled: false };
|
||||
}
|
||||
return {
|
||||
enabled: true,
|
||||
resetUrl: $("#b-reset-url").value.trim(),
|
||||
successMatch: ($("#b-success-match").value.trim() || "OK"),
|
||||
fireAndForget: !!$("#b-fire-and-forget")?.checked,
|
||||
};
|
||||
}
|
||||
|
||||
function syncLatchUi() {
|
||||
const latchOn = $("#b-latch-enabled")?.checked;
|
||||
const fields = $("#b-latch-fields");
|
||||
const rcBlock = $("#b-response-check-block");
|
||||
const ffHint = document.querySelector(".latch-fire-hint");
|
||||
if (fields) fields.classList.toggle("show", !!latchOn);
|
||||
if (rcBlock) rcBlock.style.display = latchOn ? "none" : "";
|
||||
if (ffHint) {
|
||||
ffHint.style.display = latchOn && $("#b-fire-and-forget")?.checked ? "" : "none";
|
||||
}
|
||||
}
|
||||
|
||||
$("#b-latch-enabled")?.addEventListener("change", syncLatchUi);
|
||||
$("#b-fire-and-forget")?.addEventListener("change", syncLatchUi);
|
||||
|
||||
$("#b-rc-enabled")?.addEventListener("change", syncResponseCheckUi);
|
||||
$("#b-rc-add-rule")?.addEventListener("click", () => {
|
||||
$("#b-rc-rules")?.appendChild(createRuleRow());
|
||||
@@ -284,14 +323,17 @@ function openDialogFor(btn) {
|
||||
$("#b-icon").value = btn?.iconPath || "";
|
||||
$("#b-type").value = btn?.action?.type || "http_get";
|
||||
$("#b-url").value = btn?.action?.url || "";
|
||||
$("#b-action-timeout").value = btn?.action?.timeoutMs ?? 7000;
|
||||
$("#b-success").value = btn?.feedback?.successText || "";
|
||||
$("#b-error").value = btn?.feedback?.errorText || "Ошибка";
|
||||
$("#b-pending").value = btn?.feedback?.pendingText ?? "...";
|
||||
$("#b-color").value = btn?.color || "#7b007b";
|
||||
$("#b-trigger-mode").value = btn?.trigger?.mode || "hold";
|
||||
$("#b-hold").value = btn?.trigger?.holdMs || 800;
|
||||
fillLatchResetForm(btn?.latchReset);
|
||||
fillResponseCheckForm(btn?.action?.responseCheck);
|
||||
syncHoldRow();
|
||||
syncLatchUi();
|
||||
dlg.showModal();
|
||||
}
|
||||
|
||||
@@ -322,18 +364,21 @@ form?.addEventListener("submit", async (e) => {
|
||||
if (e.submitter && e.submitter.value === "cancel") return;
|
||||
e.preventDefault();
|
||||
const id = $("#b-id").value;
|
||||
const latchReset = readLatchResetFromForm();
|
||||
const payload = {
|
||||
label: $("#b-label").value,
|
||||
iconPath: $("#b-icon").value,
|
||||
actionType: $("#b-type").value,
|
||||
url: $("#b-url").value,
|
||||
timeoutMs: parseInt($("#b-action-timeout").value, 10) || 7000,
|
||||
successText: $("#b-success").value,
|
||||
errorText: $("#b-error").value,
|
||||
pendingText: $("#b-pending").value || "...",
|
||||
color: $("#b-color").value,
|
||||
triggerMode: $("#b-trigger-mode").value,
|
||||
holdMs: parseInt($("#b-hold").value, 10),
|
||||
responseCheck: readResponseCheckFromForm(),
|
||||
latchReset,
|
||||
responseCheck: latchReset.enabled ? { enabled: false } : readResponseCheckFromForm(),
|
||||
};
|
||||
if (id) await api("PUT", `/api/buttons/${encodeURIComponent(id)}`, payload);
|
||||
else await api("POST", "/api/buttons", payload);
|
||||
|
||||
Reference in New Issue
Block a user