mohadese-dashboards/cockpit.html

2158 lines
87 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ExecCockpit | سیستم عامل مدیریت اجرایی حامد فلاحی</title>
<!-- Vazirmatn Font -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #090a0f;
--bg-surface: #11131a;
--bg-surface-elevated: #181b24;
--bg-surface-hover: #212532;
--border-subtle: #252a38;
--border-strong: #384054;
--text-main: #f1f5f9;
--text-muted: #94a3b8;
--text-faint: #64748b;
--primary: #3b82f6;
--primary-hover: #2563eb;
--primary-glow: rgba(59, 130, 246, 0.2);
--accent-green: #10b981;
--accent-amber: #f59e0b;
--accent-rose: #f43f5e;
--accent-purple: #8b5cf6;
--radius-sm: 8px;
--radius-md: 12px;
--radius-lg: 16px;
--transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-feature-settings: "tnum" 1;
}
body {
background-color: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
line-height: 1.6;
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
background: var(--border-strong);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--text-faint);
}
/* Header & Navigation */
header {
background: rgba(17, 19, 26, 0.85);
backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border-subtle);
position: sticky;
top: 0;
z-index: 50;
padding: 0.75rem 1.5rem;
}
.header-inner {
max-width: 1400px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.brand {
display: flex;
align-items: center;
gap: 0.75rem;
}
.brand-logo {
width: 36px;
height: 36px;
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
border-radius: var(--radius-sm);
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
color: white;
font-size: 1.1rem;
box-shadow: 0 0 15px var(--primary-glow);
}
.brand-title {
font-size: 1.1rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.brand-subtitle {
font-size: 0.75rem;
color: var(--text-muted);
}
/* Mode Switcher */
.view-switcher {
display: flex;
background: var(--bg-surface-elevated);
padding: 3px;
border-radius: var(--radius-sm);
border: 1px solid var(--border-subtle);
gap: 2px;
}
.view-btn {
padding: 0.4rem 0.9rem;
border: none;
background: transparent;
color: var(--text-muted);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
border-radius: 6px;
transition: var(--transition);
display: flex;
align-items: center;
gap: 0.4rem;
}
.view-btn.active {
background: var(--primary);
color: white;
box-shadow: 0 2px 8px var(--primary-glow);
}
.view-btn:hover:not(.active) {
color: var(--text-main);
background: var(--bg-surface-hover);
}
.sync-status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.8rem;
padding: 0.35rem 0.75rem;
border-radius: 20px;
background: var(--bg-surface-elevated);
border: 1px solid var(--border-subtle);
color: var(--text-muted);
}
.sync-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent-green);
box-shadow: 0 0 8px var(--accent-green);
}
.sync-dot.syncing {
background: var(--accent-amber);
box-shadow: 0 0 8px var(--accent-amber);
animation: pulse 1s infinite alternate;
}
@keyframes pulse {
0% { opacity: 0.4; transform: scale(0.9); }
100% { opacity: 1; transform: scale(1.1); }
}
/* Navigation Tabs (Master View) */
.nav-tabs {
display: flex;
gap: 0.5rem;
overflow-x: auto;
padding: 0.75rem 1.5rem;
background: var(--bg-surface);
border-bottom: 1px solid var(--border-subtle);
max-width: 1400px;
margin: 0 auto;
width: 100%;
}
.tab-btn {
padding: 0.5rem 1rem;
border-radius: var(--radius-sm);
border: 1px solid transparent;
background: transparent;
color: var(--text-muted);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
white-space: nowrap;
transition: var(--transition);
display: flex;
align-items: center;
gap: 0.5rem;
}
.tab-btn:hover {
background: var(--bg-surface-hover);
color: var(--text-main);
}
.tab-btn.active {
background: var(--bg-surface-elevated);
border-color: var(--border-strong);
color: var(--primary);
font-weight: 600;
}
.badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.15rem 0.45rem;
border-radius: 12px;
font-size: 0.7rem;
font-weight: 700;
line-height: 1;
}
.badge-primary { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.badge-rose { background: rgba(244, 63, 94, 0.2); color: #fb7185; }
.badge-amber { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge-green { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-purple { background: rgba(139, 92, 246, 0.2); color: #c084fc; }
/* Main Container */
main {
flex: 1;
max-width: 1400px;
width: 100%;
margin: 0 auto;
padding: 1.5rem;
}
/* Cards & Containers */
.card {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
padding: 1.25rem;
transition: var(--transition);
position: relative;
}
.card:hover {
border-color: var(--border-strong);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--border-subtle);
}
.card-title {
font-size: 1rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 0.5rem;
}
/* Info Tooltip Icon */
.info-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--bg-surface-elevated);
color: var(--text-muted);
border: 1px solid var(--border-strong);
font-size: 0.75rem;
font-style: normal;
cursor: help;
transition: var(--transition);
position: relative;
}
.info-icon:hover {
color: var(--primary);
border-color: var(--primary);
}
.info-icon[data-tooltip]::after {
content: attr(data-tooltip);
position: absolute;
bottom: 125%;
right: 50%;
transform: translateX(50%);
background: #1e2230;
color: #f1f5f9;
padding: 0.5rem 0.75rem;
border-radius: var(--radius-sm);
font-size: 0.75rem;
font-weight: 400;
white-space: normal;
width: 240px;
line-height: 1.4;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
border: 1px solid var(--border-strong);
pointer-events: none;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s;
z-index: 100;
text-align: right;
}
.info-icon:hover::after {
opacity: 1;
visibility: visible;
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.5rem 1rem;
border-radius: var(--radius-sm);
border: 1px solid var(--border-strong);
background: var(--bg-surface-elevated);
color: var(--text-main);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
text-decoration: none;
}
.btn:hover {
background: var(--bg-surface-hover);
border-color: var(--text-faint);
}
.btn-primary {
background: var(--primary);
border-color: var(--primary);
color: white;
}
.btn-primary:hover {
background: var(--primary-hover);
box-shadow: 0 0 12px var(--primary-glow);
}
.btn-success {
background: rgba(16, 185, 129, 0.15);
border-color: rgba(16, 185, 129, 0.3);
color: #34d399;
}
.btn-success:hover {
background: var(--accent-green);
color: white;
}
.btn-danger {
background: rgba(244, 63, 94, 0.15);
border-color: rgba(244, 63, 94, 0.3);
color: #fb7185;
}
.btn-danger:hover {
background: var(--accent-rose);
color: white;
}
.btn-sm {
padding: 0.3rem 0.65rem;
font-size: 0.78rem;
}
/* Forms & Inputs */
.form-group {
margin-bottom: 1rem;
}
.form-label {
display: block;
font-size: 0.8rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.4rem;
}
.form-control {
width: 100%;
padding: 0.6rem 0.85rem;
background: var(--bg-base);
border: 1px solid var(--border-strong);
border-radius: var(--radius-sm);
color: var(--text-main);
font-size: 0.9rem;
transition: var(--transition);
}
.form-control:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea.form-control {
resize: vertical;
min-height: 80px;
}
/* Grid Layouts */
.grid-2 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: 1.25rem;
}
.grid-3 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.25rem;
}
.grid-4 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1rem;
}
/* Executive Hamed View Specific */
.exec-banner {
background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
border: 1px solid rgba(59, 130, 246, 0.3);
border-radius: var(--radius-md);
padding: 1.25rem 1.5rem;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
}
.exec-kpi-card {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
padding: 1rem;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.exec-kpi-val {
font-size: 1.8rem;
font-weight: 800;
color: var(--text-main);
}
.exec-kpi-label {
font-size: 0.8rem;
color: var(--text-muted);
display: flex;
align-items: center;
gap: 0.35rem;
}
/* Tables */
.table-container {
overflow-x: auto;
border-radius: var(--radius-sm);
border: 1px solid var(--border-subtle);
}
table {
width: 100%;
border-collapse: collapse;
text-align: right;
font-size: 0.85rem;
}
th {
background: var(--bg-surface-elevated);
color: var(--text-muted);
padding: 0.75rem 1rem;
font-weight: 600;
border-bottom: 1px solid var(--border-subtle);
white-space: nowrap;
}
td {
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--border-subtle);
color: var(--text-main);
}
tr:last-child td {
border-bottom: none;
}
tr:hover td {
background: var(--bg-surface-hover);
}
/* Action bar */
.action-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1.25rem;
flex-wrap: wrap;
}
.search-box {
flex: 1;
min-width: 240px;
position: relative;
}
.search-input {
width: 100%;
padding: 0.55rem 2.2rem 0.55rem 0.85rem;
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: var(--radius-sm);
color: var(--text-main);
font-size: 0.85rem;
}
.search-icon {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
color: var(--text-faint);
}
/* Modals */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.75);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
padding: 1rem;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.modal-overlay.active {
opacity: 1;
pointer-events: auto;
}
.modal-content {
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: var(--radius-lg);
width: 100%;
max-width: 550px;
max-height: 90vh;
overflow-y: auto;
padding: 1.5rem;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.25rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
font-size: 1.1rem;
font-weight: 700;
}
.modal-close {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
font-size: 1.2rem;
line-height: 1;
}
.modal-close:hover {
color: var(--text-main);
}
/* Toast */
.toast-container {
position: fixed;
bottom: 1.5rem;
left: 1.5rem;
z-index: 200;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.toast {
background: var(--bg-surface-elevated);
border: 1px solid var(--border-strong);
color: var(--text-main);
padding: 0.75rem 1.25rem;
border-radius: var(--radius-sm);
box-shadow: 0 4px 20px rgba(0,0,0,0.4);
display: flex;
align-items: center;
gap: 0.6rem;
font-size: 0.85rem;
animation: slideIn 0.2s ease;
}
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
/* Provenance Footer */
footer {
border-top: 1px solid var(--border-subtle);
padding: 1.5rem;
background: var(--bg-surface);
font-size: 0.8rem;
color: var(--text-muted);
margin-top: auto;
}
.footer-inner {
max-width: 1400px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
}
/* Responsive */
@media (max-width: 768px) {
.header-inner { flex-direction: column; align-items: stretch; }
.view-switcher { justify-content: center; }
.nav-tabs { padding: 0.5rem 1rem; }
main { padding: 1rem; }
.action-bar { flex-direction: column; align-items: stretch; }
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="header-inner">
<div class="brand">
<div class="brand-logo">H</div>
<div>
<div class="brand-title">ExecCockpit | سیستم مدیریت اجرایی حامد فلاحی</div>
<div class="brand-subtitle">هماهنگی فرآیندها: محدثه معصومی | نسخه ابری زنده</div>
</div>
</div>
<!-- Mode Selector -->
<div class="view-switcher">
<button class="view-btn active" onclick="switchView('hamed')">
👤 میز کار حامد (Executive)
</button>
<button class="view-btn" onclick="switchView('master')">
⚙️ پنل مستر (محدثه)
</button>
<button class="view-btn" onclick="switchView('team')">
📥 پرتال ثبت تیم (ورودی امن)
</button>
</div>
<div class="sync-status">
<span class="sync-dot" id="syncDot"></span>
<span id="syncText">🟢 اصالت داده: PostgreSQL 17 زنده (/api/db/state)</span>
<i class="info-icon" data-tooltip="این سیستم داده‌ها را بدون استفاده از حافظه موقت محلی (localStorage)، مستقیماً در جدول دائمی ekeepa_bi.dashboard_app_storage ذخیره می‌کند.">ⓘ</i>
</div>
</div>
</header>
<!-- Master Sub-navigation (Only in Master Mode) -->
<nav class="nav-tabs" id="masterNav" style="display: none;">
<button class="tab-btn active" onclick="switchTab('approvals')">
⚡ صف تاییدیه‌ها <span class="badge badge-rose" id="badgeApprovals">0</span>
<i class="info-icon" data-tooltip="درخواست‌هایی که سایر اعضا ثبت کرده‌اند یا تصمیماتی که معطل اعلام نظر نهایی حامد هستند.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('meetings')">
📅 جلسات و تردد <span class="badge badge-primary" id="badgeMeetings">0</span>
<i class="info-icon" data-tooltip="برنامه جلسات آنلاین با لینک میت، و حضوری با پین نشان و بافر ترافیک تهران.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('tasks')">
📋 تسک‌های اجرایی <span class="badge badge-amber" id="badgeTasks">0</span>
<i class="info-icon" data-tooltip="مدیریت تسک‌های تیم و حامد با تفکیک اولویت، مسئول و ددلاین.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('finance')">
💳 رادار مالی و اقساط <span class="badge badge-green" id="badgeFinance">0</span>
<i class="info-icon" data-tooltip="تاریخ سررسید اقساط تسهیلات بانکی، تنخواه‌ها و واریزی‌های معین.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('contacts')">
📇 مخاطبین VIP <span class="badge badge-purple" id="badgeContacts">0</span>
<i class="info-icon" data-tooltip="دفترچه راهبردی تفکیک‌شده: ایکیپا، مایندرو، شخصی و سرمایه‌گذاران.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('vault')">
📁 آرشیو و اسناد درایو
<i class="info-icon" data-tooltip="لینک‌های دسترسی سریع به فولدرهای گوگل‌درایو، مدارک شرکتی و NDA.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchTab('recycle')">
🗑️ سطل بازیافت و بکاپ <span class="badge badge-primary" id="badgeRecycle">0</span>
<i class="info-icon" data-tooltip="تمامی آیتم‌های حذف‌شده در اینجا نگهداری می‌شوند و قابل بازگردانی کامل هستند. هیچ داده‌ای از بین نمی‌رود.">ⓘ</i>
</button>
</nav>
<!-- Main Viewports -->
<main>
<!-- ==================== 1. HAMED EXECUTIVE VIEW ==================== -->
<section id="viewHamed">
<div class="exec-banner">
<div>
<h2 style="font-size: 1.3rem; margin-bottom: 0.35rem;">درود حامد عزیز؛ برنامه روزانه و اولویت‌های تصمیم‌گیری</h2>
<p style="color: var(--text-muted); font-size: 0.85rem;">برای حفظ تمرکز شما، این نما فقط شامل موارد نیازمند اقدام، جلسات پیش‌رو و هشدارهای مالی است.</p>
</div>
<div style="display: flex; gap: 0.5rem;">
<button class="btn btn-sm btn-primary" onclick="exportFullBackup()">📥 دانلود بکاپ آفلاین JSON</button>
<button class="btn btn-sm" onclick="switchView('master')">ورود به پنل مستر ⚙️</button>
</div>
</div>
<!-- KPI Ribbon -->
<div class="grid-3" style="margin-bottom: 1.5rem;">
<div class="exec-kpi-card">
<div class="exec-kpi-label">
⚡ تاییدیه‌های فوری معطل تصمیم شما
<i class="info-icon" data-tooltip="درخواست‌های گلوگاهی تیم که بدون تایید شما کار متوقف می‌ماند.">ⓘ</i>
</div>
<div class="exec-kpi-val" id="kpiHamedApprovals" style="color: var(--accent-rose);">0</div>
</div>
<div class="exec-kpi-card">
<div class="exec-kpi-label">
📅 جلسات زمان‌بندی‌شده امروز
<i class="info-icon" data-tooltip="تعداد جلسات آنلاین و حضوری با احتساب بافرهای استراحت و تردد.">ⓘ</i>
</div>
<div class="exec-kpi-val" id="kpiHamedMeetings" style="color: var(--primary);">0</div>
</div>
<div class="exec-kpi-card">
<div class="exec-kpi-label">
💳 سررسید اقساط و چک‌های ۷ روز آینده
<i class="info-icon" data-tooltip="تسهیلات بانکی، اقساط دیجی‌شهر/بانک شهر و تعهدات حقوق پرسنل.">ⓘ</i>
</div>
<div class="exec-kpi-val" id="kpiHamedInstallments" style="color: var(--accent-amber);">0</div>
</div>
</div>
<!-- Hamed View Split -->
<div class="grid-2">
<!-- Approvals Queue -->
<div class="card">
<div class="card-header">
<div class="card-title">
⚡ کارتابل تاییدیه فوری حامد
<i class="info-icon" data-tooltip="پاسخ به سوالات کلیدی اعضای تیم با یک کلیک.">ⓘ</i>
</div>
<span class="badge badge-rose">نیاز به اقدام</span>
</div>
<div id="hamedApprovalsList" style="display: flex; flex-direction: column; gap: 0.75rem;">
<!-- Rendered dynamically -->
</div>
</div>
<!-- Today Meetings -->
<div class="card">
<div class="card-header">
<div class="card-title">
📅 جلسات امروز و دسترسی سریع
<i class="info-icon" data-tooltip="جلسات امروز به همراه لینک آنلاین گوگل‌میت یا لوکیشن حضوری.">ⓘ</i>
</div>
<span class="badge badge-primary">برنامه امروز</span>
</div>
<div id="hamedMeetingsList" style="display: flex; flex-direction: column; gap: 0.75rem;">
<!-- Rendered dynamically -->
</div>
</div>
</div>
</section>
<!-- ==================== 2. MASTER OPS VIEW ==================== -->
<section id="viewMaster" style="display: none;">
<!-- Sub Tab: Approvals -->
<div id="tabContentApprovals" class="tab-content">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تاییدیه‌ها..." oninput="filterData('approvals', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalApproval')">+ تاییدیه جدید برای حامد</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان تصمیم / درخواست</th>
<th>درخواست‌کننده</th>
<th>فوریت</th>
<th>پیشنهاد / توضیحات</th>
<th>پیوست</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyApprovals"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Meetings -->
<div id="tabContentMeetings" class="tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در جلسات..." oninput="filterData('meetings', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalMeeting')">+ ثبت جلسه جدید</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان جلسه</th>
<th>نوع</th>
<th>تاریخ و ساعت</th>
<th>طرفین جلسه</th>
<th>بافر / زمان حرکت</th>
<th>لینک میت / لوکیشن</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyMeetings"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Tasks -->
<div id="tabContentTasks" class="tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تسک‌ها..." oninput="filterData('tasks', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalTask')">+ افزودن تسک اجرایی</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان تسک</th>
<th>مسئول</th>
<th>دسته</th>
<th>اولویت</th>
<th>مهلت تحویل</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyTasks"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Finance -->
<div id="tabContentFinance" class="tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تسهیلات و اقساط..." oninput="filterData('finance', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalFinance')">+ ثبت تسهیلات یا قسط</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>موضوع تسهیلات / قسط</th>
<th>بانک / مرجع</th>
<th>مبلغ (تومان)</th>
<th>تاریخ سررسید</th>
<th>شماره قرارداد / تسهیلات</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyFinance"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Contacts -->
<div id="tabContentContacts" class="tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در مخاطبین..." oninput="filterData('contacts', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalContact')">+ افزودن مخاطب VIP</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>نام و نام خانوادگی</th>
<th>دسته‌بندی</th>
<th>سازمان و سمت</th>
<th>شماره تماس</th>
<th>آیدی تلگرام / واتس‌اپ</th>
<th>نکات و ترجیحات</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyContacts"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Vault -->
<div id="tabContentVault" class="tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در اسناد و درایو..." oninput="filterData('vault', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openModal('modalVault')">+ افزودن سند یا لینک درایو</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان سند یا فولدر</th>
<th>دسته‌بندی</th>
<th>لینک درایو / دسترسی</th>
<th>سطح محرمانگی</th>
<th>توضیحات</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyVault"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Recycle Bin & Backup -->
<div id="tabContentRecycle" class="tab-content" style="display: none;">
<div class="action-bar">
<div style="display: flex; gap: 0.5rem; align-items: center;">
<button class="btn btn-primary btn-sm" onclick="exportFullBackup()">📥 دانلود بکاپ جامع (JSON)</button>
<button class="btn btn-sm" onclick="restoreFromBackupFile()">📤 بازیابی از فایل بکاپ</button>
</div>
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در سطل زباله..." oninput="filterData('recycle', this.value)">
</div>
</div>
<div class="card" style="margin-bottom: 1rem;">
<div style="font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.5rem;">
🛡️ <strong>قانون عدم ابطال اطلاعات:</strong> تمامی داده‌های حذف‌شده از همه بخش‌ها به این سطل منتقل می‌شوند و تاریخ دقیق حذف و کاربر ثبت می‌گردد. شما می‌توانید در هر زمان با دکمه «بازیابی» آن‌ها را به سیستم برگردانید.
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>نوع آیتم</th>
<th>عنوان / محتوا</th>
<th>تاریخ حذف</th>
<th>جزئیات داده قبلی</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyRecycle"></tbody>
</table>
</div>
</div>
</section>
<!-- ==================== 3. TEAM INTAKE PORTAL ==================== -->
<section id="viewTeam" style="display: none;">
<div style="max-width: 600px; margin: 2rem auto;">
<div class="card">
<div class="card-header">
<div class="card-title">
📥 پرتال ارسال درخواست تاییدیه به حامد
<i class="info-icon" data-tooltip="اعضای تیم بدون دیدن تقویم، اسناد مالی یا سایر تسک‌های مدیر، درخواست تاییدیه خود را مستقیماً در صف حامد ثبت می‌کنند.">ⓘ</i>
</div>
<span class="badge badge-purple">ورودی امن همکاران</span>
</div>
<p style="font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.25rem;">
همکار گرامی؛ برای تسریع در پاسخگویی، لطفاً صورت‌مسئله، گزینه پیشنهادی و ددلاین خود را کوتاه و شفاف وارد کنید.
</p>
<form id="teamIntakeForm" onsubmit="handleTeamSubmit(event)">
<div class="form-group">
<label class="form-label">نام شما و نقش سازمانی *</label>
<input type="text" class="form-control" id="teamRequester" placeholder="مثال: سارا محمودزاده (محصول) یا آرمین زاهدی (فنی)" required>
</div>
<div class="form-group">
<label class="form-label">موضوع درخواست یا تصمیم نیازمند تایید *</label>
<input type="text" class="form-control" id="teamTitle" placeholder="مثال: تایید نهایی متن قرارداد با نیایش مال" required>
</div>
<div class="form-group">
<label class="form-label">درجه فوریت</label>
<select class="form-control" id="teamPriority">
<option value="P0">⚡ P0 - فوری (کار متوقف شده است)</option>
<option value="P1" selected>⏳ P1 - مهم (تا ۲۴ ساعت آینده)</option>
<option value="P2">🟢 P2 - عادی (تا پایان هفته)</option>
</select>
</div>
<div class="form-group">
<label class="form-label">توضیح کوتاه و گزینه پیشنهادی شما</label>
<textarea class="form-control" id="teamDescription" placeholder="مثال: پیشنهاد من گزینه الف است چون ریسک فسخ کمتری دارد. در صورت موافقت تایید بفرمایید." required></textarea>
</div>
<div class="form-group">
<label class="form-label">لینک سند یا فایل ضمیمه (گوگل درایو / فیگما / تسک)</label>
<input type="url" class="form-control" id="teamLink" placeholder="https://docs.google.com/...">
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">🚀 ثبت درخواست در کارتابل حامد</button>
</form>
</div>
</div>
</section>
</main>
<!-- Modals for Full CRUD -->
<!-- 1. Modal Approval -->
<div class="modal-overlay" id="modalApproval">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalApprovalTitle">ثبت تاییدیه جدید برای حامد</div>
<button class="modal-close" onclick="closeModal('modalApproval')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'approvals')">
<input type="hidden" id="approvalId">
<div class="form-group">
<label class="form-label">عنوان تصمیم / درخواست *</label>
<input type="text" class="form-control" id="approvalTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">درخواست‌کننده *</label>
<input type="text" class="form-control" id="approvalRequesterInput" required>
</div>
<div class="form-group">
<label class="form-label">فوریت</label>
<select class="form-control" id="approvalPriorityInput">
<option value="P0">P0 - فوری و اضطراری</option>
<option value="P1" selected>P1 - با اولویت بالا</option>
<option value="P2">P2 - عادی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">پیشنهاد شما / توضیحات *</label>
<textarea class="form-control" id="approvalDescriptionInput" required></textarea>
</div>
<div class="form-group">
<label class="form-label">لینک پیوست</label>
<input type="url" class="form-control" id="approvalLinkInput">
</div>
<div class="form-group">
<label class="form-label">وضعیت</label>
<select class="form-control" id="approvalStatusInput">
<option value="pending">در انتظار تایید حامد</option>
<option value="approved">تایید شده ✅</option>
<option value="rejected">رد شده / نیاز به اصلاح ❌</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalApproval')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره تاییدیه</button>
</div>
</form>
</div>
</div>
<!-- 2. Modal Meeting -->
<div class="modal-overlay" id="modalMeeting">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalMeetingTitle">ثبت جلسه جدید</div>
<button class="modal-close" onclick="closeModal('modalMeeting')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'meetings')">
<input type="hidden" id="meetingId">
<div class="form-group">
<label class="form-label">عنوان جلسه *</label>
<input type="text" class="form-control" id="meetingTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">نوع جلسه</label>
<select class="form-control" id="meetingTypeInput">
<option value="online">💻 آنلاین (گوگل‌میت / ادوبی)</option>
<option value="in_person">🚗 حضوری (تهران / همراه با تردد)</option>
</select>
</div>
<div class="form-group">
<label class="form-label">تاریخ و ساعت *</label>
<input type="text" class="form-control" id="meetingTimeInput" placeholder="مثال: امروز ۱۴:۰۰ تا ۱۵:۳۰" required>
</div>
<div class="form-group">
<label class="form-label">افراد حاضر و نقش‌ها</label>
<input type="text" class="form-control" id="meetingAttendeesInput" placeholder="مثال: حامد، سارا، مدیران باغ کتاب">
</div>
<div class="form-group">
<label class="form-label">بافر ترافیک / زمان خروج پیشنهادی (حضوری)</label>
<input type="text" class="form-control" id="meetingBufferInput" placeholder="مثال: خروج ساعت ۱۳:۱۵ (۴۵ دقیقه بافر)">
</div>
<div class="form-group">
<label class="form-label">لینک میت آنلاین یا آدرس/پین نشان</label>
<input type="text" class="form-control" id="meetingLinkInput" placeholder="https://meet.google.com/... یا لینک نشان">
</div>
<div class="form-group">
<label class="form-label">یادداشت پیش از جلسه و فایل‌ها</label>
<textarea class="form-control" id="meetingNotesInput" placeholder="هدف جلسه، خروجی مورد انتظار و شماره تماس فرد میزبان"></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalMeeting')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره جلسه</button>
</div>
</form>
</div>
</div>
<!-- 3. Modal Task -->
<div class="modal-overlay" id="modalTask">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalTaskTitle">ثبت تسک اجرایی جدید</div>
<button class="modal-close" onclick="closeModal('modalTask')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'tasks')">
<input type="hidden" id="taskId">
<div class="form-group">
<label class="form-label">عنوان تسک *</label>
<input type="text" class="form-control" id="taskTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">مسئول انجام</label>
<input type="text" class="form-control" id="taskAssigneeInput" placeholder="حامد فلاحی / محدثه معصومی / سارا و...">
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="taskCategoryInput">
<option value="ایکیپا">ایکیپا</option>
<option value="مایندرو">مایندرو</option>
<option value="مالی و وام">مالی و وام</option>
<option value="حقوقی و ثنا">حقوقی و ثنا</option>
<option value="شخصی">شخصی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">اولویت</label>
<select class="form-control" id="taskPriorityInput">
<option value="P0">P0 - بحرانی</option>
<option value="P1" selected>P1 - بالا</option>
<option value="P2">P2 - عادی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">مهلت تحویل (ددلاین)</label>
<input type="text" class="form-control" id="taskDeadlineInput" placeholder="مثال: چهارشنبه ساعت ۱۷">
</div>
<div class="form-group">
<label class="form-label">وضعیت</label>
<select class="form-control" id="taskStatusInput">
<option value="todo">در صف انجام</option>
<option value="in_progress">در حال اقدام</option>
<option value="waiting_approval">منتظر تایید حامد</option>
<option value="done">تکمیل شده</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalTask')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره تسک</button>
</div>
</form>
</div>
</div>
<!-- 4. Modal Finance -->
<div class="modal-overlay" id="modalFinance">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalFinanceTitle">ثبت موعد قسط یا تسهیلات</div>
<button class="modal-close" onclick="closeModal('modalFinance')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'finance')">
<input type="hidden" id="financeId">
<div class="form-group">
<label class="form-label">موضوع قسط یا واریزی *</label>
<input type="text" class="form-control" id="financeTitleInput" placeholder="مثال: قسط تسهیلات دیجی‌شهر / اجاره شعبه نیایش" required>
</div>
<div class="form-group">
<label class="form-label">بانک یا مرجع</label>
<input type="text" class="form-control" id="financeBankInput" placeholder="بانک شهر، بلو بانک و...">
</div>
<div class="form-group">
<label class="form-label">مبلغ (تومان) *</label>
<input type="text" class="form-control" id="financeAmountInput" placeholder="مثال: 15,000,000" required>
</div>
<div class="form-group">
<label class="form-label">تاریخ سررسید *</label>
<input type="text" class="form-control" id="financeDueDateInput" placeholder="مثال: ۲۵ آبان ماه" required>
</div>
<div class="form-group">
<label class="form-label">شماره تسهیلات / شبا یا یادداشت</label>
<input type="text" class="form-control" id="financeNotesInput">
</div>
<div class="form-group">
<label class="form-label">وضعیت پرداخت</label>
<select class="form-control" id="financeStatusInput">
<option value="pending">در انتظار پرداخت</option>
<option value="paid">پرداخت شده ✅</option>
<option value="overdue">معوق / اخطار ⚠️</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalFinance')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره رکورد مالی</button>
</div>
</form>
</div>
</div>
<!-- 5. Modal Contact -->
<div class="modal-overlay" id="modalContact">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalContactTitle">ثبت مخاطب کلیدی VIP</div>
<button class="modal-close" onclick="closeModal('modalContact')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'contacts')">
<input type="hidden" id="contactId">
<div class="form-group">
<label class="form-label">نام و نام خانوادگی *</label>
<input type="text" class="form-control" id="contactNameInput" required>
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="contactCategoryInput">
<option value="ایکیپا">ایکیپا</option>
<option value="مایندرو">مایندرو</option>
<option value="سرمایه‌گذار و استراتژیک">سرمایه‌گذار و استراتژیک</option>
<option value="بانکی و حقوقی">بانکی و حقوقی</option>
<option value="شخصی">شخصی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">سازمان و سمت</label>
<input type="text" class="form-control" id="contactRoleInput">
</div>
<div class="form-group">
<label class="form-label">شماره همراه *</label>
<input type="text" class="form-control" id="contactPhoneInput" required>
</div>
<div class="form-group">
<label class="form-label">آیدی تلگرام / واتس‌اپ</label>
<input type="text" class="form-control" id="contactSocialInput">
</div>
<div class="form-group">
<label class="form-label">ترجیحات، سوابق و نکات حساسیت</label>
<textarea class="form-control" id="contactNotesInput" placeholder="کانال ارتباطی ترجیحی، موضوعات مشترک و..."></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalContact')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره مخاطب</button>
</div>
</form>
</div>
</div>
<!-- 6. Modal Vault -->
<div class="modal-overlay" id="modalVault">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalVaultTitle">ثبت سند یا پوشه درایو</div>
<button class="modal-close" onclick="closeModal('modalVault')">&times;</button>
</div>
<form onsubmit="saveItem(event, 'vault')">
<input type="hidden" id="vaultId">
<div class="form-group">
<label class="form-label">عنوان پوشه یا سند *</label>
<input type="text" class="form-control" id="vaultTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="vaultCategoryInput">
<option value="اسناد حقوقی و ثنا">اسناد حقوقی و ثنا</option>
<option value="مدارک هویتی شرکت و حامد">مدارک هویتی شرکت و حامد</option>
<option value="قراردادها و NDA">قراردادها و NDA</option>
<option value="امور شعب و مایندرو">امور شعب و مایندرو</option>
<option value="مالی و وام‌ها">مالی و وام‌ها</option>
</select>
</div>
<div class="form-group">
<label class="form-label">لینک دسترسی گوگل درایو *</label>
<input type="url" class="form-control" id="vaultLinkInput" placeholder="https://drive.google.com/..." required>
</div>
<div class="form-group">
<label class="form-label">سطح محرمانگی</label>
<select class="form-control" id="vaultSecInput">
<option value="محرمانه (فقط حامد و محدثه)">محرمانه (فقط حامد و محدثه)</option>
<option value="تیم داخلی">تیم داخلی</option>
<option value="عمومی">عمومی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">توضیحات و محتویات</label>
<textarea class="form-control" id="vaultDescInput"></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalVault')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره سند</button>
</div>
</form>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<!-- Footer with Data Provenance -->
<footer>
<div class="footer-inner">
<div>
<span>🟢 <strong>اصالت داده (Data Provenance):</strong> متصل مستقیم به PostgreSQL 17</span>
<span style="margin: 0 0.5rem;">|</span>
<span>جدول: <code>ekeepa_bi.dashboard_app_storage</code></span>
<span style="margin: 0 0.5rem;">|</span>
<span>کلید دیتابیس: <code>exec_cockpit_state</code></span>
</div>
<div>
<span>سیستم حفاظت از داده‌ها: سطل بازیافت فعال (Soft-Delete & Full Audit Log)</span>
</div>
</div>
</footer>
<!-- Application Logic -->
<script>
// Initial Seed Data (if database empty)
const defaultData = {
approvals: [
{
id: "app_1",
title: "تایید قرارداد NDA با شریک راهبردی باغ کتاب",
requester: "صالح اسکندرزاده (حقوقی)",
priority: "P0",
description: "بند عدم رقابت به ۳ سال تقلیل یافت؛ در صورت موافقت تایید کنید تا نسخه نهایی پرینت شود.",
link: "https://drive.google.com",
status: "pending",
createdAt: "۱۴۰۴/۰۸/۲۲"
},
{
id: "app_2",
title: "تخصیص بودجه ادز بلک‌فرایدی ایکیپا",
requester: "الهه فلاحی (مارکتینگ)",
priority: "P1",
description: "برآورد ۳۵ میلیون تومان برای کمپین ریتارگتینگ؛ پیش‌بینی ROI ۳.۴ برابری.",
link: "https://drive.google.com",
status: "pending",
createdAt: "۱۴۰۴/۰۸/۲۲"
}
],
meetings: [
{
id: "meet_1",
title: "جلسه هماهنگی بازاریابی و پکیج‌های جدید مایندرو",
type: "online",
time: "امروز ۱۰:۳۰ تا ۱۱:۳۰",
attendees: "حامد، سارا محمودزاده، غزاله مددی",
buffer: "آنلاین (بدون بافر تردد)",
link: "https://meet.google.com/abc-defg-hij",
notes: "بررسی قیمت‌گذاری سانس‌های آخر هفته نیایش مال و بازی چهارم"
},
{
id: "meet_2",
title: "جلسه حضوری با مدیران باغ کتاب تهران",
type: "in_person",
time: "امروز ۱۵:۰۰ تا ۱۶:۳۰",
attendees: "حامد فلاحی، خانم ارشادی",
buffer: "خروج ساعت ۱۴:۱۵ (۴۵ دقیقه بافر ترافیک همت)",
link: "https://neshan.org",
notes: "تحویل وسایل و نهایی‌سازی تسویه‌حساب تابستان؛ هماهنگی ورود با پارکینگ شماره ۱"
}
],
tasks: [
{
id: "task_1",
title: "ارسال مدارک تکمیلی وام دیجی‌شهر به شعبه",
assignee: "حامد فلاحی / محدثه",
category: "مالی و وام",
priority: "P0",
deadline: "امروز ساعت ۱۴",
status: "in_progress"
},
{
id: "task_2",
title: "بررسی کارکرد و حقوق ماهانه پرسنل مایندرو با پورصمد",
assignee: "محدثه معصومی",
category: "مایندرو",
priority: "P1",
deadline: "چهارشنبه",
status: "todo"
}
],
finance: [
{
id: "fin_1",
title: "قسط تسهیلات دیجی‌شهر (حامد و آقای فلاحی)",
bank: "بانک شهر",
amount: "14,800,000",
dueDate: "۲۸ آبان ماه",
notes: "تسهیلات شماره ۴۸۸۹۲",
status: "pending"
},
{
id: "fin_2",
title: "تسویه تنخواه هفتگی بلوبانک مایندرو",
bank: "بلو بانک",
amount: "8,500,000",
dueDate: "پایان هفته",
notes: "حساب مشترک هزینه‌های جاری شعب",
status: "pending"
}
],
contacts: [
{
id: "cnt_1",
name: "ایمان پورصمد",
category: "مایندرو",
role: "توسعه و حسابرسی مالی",
phone: "09120000000",
social: "@iman_pour",
notes: "هماهنگی روزهای سه‌شنبه و چهارشنبه؛ حساسیت روی تطابق ریالی واریزی‌ها"
},
{
id: "cnt_2",
name: "سارا محمودزاده",
category: "ایکیپا",
role: "Product & Operations Lead",
phone: "09121111111",
social: "@sara_m",
notes: "فیلتر اصلی مسائل محصول و تیم فنی؛ هماهنگی روتین روزانه"
},
{
id: "cnt_3",
name: "فدیا ارشادی",
category: "مایندرو",
role: "سوپروایزر باغ کتاب",
phone: "09122222222",
social: "@f_ershadi",
notes: "امور هماهنگی تخلیه، تحویل تجهیزات و تسویه‌های پرسنلی"
}
],
vault: [
{
id: "vlt_1",
title: "پوشه مدارک هویتی، آگهی تاسیس و روزنامه رسمی",
category: "مدارک هویتی شرکت و حامد",
link: "https://drive.google.com",
sec: "محرمانه (فقط حامد و محدثه)",
desc: "شناسنامه‌ها، کارت‌های ملی، امضاها و آگهی تغییرات هلدینگ"
},
{
id: "vlt_2",
title: "قراردادهای شعب نیایش و باغ کتاب مایندرو",
category: "امور شعب و مایندرو",
link: "https://drive.google.com",
sec: "محرمانه (فقط حامد و محدثه)",
desc: "اجاره‌نامه‌ها، الحاقیه‌ها و نسخه‌های اسکن‌شده امضا شده"
}
],
recycle: [] // Soft-deleted items
};
let appState = JSON.parse(JSON.stringify(defaultData));
let currentView = 'hamed';
let currentTab = 'approvals';
let saveTimeout = null;
// Database Sync Functions
async function loadFromPostgres() {
const syncDot = document.getElementById('syncDot');
const syncText = document.getElementById('syncText');
syncDot.className = 'sync-dot syncing';
syncText.innerText = 'در حال بازیابی اطلاعات از PostgreSQL 17...';
try {
const res = await fetch('/api/db/state?key=exec_cockpit_state');
if (res.ok) {
const json = await res.json();
if (json && json.data && typeof json.data === 'object' && json.data.approvals) {
appState = json.data;
showToast('✅ داده‌های زنده با موفقیت از PostgreSQL بارگذاری شد.');
} else {
// First time seeding
await saveToPostgres();
}
}
} catch (err) {
console.warn('PostgreSQL fetch error, running with cached data:', err);
} finally {
syncDot.className = 'sync-dot';
syncText.innerText = '🟢 اصالت داده: PostgreSQL 17 زنده (/api/db/state)';
renderAll();
}
}
async function saveToPostgres() {
const syncDot = document.getElementById('syncDot');
const syncText = document.getElementById('syncText');
syncDot.className = 'sync-dot syncing';
syncText.innerText = 'در حال ذخیره‌سازی ابری...';
try {
const payload = {
state_key: 'exec_cockpit_state',
data: appState
};
const res = await fetch('/api/db/state', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
syncDot.className = 'sync-dot';
syncText.innerText = '🟢 اصالت داده: PostgreSQL 17 ذخیره شد';
}
} catch (err) {
console.error('Error saving state to DB:', err);
syncDot.className = 'sync-dot';
syncText.innerText = '⚠️ خطای ذخیره‌سازی ابری؛ کش فعال';
}
}
function triggerStateChange() {
if (saveTimeout) clearTimeout(saveTimeout);
saveTimeout = setTimeout(saveToPostgres, 400);
renderAll();
}
// View & Tab Switching
function switchView(view) {
currentView = view;
document.querySelectorAll('.view-btn').forEach((btn, idx) => {
btn.classList.toggle('active',
(view === 'hamed' && idx === 0) ||
(view === 'master' && idx === 1) ||
(view === 'team' && idx === 2)
);
});
document.getElementById('viewHamed').style.display = (view === 'hamed') ? 'block' : 'none';
document.getElementById('viewMaster').style.display = (view === 'master') ? 'block' : 'none';
document.getElementById('viewTeam').style.display = (view === 'team') ? 'block' : 'none';
document.getElementById('masterNav').style.display = (view === 'master') ? 'flex' : 'none';
renderAll();
}
function switchTab(tab) {
currentTab = tab;
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
const activeBtn = Array.from(document.querySelectorAll('.tab-btn')).find(b => b.innerText.includes(getTabName(tab)));
if (activeBtn) activeBtn.classList.add('active');
document.querySelectorAll('.tab-content').forEach(tc => tc.style.display = 'none');
const targetContent = document.getElementById('tabContent' + capitalize(tab));
if (targetContent) targetContent.style.display = 'block';
}
function getTabName(t) {
const map = {
approvals: 'تاییدیه‌ها',
meetings: 'جلسات',
tasks: 'تسک‌های',
finance: 'مالی',
contacts: 'مخاطبین',
vault: 'آرشیو',
recycle: 'سطل'
};
return map[t] || '';
}
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
// Toast Notifications
function showToast(msg) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = 'toast';
toast.innerHTML = `<span>${msg}</span>`;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transition = 'opacity 0.3s ease';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Modal Handlers
function openModal(id) {
document.getElementById(id).classList.add('active');
}
function closeModal(id) {
document.getElementById(id).classList.remove('active');
}
// Render Logic
function renderAll() {
updateBadges();
renderHamedView();
renderMasterApprovals();
renderMasterMeetings();
renderMasterTasks();
renderMasterFinance();
renderMasterContacts();
renderMasterVault();
renderRecycleBin();
}
function updateBadges() {
document.getElementById('badgeApprovals').innerText = appState.approvals.filter(a => a.status === 'pending').length;
document.getElementById('badgeMeetings').innerText = appState.meetings.length;
document.getElementById('badgeTasks').innerText = appState.tasks.filter(t => t.status !== 'done').length;
document.getElementById('badgeFinance').innerText = appState.finance.filter(f => f.status === 'pending').length;
document.getElementById('badgeContacts').innerText = appState.contacts.length;
document.getElementById('badgeRecycle').innerText = appState.recycle.length;
document.getElementById('kpiHamedApprovals').innerText = appState.approvals.filter(a => a.status === 'pending').length;
document.getElementById('kpiHamedMeetings').innerText = appState.meetings.length;
document.getElementById('kpiHamedInstallments').innerText = appState.finance.filter(f => f.status === 'pending').length;
}
// Render Hamed Executive View
function renderHamedView() {
const approvalsList = document.getElementById('hamedApprovalsList');
const pendingApprovals = appState.approvals.filter(a => a.status === 'pending');
if (!pendingApprovals.length) {
approvalsList.innerHTML = `<div style="padding: 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.9rem;">✨ همه تاییدیه‌ها انجام شده است. موردی در صف انتظار نیست.</div>`;
} else {
approvalsList.innerHTML = pendingApprovals.map(appr => `
<div style="background: var(--bg-surface-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 1rem;">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem;">
<div style="font-weight: 700; font-size: 0.95rem; color: #f8fafc;">${appr.title}</div>
<span class="badge ${appr.priority === 'P0' ? 'badge-rose' : 'badge-amber'}">${appr.priority}</span>
</div>
<div style="font-size: 0.8rem; color: var(--primary); margin-bottom: 0.4rem;">👤 درخواست از: ${appr.requester}</div>
<p style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 0.75rem;">${appr.description}</p>
${appr.link ? `<div style="margin-bottom: 0.75rem;"><a href="${appr.link}" target="_blank" class="btn btn-sm" style="font-size: 0.75rem;">🔗 مشاهده سند ضمیمه</a></div>` : ''}
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button class="btn btn-sm btn-danger" onclick="setApprovalStatus('${appr.id}', 'rejected')">❌ رد / اصلاح</button>
<button class="btn btn-sm btn-success" onclick="setApprovalStatus('${appr.id}', 'approved')">✅ تایید فوری</button>
</div>
</div>
`).join('');
}
// Hamed Meetings List
const meetingsList = document.getElementById('hamedMeetingsList');
if (!appState.meetings.length) {
meetingsList.innerHTML = `<div style="padding: 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.9rem;">هیچ جلسه‌ای برای امروز تنظیم نشده است.</div>`;
} else {
meetingsList.innerHTML = appState.meetings.map(m => `
<div style="background: var(--bg-surface-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 1rem;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem;">
<div style="font-weight: 700; font-size: 0.95rem;">${m.title}</div>
<span class="badge ${m.type === 'online' ? 'badge-primary' : 'badge-amber'}">${m.type === 'online' ? '💻 آنلاین' : '🚗 حضوری'}</span>
</div>
<div style="font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.3rem;">⏰ ${m.time} | 👥 ${m.attendees || 'بدون لیست حاضرین'}</div>
${m.buffer ? `<div style="font-size: 0.78rem; color: #fbbf24; margin-bottom: 0.5rem;">⚠️ ${m.buffer}</div>` : ''}
${m.notes ? `<div style="font-size: 0.8rem; background: var(--bg-base); padding: 0.5rem; border-radius: 6px; margin-bottom: 0.6rem; color: var(--text-muted);">${m.notes}</div>` : ''}
<div style="display: flex; gap: 0.5rem;">
${m.link ? `<a href="${m.link}" target="_blank" class="btn btn-sm btn-primary" style="flex: 1; justify-content: center;">${m.type === 'online' ? '🚀 ورود به میت' : '📍 مسیریابی در نشان'}</a>` : ''}
</div>
</div>
`).join('');
}
}
function setApprovalStatus(id, status) {
const appr = appState.approvals.find(a => a.id === id);
if (appr) {
appr.status = status;
showToast(status === 'approved' ? '✅ تاییدیه صادر شد.' : '❌ درخواست رد/جهت اصلاح ارجاع شد.');
triggerStateChange();
}
}
// Master Approvals Table
function renderMasterApprovals() {
const tbody = document.getElementById('tableBodyApprovals');
tbody.innerHTML = appState.approvals.map(appr => `
<tr>
<td><strong>${appr.title}</strong></td>
<td>${appr.requester}</td>
<td><span class="badge ${appr.priority === 'P0' ? 'badge-rose' : 'badge-amber'}">${appr.priority}</span></td>
<td style="max-width: 250px;">${appr.description}</td>
<td>${appr.link ? `<a href="${appr.link}" target="_blank" class="btn btn-sm">لینک</a>` : '-'}</td>
<td>
<span class="badge ${appr.status === 'approved' ? 'badge-green' : (appr.status === 'rejected' ? 'badge-rose' : 'badge-primary')}">
${appr.status === 'approved' ? 'تایید شد' : (appr.status === 'rejected' ? 'رد شد' : 'در انتظار')}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('approvals', '${appr.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('approvals', '${appr.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Master Meetings Table
function renderMasterMeetings() {
const tbody = document.getElementById('tableBodyMeetings');
tbody.innerHTML = appState.meetings.map(m => `
<tr>
<td><strong>${m.title}</strong></td>
<td><span class="badge ${m.type === 'online' ? 'badge-primary' : 'badge-amber'}">${m.type === 'online' ? 'آنلاین' : 'حضوری'}</span></td>
<td>${m.time}</td>
<td>${m.attendees || '-'}</td>
<td>${m.buffer || '-'}</td>
<td>${m.link ? `<a href="${m.link}" target="_blank" class="btn btn-sm">باز کردن</a>` : '-'}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('meetings', '${m.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('meetings', '${m.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Master Tasks Table
function renderMasterTasks() {
const tbody = document.getElementById('tableBodyTasks');
tbody.innerHTML = appState.tasks.map(t => `
<tr>
<td><strong>${t.title}</strong></td>
<td>${t.assignee || '-'}</td>
<td><span class="badge badge-primary">${t.category}</span></td>
<td><span class="badge ${t.priority === 'P0' ? 'badge-rose' : (t.priority === 'P1' ? 'badge-amber' : 'badge-green')}">${t.priority}</span></td>
<td>${t.deadline || '-'}</td>
<td>
<span class="badge ${t.status === 'done' ? 'badge-green' : (t.status === 'waiting_approval' ? 'badge-rose' : 'badge-primary')}">
${t.status === 'done' ? 'تکمیل' : (t.status === 'waiting_approval' ? 'منتظر تایید' : (t.status === 'in_progress' ? 'در اقدام' : 'در صف'))}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('tasks', '${t.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('tasks', '${t.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Master Finance Table
function renderMasterFinance() {
const tbody = document.getElementById('tableBodyFinance');
tbody.innerHTML = appState.finance.map(f => `
<tr>
<td><strong>${f.title}</strong></td>
<td>${f.bank}</td>
<td style="font-weight: 700; color: var(--accent-green);">${f.amount}</td>
<td>${f.dueDate}</td>
<td>${f.notes || '-'}</td>
<td>
<span class="badge ${f.status === 'paid' ? 'badge-green' : (f.status === 'overdue' ? 'badge-rose' : 'badge-amber')}">
${f.status === 'paid' ? 'پرداخت شد' : (f.status === 'overdue' ? 'معوق' : 'در انتظار')}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('finance', '${f.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('finance', '${f.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Master Contacts Table
function renderMasterContacts() {
const tbody = document.getElementById('tableBodyContacts');
tbody.innerHTML = appState.contacts.map(c => `
<tr>
<td><strong>${c.name}</strong></td>
<td><span class="badge badge-purple">${c.category}</span></td>
<td>${c.role || '-'}</td>
<td style="direction: ltr; text-align: right;">${c.phone}</td>
<td style="direction: ltr; text-align: right;">${c.social || '-'}</td>
<td style="max-width: 250px;">${c.notes || '-'}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('contacts', '${c.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('contacts', '${c.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Master Vault Table
function renderMasterVault() {
const tbody = document.getElementById('tableBodyVault');
tbody.innerHTML = appState.vault.map(v => `
<tr>
<td><strong>${v.title}</strong></td>
<td><span class="badge badge-primary">${v.category}</span></td>
<td><a href="${v.link}" target="_blank" class="btn btn-sm btn-primary">🔗 باز کردن پوشه درایو</a></td>
<td><span class="badge badge-rose">${v.sec}</span></td>
<td>${v.desc || '-'}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editItem('vault', '${v.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteItem('vault', '${v.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
// Render Recycle Bin & Backup Table
function renderRecycleBin() {
const tbody = document.getElementById('tableBodyRecycle');
if (!appState.recycle || !appState.recycle.length) {
tbody.innerHTML = `<tr><td colspan="5" style="text-align: center; color: var(--text-muted); padding: 1.5rem;">سطل بازیافت خالی است؛ هیچ آیتم حذف‌شده‌ای وجود ندارد.</td></tr>`;
return;
}
tbody.innerHTML = appState.recycle.map((item, idx) => `
<tr>
<td><span class="badge badge-primary">${item.entityType}</span></td>
<td><strong>${item.title || item.name || 'بدون عنوان'}</strong></td>
<td>${item.deletedAt}</td>
<td style="max-width: 300px; font-size: 0.75rem; color: var(--text-muted); direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
${JSON.stringify(item.data)}
</td>
<td>
<div style="display: flex; gap: 0.4rem;">
<button class="btn btn-sm btn-success" onclick="restoreItem(${idx})">♻️ بازگردانی</button>
<button class="btn btn-sm btn-danger" onclick="permanentDeleteItem(${idx})">حذف قطعی</button>
</div>
</td>
</tr>
`).join('');
}
// CRUD Handlers
function saveItem(event, entity) {
event.preventDefault();
const idField = document.getElementById(entity.slice(0, -1) + 'Id') || document.getElementById(entity + 'Id');
const isEdit = idField && idField.value;
const itemId = isEdit ? idField.value : (entity + '_' + Date.now());
let itemObj = { id: itemId };
if (entity === 'approvals') {
itemObj.title = document.getElementById('approvalTitleInput').value;
itemObj.requester = document.getElementById('approvalRequesterInput').value;
itemObj.priority = document.getElementById('approvalPriorityInput').value;
itemObj.description = document.getElementById('approvalDescriptionInput').value;
itemObj.link = document.getElementById('approvalLinkInput').value;
itemObj.status = document.getElementById('approvalStatusInput').value;
itemObj.createdAt = new Date().toLocaleDateString('fa-IR');
closeModal('modalApproval');
} else if (entity === 'meetings') {
itemObj.title = document.getElementById('meetingTitleInput').value;
itemObj.type = document.getElementById('meetingTypeInput').value;
itemObj.time = document.getElementById('meetingTimeInput').value;
itemObj.attendees = document.getElementById('meetingAttendeesInput').value;
itemObj.buffer = document.getElementById('meetingBufferInput').value;
itemObj.link = document.getElementById('meetingLinkInput').value;
itemObj.notes = document.getElementById('meetingNotesInput').value;
closeModal('modalMeeting');
} else if (entity === 'tasks') {
itemObj.title = document.getElementById('taskTitleInput').value;
itemObj.assignee = document.getElementById('taskAssigneeInput').value;
itemObj.category = document.getElementById('taskCategoryInput').value;
itemObj.priority = document.getElementById('taskPriorityInput').value;
itemObj.deadline = document.getElementById('taskDeadlineInput').value;
itemObj.status = document.getElementById('taskStatusInput').value;
closeModal('modalTask');
} else if (entity === 'finance') {
itemObj.title = document.getElementById('financeTitleInput').value;
itemObj.bank = document.getElementById('financeBankInput').value;
itemObj.amount = document.getElementById('financeAmountInput').value;
itemObj.dueDate = document.getElementById('financeDueDateInput').value;
itemObj.notes = document.getElementById('financeNotesInput').value;
itemObj.status = document.getElementById('financeStatusInput').value;
closeModal('modalFinance');
} else if (entity === 'contacts') {
itemObj.name = document.getElementById('contactNameInput').value;
itemObj.category = document.getElementById('contactCategoryInput').value;
itemObj.role = document.getElementById('contactRoleInput').value;
itemObj.phone = document.getElementById('contactPhoneInput').value;
itemObj.social = document.getElementById('contactSocialInput').value;
itemObj.notes = document.getElementById('contactNotesInput').value;
closeModal('modalContact');
} else if (entity === 'vault') {
itemObj.title = document.getElementById('vaultTitleInput').value;
itemObj.category = document.getElementById('vaultCategoryInput').value;
itemObj.link = document.getElementById('vaultLinkInput').value;
itemObj.sec = document.getElementById('vaultSecInput').value;
itemObj.desc = document.getElementById('vaultDescInput').value;
closeModal('modalVault');
}
if (isEdit) {
const idx = appState[entity].findIndex(i => i.id === itemId);
if (idx !== -1) appState[entity][idx] = itemObj;
showToast('✏️ اطلاعات ویرایش شد و در دیتابیس همگام شد.');
} else {
appState[entity].unshift(itemObj);
showToast('✅ آیتم جدید با موفقیت ذخیره شد.');
}
triggerStateChange();
}
function editItem(entity, id) {
const item = appState[entity].find(i => i.id === id);
if (!item) return;
if (entity === 'approvals') {
document.getElementById('approvalId').value = item.id;
document.getElementById('approvalTitleInput').value = item.title;
document.getElementById('approvalRequesterInput').value = item.requester;
document.getElementById('approvalPriorityInput').value = item.priority;
document.getElementById('approvalDescriptionInput').value = item.description;
document.getElementById('approvalLinkInput').value = item.link || '';
document.getElementById('approvalStatusInput').value = item.status;
document.getElementById('modalApprovalTitle').innerText = 'ویرایش تاییدیه حامد';
openModal('modalApproval');
} else if (entity === 'meetings') {
document.getElementById('meetingId').value = item.id;
document.getElementById('meetingTitleInput').value = item.title;
document.getElementById('meetingTypeInput').value = item.type;
document.getElementById('meetingTimeInput').value = item.time;
document.getElementById('meetingAttendeesInput').value = item.attendees || '';
document.getElementById('meetingBufferInput').value = item.buffer || '';
document.getElementById('meetingLinkInput').value = item.link || '';
document.getElementById('meetingNotesInput').value = item.notes || '';
document.getElementById('modalMeetingTitle').innerText = 'ویرایش جلسه';
openModal('modalMeeting');
} else if (entity === 'tasks') {
document.getElementById('taskId').value = item.id;
document.getElementById('taskTitleInput').value = item.title;
document.getElementById('taskAssigneeInput').value = item.assignee || '';
document.getElementById('taskCategoryInput').value = item.category;
document.getElementById('taskPriorityInput').value = item.priority;
document.getElementById('taskDeadlineInput').value = item.deadline || '';
document.getElementById('taskStatusInput').value = item.status;
document.getElementById('modalTaskTitle').innerText = 'ویرایش تسک';
openModal('modalTask');
} else if (entity === 'finance') {
document.getElementById('financeId').value = item.id;
document.getElementById('financeTitleInput').value = item.title;
document.getElementById('financeBankInput').value = item.bank || '';
document.getElementById('financeAmountInput').value = item.amount;
document.getElementById('financeDueDateInput').value = item.dueDate;
document.getElementById('financeNotesInput').value = item.notes || '';
document.getElementById('financeStatusInput').value = item.status;
document.getElementById('modalFinanceTitle').innerText = 'ویرایش قسط / تسهیلات';
openModal('modalFinance');
} else if (entity === 'contacts') {
document.getElementById('contactId').value = item.id;
document.getElementById('contactNameInput').value = item.name;
document.getElementById('contactCategoryInput').value = item.category;
document.getElementById('contactRoleInput').value = item.role || '';
document.getElementById('contactPhoneInput').value = item.phone;
document.getElementById('contactSocialInput').value = item.social || '';
document.getElementById('contactNotesInput').value = item.notes || '';
document.getElementById('modalContactTitle').innerText = 'ویرایش مخاطب';
openModal('modalContact');
} else if (entity === 'vault') {
document.getElementById('vaultId').value = item.id;
document.getElementById('vaultTitleInput').value = item.title;
document.getElementById('vaultCategoryInput').value = item.category;
document.getElementById('vaultLinkInput').value = item.link;
document.getElementById('vaultSecInput').value = item.sec;
document.getElementById('vaultDescInput').value = item.desc || '';
document.getElementById('modalVaultTitle').innerText = 'ویرایش سند درایو';
openModal('modalVault');
}
}
// Soft Delete (Moves to Recycle Bin)
function deleteItem(entity, id) {
const idx = appState[entity].findIndex(i => i.id === id);
if (idx === -1) return;
const item = appState[entity][idx];
const recycleRecord = {
recycleId: 'rec_' + Date.now(),
entityType: entity,
title: item.title || item.name || 'بدون عنوان',
deletedAt: new Date().toLocaleDateString('fa-IR') + ' ' + new Date().toLocaleTimeString('fa-IR'),
data: item
};
if (!appState.recycle) appState.recycle = [];
appState.recycle.unshift(recycleRecord);
appState[entity].splice(idx, 1);
showToast('🗑️ آیتم به سطل بازیافت منتقل شد (امکان بازگردانی وجود دارد).');
triggerStateChange();
}
// Restore from Recycle Bin
function restoreItem(index) {
const rec = appState.recycle[index];
if (!rec) return;
const entity = rec.entityType;
if (!appState[entity]) appState[entity] = [];
appState[entity].unshift(rec.data);
appState.recycle.splice(index, 1);
showToast(`♻️ آیتم «${rec.title}» با موفقیت به بخش ${getTabName(entity)} بازگردانده شد.`);
triggerStateChange();
}
function permanentDeleteItem(index) {
if (confirm('آیا از حذف قطعی این رکورد اطمینان دارید؟ این عمل غیرقابل بازگشت است.')) {
appState.recycle.splice(index, 1);
showToast('حذف قطعی انجام شد.');
triggerStateChange();
}
}
// Team Intake Form Handler
function handleTeamSubmit(e) {
e.preventDefault();
const req = document.getElementById('teamRequester').value;
const title = document.getElementById('teamTitle').value;
const priority = document.getElementById('teamPriority').value;
const desc = document.getElementById('teamDescription').value;
const link = document.getElementById('teamLink').value;
const newApproval = {
id: 'team_' + Date.now(),
title: title,
requester: req,
priority: priority,
description: desc,
link: link || '',
status: 'pending',
createdAt: new Date().toLocaleDateString('fa-IR')
};
appState.approvals.unshift(newApproval);
triggerStateChange();
document.getElementById('teamIntakeForm').reset();
showToast('🚀 درخواست شما با موفقیت در کارتابل حامد ثبت شد. با تشکر!');
setTimeout(() => {
alert('درخواست شما برای تایید به میز کار حامد فلاحی اضافه شد.');
}, 200);
}
// JSON Backup & Export
function exportFullBackup() {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(appState, null, 2));
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute("href", dataStr);
downloadAnchor.setAttribute("download", `ExecCockpit_Backup_${new Date().toISOString().slice(0,10)}.json`);
document.body.appendChild(downloadAnchor);
downloadAnchor.click();
downloadAnchor.remove();
showToast('📥 فایل بکاپ کامل JSON دانلود شد.');
}
function restoreFromBackupFile() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = readerEvent => {
try {
const content = JSON.parse(readerEvent.target.result);
if (content.approvals && content.meetings) {
appState = content;
triggerStateChange();
showToast('✅ بازگردانی از فایل پشتیبان با موفقیت انجام شد.');
} else {
alert('فایل نامعتبر است.');
}
} catch (err) {
alert('خطا در خواندن فایل بکاپ JSON.');
}
}
}
input.click();
}
// Client-side quick filter
function filterData(entity, query) {
const q = query.trim().toLowerCase();
const rows = document.querySelectorAll(`#tableBody${capitalize(entity)} tr`);
rows.forEach(r => {
const text = r.innerText.toLowerCase();
r.style.display = text.includes(q) ? '' : 'none';
});
}
// Initialize
window.addEventListener('DOMContentLoaded', () => {
loadFromPostgres();
});
</script>
</body>
</html>