سامانه صدور فاکتور و حسابداری
Phase 1: add module navigation and command search
davoodmehraban89 committed
Sep 28, 2026 at 17:29 UTC
031e8e3fe0d4e10f725b5d56f745692e882d6a5f
1 file changed
+72
-1
js/ui.js
+72
-1
@@ -5,7 +5,7 @@ function switchView(viewId){
5
document.querySelectorAll('.nav-link').forEach(btn=>btn.classList.toggle('active',btn.getAttribute('data-view')===viewId));
6
document.querySelectorAll('.dock-tab').forEach(dock=>dock.classList.toggle('active',dock.dataset.view===viewId));
7
if(viewId==='view-admin')renderAdminPanel();
8
- if(viewId==='view-reports')renderFinancialReports();
8
+ if(viewId==='view-reports')renderFinancialReports();\n if(typeof syncShellForView==='function')syncShellForView(viewId);
9
window.scrollTo({top:0,behavior:'smooth'});
10
}
11
function toggleAccordion(headerEl){headerEl.parentElement.classList.toggle('open');}
@@ -54,3 +54,74 @@ function applyEntityTypeToForm(entity,opts){
54
}
55
function handleContactEntityChange(){const el=document.getElementById('contact-entity-type');if(!el)return;applyEntityTypeToForm(el.value,{prefixId:'box-contact-prefix',nameId:'box-contact-name',econId:'box-contact-economic',regId:'box-contact-reg',nationalLabelId:'label-contact-national'});}
56
function handleQuickCEntityChange(){const el=document.getElementById('quick-c-entity');if(!el)return;applyEntityTypeToForm(el.value,{prefixId:'box-quick-c-prefix',nameId:'box-quick-c-name',econId:'box-quick-c-economic',regId:'box-quick-c-reg',nationalLabelId:'label-quick-c-national'});}
57
+
58
+
59
+/* Phase 1 scalable navigation shell */
60
+const FINORA_MODULES={
61
+ home:{title:'خانه',groups:[{title:'نمای کلی',items:[['داشبورد','view-dashboard','⌂'],['گزارشهای مالی','view-reports','▥']]}]},
62
+ sales:{title:'فروش',groups:[{title:'عملیات فروش',items:[['فاکتور فروش و اسناد','view-invoices','▤'],['اشخاص / مشتریان','view-contacts','◎']]},{title:'داده پایه',items:[['کالا و خدمات','view-products','◇']]}]},
63
+ purchases:{title:'خرید',groups:[{title:'عملیات خرید',items:[['فاکتورهای خرید','view-purchases','▣'],['اشخاص / تأمینکنندگان','view-contacts','◎']]},{title:'کنترل',items:[['هزینهها و درآمد','view-expenses','◌']]}]},
64
+ treasury:{title:'خزانهداری',groups:[{title:'عملیات روزانه',items:[['دریافت و پرداخت','view-payments','↔'],['چکها و صیاد','view-cheques','◈']]},{title:'مرتبط',items:[['هزینهها و درآمد','view-expenses','◌']]}]},
65
+ people:{title:'اشخاص',groups:[{title:'مدیریت اشخاص',items:[['طرفحسابها','view-contacts','◎']]},{title:'تحلیل',items:[['گزارشهای مالی','view-reports','▥']]}]},
66
+ catalog:{title:'کالا و خدمات',groups:[{title:'داده پایه',items:[['کالاها و خدمات','view-products','◇']]},{title:'گردش',items:[['فروش','view-invoices','▤'],['خرید','view-purchases','▣']]}]},
67
+ reports:{title:'گزارشها',groups:[{title:'گزارشهای موجود',items:[['گزارشهای مالی','view-reports','▥'],['داشبورد تحلیلی','view-dashboard','⌂']]}]},
68
+ settings:{title:'تنظیمات',groups:[{title:'مدیریت',items:[['تنظیمات و شرکتها','view-settings','⚙'],['مدیریت کاربران و لایسنس','view-admin','♙','admin']]}]}
69
+};
70
+const FINORA_COMMANDS=Object.entries(FINORA_MODULES).flatMap(([module,m])=>m.groups.flatMap(g=>g.items.map(i=>({module,moduleTitle:m.title,title:i[0],view:i[1],icon:i[2],guard:i[3]||''}))));
71
+
72
+function canShowShellCommand(cmd){
73
+ if(cmd.guard==='admin'){
74
+ const el=document.getElementById('menu-admin-panel');
75
+ return !!el&&el.style.display!=='none';
76
+ }
77
+ return true;
78
+}
79
+function renderModulePanel(moduleKey,activeView){
80
+ const m=FINORA_MODULES[moduleKey]||FINORA_MODULES.home;
81
+ const title=document.getElementById('module-panel-title'),box=document.getElementById('module-panel-links');
82
+ if(title)title.textContent=m.title;
83
+ if(!box)return;
84
+ box.innerHTML=m.groups.map(g=>'<div class="module-group"><div class="module-group-title">'+g.title+'</div>'+g.items.filter(i=>canShowShellCommand({guard:i[3]||''})).map(i=>'<button class="module-link '+(i[1]===activeView?'active':'')+'" data-view="'+i[1]+'" onclick="navigateShell(\''+moduleKey+'\',\''+i[1]+'\')"><span class="mi">'+i[2]+'</span><span>'+i[0]+'</span></button>').join('')+'</div>').join('');
85
+}
86
+function openModule(moduleKey,defaultView){
87
+ document.querySelectorAll('.module-tab').forEach(x=>x.classList.toggle('active',x.dataset.module===moduleKey));
88
+ renderModulePanel(moduleKey,defaultView);
89
+ if(defaultView)navigateShell(moduleKey,defaultView,false);
90
+}
91
+function navigateShell(moduleKey,viewId,rerender=true){
92
+ switchView(viewId);
93
+ if(viewId==='view-payments'&&typeof renderPayments==='function')renderPayments();
94
+ if(rerender)renderModulePanel(moduleKey,viewId);
95
+ document.querySelectorAll('.module-tab').forEach(x=>x.classList.toggle('active',x.dataset.module===moduleKey));
96
+ closeCommandSearch();
97
+}
98
+function toggleModulePanel(){
99
+ document.body.classList.toggle('shell-panel-collapsed');
100
+ const p=document.getElementById('module-panel');if(p)p.classList.toggle('collapsed',document.body.classList.contains('shell-panel-collapsed'));
101
+}
102
+function renderCommandSearch(query){
103
+ const box=document.getElementById('command-search-results');if(!box)return;
104
+ const q=(query||'').trim().toLowerCase();
105
+ if(!q){closeCommandSearch();return;}
106
+ const matches=FINORA_COMMANDS.filter(canShowShellCommand).filter(x=>(x.title+' '+x.moduleTitle).toLowerCase().includes(q)).slice(0,8);
107
+ box.innerHTML=matches.length?matches.map((x,n)=>'<div class="command-result" data-index="'+n+'" onclick="navigateShell(\''+x.module+'\',\''+x.view+'\')">'+x.icon+' '+x.title+' <small>'+x.moduleTitle+'</small></div>').join(''):'<div class="command-result">نتیجهای در منو پیدا نشد</div>';
108
+ box.classList.add('open');
109
+}
110
+function handleCommandSearchKey(e){
111
+ if(e.key==='Escape'){closeCommandSearch();e.currentTarget.blur();return;}
112
+ if(e.key==='Enter'){
113
+ const q=(e.currentTarget.value||'').trim().toLowerCase();
114
+ const x=FINORA_COMMANDS.filter(canShowShellCommand).find(x=>(x.title+' '+x.moduleTitle).toLowerCase().includes(q));
115
+ if(x){e.preventDefault();navigateShell(x.module,x.view);}
116
+ }
117
+}
118
+function closeCommandSearch(){const b=document.getElementById('command-search-results');if(b)b.classList.remove('open');}
119
+function syncShellForView(viewId){
120
+ const cmd=FINORA_COMMANDS.find(x=>x.view===viewId&&canShowShellCommand(x));
121
+ if(!cmd)return;
122
+ document.querySelectorAll('.module-tab').forEach(x=>x.classList.toggle('active',x.dataset.module===cmd.module));
123
+ renderModulePanel(cmd.module,viewId);
124
+}
125
+document.addEventListener('click',e=>{if(!e.target.closest('.global-search'))closeCommandSearch();});
126
+document.addEventListener('keydown',e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='k'){e.preventDefault();const s=document.getElementById('global-command-search');if(s){s.focus();s.select();}}});
127
+document.addEventListener('DOMContentLoaded',()=>renderModulePanel('home','view-dashboard'));