|
|
|
|
|
|
|
|
|
|
|
|
|
function openAddKeyModal() {
|
|
if (!window.apiKeyManagerInstance) return;
|
|
window.apiKeyManagerInstance.showAddModal = true;
|
|
|
|
|
|
setTimeout(() => {
|
|
document.getElementById('platform')?.focus();
|
|
}, 100);
|
|
}
|
|
|
|
|
|
function openEditKeyModal(id, name, key, platform) {
|
|
if (!window.apiKeyManagerInstance) return;
|
|
window.apiKeyManagerInstance.editApiKey(id, name, key, platform);
|
|
}
|
|
|
|
|
|
function openDeleteConfirmModal(id, name) {
|
|
if (!window.apiKeyManagerInstance) return;
|
|
window.apiKeyManagerInstance.deleteApiKey(id, name);
|
|
}
|
|
|
|
|
|
function closeAllModals() {
|
|
if (!window.apiKeyManagerInstance) return;
|
|
|
|
window.apiKeyManagerInstance.showAddModal = false;
|
|
window.apiKeyManagerInstance.showEditModal = false;
|
|
window.apiKeyManagerInstance.showDeleteConfirm = false;
|
|
}
|
|
|
|
|
|
function setupModalKeyboardShortcuts() {
|
|
document.addEventListener('keydown', (e) => {
|
|
|
|
if (e.key === 'Escape') {
|
|
closeAllModals();
|
|
}
|
|
|
|
|
|
if (e.altKey && e.key === 'n') {
|
|
openAddKeyModal();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function initModals() {
|
|
|
|
window.addEventListener('alpine:initialized', () => {
|
|
const apiKeyManagerEl = document.querySelector('[x-data="apiKeyManager()"]');
|
|
if (apiKeyManagerEl) {
|
|
window.apiKeyManagerInstance = apiKeyManagerEl.__x.getUnobservedData();
|
|
}
|
|
});
|
|
|
|
|
|
setupModalKeyboardShortcuts();
|
|
|
|
|
|
window.addEventListener('open-add-modal', openAddKeyModal);
|
|
}
|
|
|
|
|
|
window.apiKeyModals = {
|
|
openAddKeyModal,
|
|
openEditKeyModal,
|
|
openDeleteConfirmModal,
|
|
closeAllModals,
|
|
initModals
|
|
};
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initModals();
|
|
});
|
|
|