Refactor to reduce lines
This commit is contained in:
@@ -819,135 +819,104 @@
|
||||
(function() {
|
||||
const personId = "{{ person.id }}";
|
||||
const canSend = "{{ send_state.can_send|yesno:'1,0' }}" === "1";
|
||||
function resizeEditableTextareas(root) {
|
||||
const TAB_NAMES = ["plan_board", "corrections", "engage", "fundamentals", "auto", "ask_ai"];
|
||||
const defineGlobal = function(name, handler) {
|
||||
if (typeof window[name] !== "function") {
|
||||
window[name] = handler;
|
||||
}
|
||||
};
|
||||
const resizeEditableTextareas = function(root) {
|
||||
if (!root) return;
|
||||
root.querySelectorAll('textarea[data-editable="1"]').forEach(function(area) {
|
||||
area.style.height = "auto";
|
||||
area.style.height = Math.max(area.scrollHeight, 72) + "px";
|
||||
});
|
||||
}
|
||||
|
||||
window.giaEngageSyncSendOverride = function(pid) {
|
||||
if (pid !== personId) return;
|
||||
const forceInput = document.getElementById("engage-force-send-" + pid);
|
||||
const sendBtn = document.getElementById("engage-send-btn-" + pid);
|
||||
const force =
|
||||
!!(window.giaWorkspaceState
|
||||
&& window.giaWorkspaceState[pid]
|
||||
&& window.giaWorkspaceState[pid].forceSend);
|
||||
if (forceInput) {
|
||||
forceInput.value = force ? "1" : "0";
|
||||
}
|
||||
if (sendBtn) {
|
||||
sendBtn.disabled = !canSend && !force;
|
||||
}
|
||||
};
|
||||
|
||||
function setActiveTabHiddenFields(tabName) {
|
||||
const syncActiveTab = function(tabName) {
|
||||
const root = document.getElementById("mitigation-shell-" + personId);
|
||||
if (!root) return;
|
||||
root.querySelectorAll('input[name="active_tab"]').forEach(function(input) {
|
||||
input.value = tabName;
|
||||
});
|
||||
resizeEditableTextareas(root);
|
||||
}
|
||||
};
|
||||
|
||||
window.giaEngageSyncSendOverride = function(pid) {
|
||||
if (pid !== personId) return;
|
||||
const forceInput = document.getElementById("engage-force-send-" + pid);
|
||||
const sendBtn = document.getElementById("engage-send-btn-" + pid);
|
||||
const force = !!(window.giaWorkspaceState && window.giaWorkspaceState[pid] && window.giaWorkspaceState[pid].forceSend);
|
||||
if (forceInput) forceInput.value = force ? "1" : "0";
|
||||
if (sendBtn) {
|
||||
sendBtn.disabled = !canSend && !force;
|
||||
}
|
||||
};
|
||||
|
||||
window.giaMitigationShowTab = function(pid, tabName) {
|
||||
if (pid !== personId) return;
|
||||
["plan_board", "corrections", "engage", "fundamentals", "auto", "ask_ai"].forEach(function(name) {
|
||||
TAB_NAMES.forEach(function(name) {
|
||||
const pane = document.getElementById("mitigation-tab-" + personId + "-" + name);
|
||||
const tab = document.getElementById("mitigation-tab-btn-" + personId + "-" + name);
|
||||
if (!pane) return;
|
||||
const active = name === tabName;
|
||||
pane.style.display = active ? "block" : "none";
|
||||
if (tab) {
|
||||
tab.classList.toggle("is-active", active);
|
||||
}
|
||||
if (tab) tab.classList.toggle("is-active", active);
|
||||
});
|
||||
setActiveTabHiddenFields(tabName);
|
||||
syncActiveTab(tabName);
|
||||
};
|
||||
|
||||
window.giaMitigationToggleEdit = function(button) {
|
||||
const form = button.closest("form");
|
||||
if (!form) return;
|
||||
const card = form.closest(".mitigation-artifact-card");
|
||||
const editing = button.dataset.editState === "edit";
|
||||
const fields = form.querySelectorAll('[data-editable="1"]');
|
||||
const toggles = form.querySelectorAll('[data-editable-toggle="1"]');
|
||||
if (!editing) {
|
||||
fields.forEach(function(field) {
|
||||
field.removeAttribute("readonly");
|
||||
});
|
||||
toggles.forEach(function(field) {
|
||||
field.removeAttribute("disabled");
|
||||
});
|
||||
if (card) {
|
||||
card.classList.add("is-editing");
|
||||
defineGlobal("giaMitigationToggleEdit", function(button) {
|
||||
const form = button && button.closest ? button.closest("form") : null;
|
||||
if (!form) return;
|
||||
const editing = button.dataset.editState === "edit";
|
||||
if (!editing) {
|
||||
form.querySelectorAll('[data-editable="1"]').forEach(function(field) { field.removeAttribute("readonly"); });
|
||||
form.querySelectorAll('[data-editable-toggle="1"]').forEach(function(field) { field.removeAttribute("disabled"); });
|
||||
const card = form.closest(".mitigation-artifact-card");
|
||||
if (card) card.classList.add("is-editing");
|
||||
button.dataset.editState = "edit";
|
||||
button.classList.remove("is-light");
|
||||
button.title = "Save";
|
||||
button.innerHTML = '<span class="icon is-small"><i class="fa-solid fa-check"></i></span>';
|
||||
resizeEditableTextareas(form);
|
||||
return;
|
||||
}
|
||||
button.dataset.editState = "edit";
|
||||
button.classList.remove("is-light");
|
||||
button.title = "Save";
|
||||
button.innerHTML = '<span class="icon is-small"><i class="fa-solid fa-check"></i></span>';
|
||||
resizeEditableTextareas(form);
|
||||
} else {
|
||||
form.requestSubmit();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
window.giaEngageSetAction = function(pid, action) {
|
||||
if (pid !== personId) return;
|
||||
const actionInput = document.getElementById("engage-action-input-" + pid);
|
||||
if (actionInput) {
|
||||
actionInput.value = action;
|
||||
}
|
||||
if (action === "send") {
|
||||
window.giaEngageSyncSendOverride(pid);
|
||||
}
|
||||
};
|
||||
defineGlobal("giaEngageSetAction", function(pid, action) {
|
||||
const actionInput = document.getElementById("engage-action-input-" + pid);
|
||||
if (actionInput) actionInput.value = action;
|
||||
if (action === "send") window.giaEngageSyncSendOverride(pid);
|
||||
});
|
||||
|
||||
window.giaEngageAutoPreview = function(pid) {
|
||||
if (pid !== personId) return;
|
||||
const form = document.getElementById("engage-form-" + pid);
|
||||
if (!form) return;
|
||||
window.giaEngageSetAction(pid, "preview");
|
||||
form.requestSubmit();
|
||||
};
|
||||
defineGlobal("giaEngageAutoPreview", function(pid) {
|
||||
const form = document.getElementById("engage-form-" + pid);
|
||||
if (!form) return;
|
||||
window.giaEngageSetAction(pid, "preview");
|
||||
form.requestSubmit();
|
||||
});
|
||||
|
||||
window.giaEngageSetTarget = function(pid, targetId) {
|
||||
if (pid !== personId) return;
|
||||
const normalized = String(targetId || "").trim();
|
||||
const input = document.getElementById("engage-target-input-" + pid);
|
||||
if (input) {
|
||||
input.value = normalized;
|
||||
}
|
||||
if (input) input.value = normalized;
|
||||
const parentSelect = document.getElementById("ai-target-select-" + pid);
|
||||
if (parentSelect && normalized) {
|
||||
parentSelect.value = normalized;
|
||||
}
|
||||
if (parentSelect && normalized) parentSelect.value = normalized;
|
||||
};
|
||||
|
||||
window.giaEngageSelect = function(pid, kind, value, node) {
|
||||
if (pid !== personId) return;
|
||||
let inputId = "";
|
||||
if (kind === "share") {
|
||||
inputId = "engage-share-input-" + pid;
|
||||
} else if (kind === "framing") {
|
||||
inputId = "engage-framing-input-" + pid;
|
||||
}
|
||||
const input = inputId ? document.getElementById(inputId) : null;
|
||||
if (input) {
|
||||
input.value = value;
|
||||
}
|
||||
const li = node && node.closest ? node.closest("li") : null;
|
||||
if (!li) return;
|
||||
const ul = li.parentElement;
|
||||
if (!ul) return;
|
||||
Array.from(ul.children).forEach(function(child) {
|
||||
child.classList.remove("is-active");
|
||||
});
|
||||
li.classList.add("is-active");
|
||||
window.giaEngageAutoPreview(pid);
|
||||
};
|
||||
defineGlobal("giaEngageSelect", function(pid, kind, value, node) {
|
||||
const inputId = kind === "share" ? ("engage-share-input-" + pid) : (kind === "framing" ? ("engage-framing-input-" + pid) : "");
|
||||
const input = inputId ? document.getElementById(inputId) : null;
|
||||
if (input) input.value = value;
|
||||
const li = node && node.closest ? node.closest("li") : null;
|
||||
if (!li || !li.parentElement) return;
|
||||
Array.from(li.parentElement.children).forEach(function(child) { child.classList.remove("is-active"); });
|
||||
li.classList.add("is-active");
|
||||
window.giaEngageAutoPreview(pid);
|
||||
});
|
||||
|
||||
window.giaMitigationShowTab(personId, "{{ active_tab|default:'plan_board' }}");
|
||||
resizeEditableTextareas(document.getElementById("mitigation-shell-" + personId));
|
||||
|
||||
Reference in New Issue
Block a user