second
This commit is contained in:
545
js/app.js
Normal file
545
js/app.js
Normal file
@@ -0,0 +1,545 @@
|
||||
// VaultSentinel - Account Management Application
|
||||
// Main JavaScript functionality
|
||||
|
||||
class AccountManager {
|
||||
constructor() {
|
||||
// Check if user is logged in
|
||||
const currentUser = this.loadFromStorage('currentUser');
|
||||
if (!currentUser) {
|
||||
window.location.href = '../pages/login.html';
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentUser = currentUser;
|
||||
this.accounts = this.loadFromStorage('accounts') || [];
|
||||
this.applications = this.loadFromStorage('applications') || [
|
||||
{ id: 1, name: 'AWS', type: 'Cloud', status: 'online', icon: 'cloud' },
|
||||
{ id: 2, name: 'GitHub', type: 'VCS', status: 'online', icon: 'code' },
|
||||
{ id: 3, name: 'Google Workspace', type: 'Collaboration', status: 'online', icon: 'mail' },
|
||||
{ id: 4, name: 'Nginx Proxy', type: 'Infra', status: 'offline', icon: 'dns' },
|
||||
];
|
||||
this.currentPage = 'dashboard';
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.setupEventListeners();
|
||||
// Render dashboard content
|
||||
const mainContent = document.getElementById('mainContent');
|
||||
if (mainContent) {
|
||||
mainContent.innerHTML = this.renderDashboard();
|
||||
}
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Account modal
|
||||
const addAccountBtn = document.getElementById('addAccountBtn');
|
||||
if (addAccountBtn) {
|
||||
addAccountBtn.addEventListener('click', () => this.openAccountModal());
|
||||
}
|
||||
|
||||
// Application modal
|
||||
const addAppBtn = document.getElementById('addAppBtn');
|
||||
if (addAppBtn) {
|
||||
addAppBtn.addEventListener('click', () => this.openAppModal());
|
||||
}
|
||||
|
||||
// Modal close buttons
|
||||
document.querySelectorAll('[data-close-modal]').forEach(btn => {
|
||||
btn.addEventListener('click', () => this.closeModals());
|
||||
});
|
||||
|
||||
// Form submissions
|
||||
const accountForm = document.getElementById('accountForm');
|
||||
if (accountForm) {
|
||||
accountForm.addEventListener('submit', (e) => this.handleAccountSubmit(e));
|
||||
}
|
||||
|
||||
const appForm = document.getElementById('appForm');
|
||||
if (appForm) {
|
||||
appForm.addEventListener('submit', (e) => this.handleAppSubmit(e));
|
||||
}
|
||||
|
||||
// Logout button
|
||||
const logoutBtn = document.getElementById('logoutBtn');
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener('click', () => this.handleLogout());
|
||||
}
|
||||
|
||||
// Update account display
|
||||
this.updateAccountDisplay();
|
||||
|
||||
// Account table row clicks
|
||||
this.setupAccountRowListeners();
|
||||
}
|
||||
|
||||
updateAccountDisplay() {
|
||||
// Use the logged-in user from constructor
|
||||
const usernameEl = document.getElementById('accountUsername');
|
||||
const roleEl = document.getElementById('accountRole');
|
||||
|
||||
if (usernameEl) usernameEl.textContent = this.currentUser?.username || 'User';
|
||||
if (roleEl) roleEl.textContent = this.currentUser?.role || 'Administrator';
|
||||
}
|
||||
|
||||
handleLogout() {
|
||||
if (confirm('Are you sure you want to logout?')) {
|
||||
this.saveToStorage('currentUser', null);
|
||||
localStorage.clear();
|
||||
window.location.href = '../pages/login.html';
|
||||
}
|
||||
}
|
||||
|
||||
renderDashboard() {
|
||||
return `
|
||||
<div class="flex-1 flex flex-col p-6 space-y-6 min-h-0 overflow-auto">
|
||||
<!-- Title and Stats -->
|
||||
<div class="flex items-end justify-between shrink-0">
|
||||
<div>
|
||||
<h1 class="text-2xl font-extrabold text-on-surface tracking-tight leading-none">System Overview</h1>
|
||||
<p class="text-xs text-on-surface-variant font-medium mt-1">Account & Service Management</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<a href="./accounts.html" class="py-1.5 px-3 bg-primary text-on-primary rounded-lg text-xs font-bold flex items-center gap-1.5 shadow-sm active:scale-95 duration-100">
|
||||
<span class="material-symbols-outlined text-sm">add</span>
|
||||
Add Account
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metric Grid -->
|
||||
<div class="grid grid-cols-4 gap-4 shrink-0">
|
||||
<div class="bg-surface-container-lowest p-4 rounded-xl border border-outline-variant/15 flex flex-col">
|
||||
<span class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider mb-2">Applications</span>
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-2xl font-black text-on-surface">${this.applications.length}</span>
|
||||
<span class="text-[10px] font-bold text-on-surface-variant">${this.applications.filter(a => a.status === 'online').length} Active</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-surface-container-lowest p-4 rounded-xl border border-outline-variant/15 flex flex-col">
|
||||
<span class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider mb-2">Total Accounts</span>
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-2xl font-black text-on-surface">${this.accounts.length}</span>
|
||||
<span class="text-[10px] font-bold text-on-surface-variant/40">Managed</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-surface-container-lowest p-4 rounded-xl border border-outline-variant/15 flex flex-col">
|
||||
<span class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider mb-2">Last Updated</span>
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-sm font-black text-on-surface">${new Date().toLocaleDateString()}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-primary-container/10 p-4 rounded-xl border border-primary/20 flex flex-col">
|
||||
<span class="text-[10px] font-bold text-primary uppercase tracking-wider mb-2">Status</span>
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-lg font-black text-primary">Operational</span>
|
||||
<span class="material-symbols-outlined text-primary text-sm">check_circle</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recent Activity -->
|
||||
<div class="bg-surface-container-lowest rounded-xl p-5 border border-outline-variant/15 flex flex-col flex-1 min-h-0">
|
||||
<div class="flex items-center justify-between mb-4 shrink-0">
|
||||
<h3 class="text-sm font-bold text-on-surface flex items-center gap-2">
|
||||
<span class="material-symbols-outlined text-primary text-base">history</span>
|
||||
Recent Accounts
|
||||
</h3>
|
||||
</div>
|
||||
${this.accounts.length > 0 ? `
|
||||
<div class="flex-1 overflow-y-auto space-y-2">
|
||||
${this.accounts.slice(-5).reverse().map(acc => `
|
||||
<div class="flex gap-3 p-3 bg-surface-container-low/50 rounded-lg border-l-2 border-primary/50">
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="text-[11px] font-bold text-on-surface truncate">${acc.username}</p>
|
||||
<p class="text-[9px] text-on-surface-variant">${acc.service} • ${acc.owner}</p>
|
||||
</div>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
` : `
|
||||
<div class="flex-1 flex items-center justify-center text-center">
|
||||
<p class="text-sm text-on-surface-variant">No accounts yet. <a href="./accounts.html" class="text-primary font-bold">Create one</a></p>
|
||||
</div>
|
||||
`}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
getAccountsContent() {
|
||||
return `
|
||||
<div class="p-4 md:p-6 flex flex-col h-full overflow-hidden">
|
||||
<!-- Page Header -->
|
||||
<div class="flex items-center justify-between mb-4 shrink-0">
|
||||
<div>
|
||||
<h1 class="text-xl font-extrabold text-on-surface tracking-tight">Accounts Management</h1>
|
||||
<p class="text-[10px] text-on-surface-variant uppercase font-semibold tracking-widest mt-0.5">Administrative Access Control</p>
|
||||
</div>
|
||||
<button id="addAccountBtn" class="bg-primary hover:bg-primary-dim text-on-primary px-3 py-1.5 rounded-lg text-xs font-bold shadow-sm flex items-center gap-1.5 transition-all active:scale-95">
|
||||
<span class="material-symbols-outlined text-base">person_add</span>
|
||||
Add Account
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="flex items-center gap-3 mb-4">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="text-[10px] font-bold uppercase text-on-surface-variant">Service</span>
|
||||
<select id="serviceFilter" class="bg-surface-container-low border-slate-200 rounded-md text-[11px] py-1 px-2 pr-6 focus:ring-1 focus:ring-primary shadow-sm">
|
||||
<option value="">All Services</option>
|
||||
${this.applications.map(app => `<option value="${app.name}">${app.name}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex-1"></div>
|
||||
</div>
|
||||
|
||||
<!-- Accounts Table -->
|
||||
<div class="flex-1 bg-white rounded-xl border border-slate-200 shadow-sm flex flex-col overflow-hidden min-h-0">
|
||||
${this.accounts.length > 0 ? `
|
||||
<div class="overflow-y-auto overflow-x-auto flex-1">
|
||||
<table class="w-full text-left border-collapse w-full">
|
||||
<thead class="sticky top-0 z-10">
|
||||
<tr class="bg-slate-50 border-b border-slate-200">
|
||||
<th class="px-4 py-2.5 text-[10px] font-bold uppercase tracking-wider text-slate-500">Owner</th>
|
||||
<th class="px-4 py-2.5 text-[10px] font-bold uppercase tracking-wider text-slate-500">Username</th>
|
||||
<th class="px-4 py-2.5 text-[10px] font-bold uppercase tracking-wider text-slate-500">Service</th>
|
||||
<th class="px-4 py-2.5 text-[10px] font-bold uppercase tracking-wider text-slate-500 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
${this.accounts.map((acc, idx) => `
|
||||
<tr class="hover:bg-slate-50/80 transition-colors group account-row" data-account-id="${idx}">
|
||||
<td class="px-4 py-3 text-sm font-medium text-slate-900">${acc.owner}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${acc.username}</td>
|
||||
<td class="px-4 py-3 text-sm">
|
||||
<span class="px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs font-semibold">${acc.service}</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button class="p-1.5 text-slate-400 hover:text-primary transition-colors edit-account" data-account-id="${idx}">
|
||||
<span class="material-symbols-outlined text-lg">edit</span>
|
||||
</button>
|
||||
<button class="p-1.5 text-slate-400 hover:text-error transition-colors delete-account" data-account-id="${idx}">
|
||||
<span class="material-symbols-outlined text-lg">delete</span>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
` : `
|
||||
<div class="flex-1 flex items-center justify-center text-center">
|
||||
<div>
|
||||
<p class="text-sm text-on-surface-variant mb-4">No accounts yet. Create one to get started.</p>
|
||||
<button id="addAccountBtn" class="bg-primary hover:bg-primary-dim text-on-primary px-4 py-2 rounded-lg text-sm font-bold">
|
||||
<span class="material-symbols-outlined text-base inline mr-2">person_add</span>
|
||||
Add First Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Account Modal -->
|
||||
<div class="modal-backdrop fixed inset-0 z-[100] flex items-center justify-center bg-black/40 backdrop-blur-sm hidden" id="accountModal">
|
||||
<div class="modal-content w-full max-w-lg bg-white rounded-xl shadow-2xl border border-slate-200 overflow-hidden m-4">
|
||||
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50">
|
||||
<h3 class="text-base font-extrabold text-slate-900">Add New Account</h3>
|
||||
<button class="p-1.5 rounded-lg hover:bg-slate-200 text-slate-400 transition-colors" data-close-modal>
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
<form id="accountForm" class="p-6 space-y-4">
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Service</label>
|
||||
<select id="accountService" class="w-full border-slate-200 rounded-lg text-sm py-2.5 px-3" required>
|
||||
<option value="">Select a service</option>
|
||||
${this.applications.map(app => `<option value="${app.name}">${app.name}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Owner Name</label>
|
||||
<input type="text" id="accountOwner" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3" required placeholder="John Doe">
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Username</label>
|
||||
<input type="text" id="accountUsername" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3" required placeholder="username">
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Password</label>
|
||||
<input type="password" id="accountPassword" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3" required placeholder="••••••••">
|
||||
</div>
|
||||
<div class="flex gap-3 pt-4">
|
||||
<button type="button" class="flex-1 px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg" data-close-modal>Cancel</button>
|
||||
<button type="submit" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary rounded-lg text-xs font-bold">Save Account</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
getApplicationsContent() {
|
||||
return `
|
||||
<div class="flex flex-col p-6 overflow-hidden h-full">
|
||||
<!-- Header Section -->
|
||||
<div class="flex items-center justify-between gap-6 mb-6 shrink-0">
|
||||
<div>
|
||||
<h1 class="text-2xl font-extrabold text-on-surface tracking-tight">Applications</h1>
|
||||
<p class="text-sm text-on-surface-variant">Manage and monitor active infrastructure services.</p>
|
||||
</div>
|
||||
<button id="addAppBtn" class="bg-primary hover:bg-primary-dim text-on-primary px-4 py-2 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95 shadow-sm">
|
||||
<span class="material-symbols-outlined">add</span>
|
||||
Add New
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Dashboard Stats -->
|
||||
<div class="grid grid-cols-3 gap-4 mb-6 shrink-0">
|
||||
<div class="bg-surface-container-lowest px-4 py-3 rounded-xl shadow-sm border border-outline-variant/5 flex items-center gap-4">
|
||||
<div class="w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center text-primary">
|
||||
<span class="material-symbols-outlined text-xl">lan</span>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider">Active</p>
|
||||
<p class="text-lg font-black text-on-surface">${this.applications.filter(a => a.status === 'online').length}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-surface-container-lowest px-4 py-3 rounded-xl shadow-sm border border-outline-variant/5 flex items-center gap-4">
|
||||
<div class="w-10 h-10 rounded-lg bg-tertiary/10 flex items-center justify-center text-tertiary">
|
||||
<span class="material-symbols-outlined text-xl">bolt</span>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider">Total</p>
|
||||
<p class="text-lg font-black text-on-surface">${this.applications.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-surface-container-lowest px-4 py-3 rounded-xl shadow-sm border border-outline-variant/5 flex items-center gap-4">
|
||||
<div class="w-10 h-10 rounded-lg bg-secondary/10 flex items-center justify-center text-secondary">
|
||||
<span class="material-symbols-outlined text-xl">database</span>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-[10px] font-bold text-on-surface-variant uppercase tracking-wider">Health</p>
|
||||
<p class="text-lg font-black text-on-surface">99.9%</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Applications List -->
|
||||
<div class="bg-surface-container-lowest rounded-xl shadow-sm border border-outline-variant/10 overflow-hidden flex flex-col flex-1 min-h-0">
|
||||
<div class="overflow-y-auto flex-1">
|
||||
<table class="w-full text-left border-collapse">
|
||||
<thead class="sticky top-0 bg-surface-container-lowest z-10">
|
||||
<tr class="bg-surface-container-low/30 border-b border-outline-variant/10">
|
||||
<th class="px-6 py-2.5 text-[10px] font-bold text-on-surface-variant uppercase tracking-widest">Name</th>
|
||||
<th class="px-6 py-2.5 text-[10px] font-bold text-on-surface-variant uppercase tracking-widest">Type</th>
|
||||
<th class="px-6 py-2.5 text-[10px] font-bold text-on-surface-variant uppercase tracking-widest">Status</th>
|
||||
<th class="px-6 py-2.5 text-[10px] font-bold text-on-surface-variant uppercase tracking-widest text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-outline-variant/5">
|
||||
${this.applications.map((app, idx) => `
|
||||
<tr class="hover:bg-surface-container-low/30 transition-colors group">
|
||||
<td class="px-6 py-3">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-8 h-8 rounded bg-surface-container-highest flex items-center justify-center text-primary">
|
||||
<span class="material-symbols-outlined text-sm">${app.icon}</span>
|
||||
</div>
|
||||
<span class="font-bold text-sm text-on-surface">${app.name}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-3">
|
||||
<span class="px-2 py-0.5 rounded-full text-[9px] font-black uppercase bg-surface-container-highest text-on-surface-variant">${app.type}</span>
|
||||
</td>
|
||||
<td class="px-6 py-3">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<div class="w-1.5 h-1.5 rounded-full ${app.status === 'online' ? 'bg-primary' : 'bg-error'} ring-2 ${app.status === 'online' ? 'ring-primary/20' : 'ring-error/20'}"></div>
|
||||
<span class="text-xs font-medium ${app.status === 'online' ? 'text-on-primary-fixed-variant' : 'text-error'}">${app.status === 'online' ? 'Online' : 'Offline'}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-3 text-right">
|
||||
<div class="flex items-center justify-end gap-1">
|
||||
<button class="p-1.5 text-on-surface-variant hover:text-primary transition-colors edit-app" data-app-id="${idx}">
|
||||
<span class="material-symbols-outlined text-lg">edit</span>
|
||||
</button>
|
||||
<button class="p-1.5 text-on-surface-variant hover:text-error transition-colors delete-app" data-app-id="${idx}">
|
||||
<span class="material-symbols-outlined text-lg">delete</span>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- App Modal -->
|
||||
<div class="modal-backdrop fixed inset-0 z-[100] flex items-center justify-center bg-black/40 backdrop-blur-sm hidden" id="appModal">
|
||||
<div class="modal-content w-full max-w-lg bg-white rounded-xl shadow-2xl border border-slate-200 overflow-hidden m-4">
|
||||
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50">
|
||||
<h3 class="text-base font-extrabold text-slate-900">Add New Application</h3>
|
||||
<button class="p-1.5 rounded-lg hover:bg-slate-200 text-slate-400 transition-colors" data-close-modal>
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
<form id="appForm" class="p-6 space-y-4">
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Application Name</label>
|
||||
<input type="text" id="appName" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3" required placeholder="AWS Services">
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Type</label>
|
||||
<input type="text" id="appType" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3" required placeholder="Cloud">
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-[10px] font-bold uppercase text-slate-500 tracking-widest block mb-1">Status</label>
|
||||
<select id="appStatus" class="w-full border border-slate-200 rounded-lg text-sm py-2.5 px-3">
|
||||
<option value="online">Online</option>
|
||||
<option value="offline">Offline</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex gap-3 pt-4">
|
||||
<button type="button" class="flex-1 px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg" data-close-modal>Cancel</button>
|
||||
<button type="submit" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary rounded-lg text-xs font-bold">Save Application</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
setupAccountRowListeners() {
|
||||
document.querySelectorAll('.delete-account').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
const accountId = btn.dataset.accountId;
|
||||
if (confirm('Delete this account?')) {
|
||||
this.accounts.splice(accountId, 1);
|
||||
this.saveToStorage('accounts', this.accounts);
|
||||
location.href = './accounts.html';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.edit-account').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
const accountId = btn.dataset.accountId;
|
||||
const account = this.accounts[accountId];
|
||||
// Populate form with existing data
|
||||
document.getElementById('accountUsername').value = account.username;
|
||||
document.getElementById('accountPassword').value = account.password;
|
||||
document.getElementById('accountOwner').value = account.owner;
|
||||
document.getElementById('accountService').value = account.service;
|
||||
this.editingAccountId = accountId;
|
||||
this.openAccountModal();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.delete-app').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
const appId = btn.dataset.appId;
|
||||
if (confirm('Delete this application?')) {
|
||||
this.applications.splice(appId, 1);
|
||||
this.saveToStorage('applications', this.applications);
|
||||
location.href = './applications.html';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.edit-app').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
const appId = btn.dataset.appId;
|
||||
const app = this.applications[appId];
|
||||
document.getElementById('appName').value = app.name;
|
||||
document.getElementById('appType').value = app.type;
|
||||
document.getElementById('appStatus').value = app.status;
|
||||
this.editingAppId = appId;
|
||||
this.openAppModal();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleAccountSubmit(e) {
|
||||
e.preventDefault();
|
||||
const newAccount = {
|
||||
service: document.getElementById('accountService').value,
|
||||
owner: document.getElementById('accountOwner').value,
|
||||
username: document.getElementById('accountUsername').value,
|
||||
password: document.getElementById('accountPassword').value,
|
||||
dateCreated: new Date().toLocaleDateString()
|
||||
};
|
||||
|
||||
if (this.editingAccountId !== undefined) {
|
||||
this.accounts[this.editingAccountId] = newAccount;
|
||||
this.editingAccountId = undefined;
|
||||
} else {
|
||||
this.accounts.push(newAccount);
|
||||
}
|
||||
|
||||
this.saveToStorage('accounts', this.accounts);
|
||||
this.closeModals();
|
||||
location.href = './accounts.html';
|
||||
}
|
||||
|
||||
handleAppSubmit(e) {
|
||||
e.preventDefault();
|
||||
const newApp = {
|
||||
name: document.getElementById('appName').value,
|
||||
type: document.getElementById('appType').value,
|
||||
status: document.getElementById('appStatus').value,
|
||||
icon: 'cloud'
|
||||
};
|
||||
|
||||
if (this.editingAppId !== undefined) {
|
||||
this.applications[this.editingAppId] = newApp;
|
||||
this.editingAppId = undefined;
|
||||
} else {
|
||||
this.applications.push(newApp);
|
||||
}
|
||||
|
||||
this.saveToStorage('applications', this.applications);
|
||||
this.closeModals();
|
||||
location.href = './applications.html';
|
||||
}
|
||||
|
||||
openAccountModal() {
|
||||
this.editingAccountId = undefined;
|
||||
document.getElementById('accountService').value = '';
|
||||
document.getElementById('accountOwner').value = '';
|
||||
document.getElementById('accountUsername').value = '';
|
||||
document.getElementById('accountPassword').value = '';
|
||||
document.getElementById('accountModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
openAppModal() {
|
||||
this.editingAppId = undefined;
|
||||
document.getElementById('appName').value = '';
|
||||
document.getElementById('appType').value = '';
|
||||
document.getElementById('appStatus').value = 'online';
|
||||
document.getElementById('appModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
closeModals() {
|
||||
document.querySelectorAll('.modal-backdrop').forEach(modal => {
|
||||
modal.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
loadFromStorage(key) {
|
||||
const data = localStorage.getItem(key);
|
||||
return data ? JSON.parse(data) : null;
|
||||
}
|
||||
|
||||
saveToStorage(key, data) {
|
||||
localStorage.setItem(key, JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize app when DOM is ready
|
||||
let app;
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
app = new AccountManager();
|
||||
});
|
||||
Reference in New Issue
Block a user