feat(chat): custom branded modal for topic renaming (replaces browser prompt)
This commit is contained in:
@@ -31,7 +31,8 @@ async function loadModals() {
|
||||
'admin_modal.html',
|
||||
'snapshot_inspector_modal.html',
|
||||
'presence_modal.html',
|
||||
'confirm_modal.html'
|
||||
'confirm_modal.html',
|
||||
'rename_topic_modal.html'
|
||||
];
|
||||
|
||||
const container = document.getElementById('modals-container');
|
||||
|
||||
@@ -119,12 +119,20 @@ window.TopicsManager = (function() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button"
|
||||
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
|
||||
class="opacity-0 group-hover:opacity-100 p-1 text-slate-400 hover:text-rose-600 rounded transition shrink-0"
|
||||
title="Удалить чат">
|
||||
<i class="fa-solid fa-trash-can text-xs"></i>
|
||||
</button>
|
||||
<div class="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition shrink-0 mt-0.5">
|
||||
<button type="button"
|
||||
onclick="event.stopPropagation(); window.TopicsManager.openRenameModal('${session.id}', '${escapeHtml(title)}')"
|
||||
class="p-1 text-slate-400 hover:text-indigo-600 rounded transition"
|
||||
title="Переименовать тему">
|
||||
<i class="fa-solid fa-pencil text-xs"></i>
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
|
||||
class="p-1 text-slate-400 hover:text-rose-600 rounded transition"
|
||||
title="Удалить чат">
|
||||
<i class="fa-solid fa-trash-can text-xs"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join("");
|
||||
@@ -275,12 +283,65 @@ window.TopicsManager = (function() {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function openRenameModal(sessionId, currentTitle) {
|
||||
const modal = document.getElementById("rename-topic-modal");
|
||||
const idInput = document.getElementById("rename-topic-session-id");
|
||||
const titleInput = document.getElementById("rename-topic-input");
|
||||
|
||||
if (idInput) idInput.value = sessionId;
|
||||
if (titleInput) {
|
||||
titleInput.value = currentTitle;
|
||||
setTimeout(() => {
|
||||
titleInput.focus();
|
||||
titleInput.select();
|
||||
}, 50);
|
||||
}
|
||||
if (modal) modal.classList.remove("hidden");
|
||||
}
|
||||
|
||||
function closeRenameModal() {
|
||||
const modal = document.getElementById("rename-topic-modal");
|
||||
if (modal) modal.classList.add("hidden");
|
||||
}
|
||||
|
||||
async function submitRenameModal(event) {
|
||||
if (event) event.preventDefault();
|
||||
const sessionId = document.getElementById("rename-topic-session-id")?.value;
|
||||
const newTitle = document.getElementById("rename-topic-input")?.value.trim();
|
||||
|
||||
if (!sessionId || !newTitle) return;
|
||||
closeRenameModal();
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/v1/chat/sessions/' + encodeURIComponent(sessionId), {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
...AuthManager.getAuthHeaders(),
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ title: newTitle })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
await loadTopics();
|
||||
} else {
|
||||
console.error("Ошибка сохранения названия темы");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Ошибка сети при переименовании темы:", e);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
init,
|
||||
loadTopics,
|
||||
getActiveSessionId,
|
||||
switchTopic,
|
||||
createNewTopic,
|
||||
askDeleteTopic
|
||||
askDeleteTopic,
|
||||
openRenameModal,
|
||||
closeRenameModal,
|
||||
submitRenameModal
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user