سامانه صدور فاکتور و حسابداری
fix(settings): await cloud persistence and rehydrate keyboard preferences on refresh
davoodmehraban89 committed
Oct 14, 2026 at 13:23 UTC
bcb27b106849f3c514ddefac9f71203151775cb8
1 file changed
+14
-3
js/ux-hardening-r2.js
+14
-3
@@ -216,8 +216,16 @@ body.finora-theme-dark .form-group[style*="background"]{
216
function ensureThemeCss(){if($('finora-theme-r2-css'))return;const s=document.createElement('style');s.id='finora-theme-r2-css';s.textContent=THEME_CSS;document.head.appendChild(s)}
217
function resolveTheme(mode){if(mode==='dark'||mode==='light')return mode;const h=new Date().getHours();return h>=7&&h<19?'light':'dark'}
218
window.finoraApplyTheme=function(){ensureThemeCss();const mode=getMySettings()?.ui_theme||'auto',r=resolveTheme(mode);document.body.classList.toggle('finora-theme-dark',r==='dark');document.documentElement.dataset.finoraTheme=r}
219
- function saveExperience(){
220
- if(!requireWrite())return;const s=getMySettings();s.ui_theme=$('finora-theme-select').value;s.hotkey_ctrl_s=$('finora-hotkey-ctrls').checked;s.hotkey_ctrl_enter=$('finora-hotkey-ctrlenter').checked;s.hotkey_enter_save=$('finora-hotkey-enter').checked;s.hotkey_quick_zeros=$('finora-hotkey-zeros').checked;saveDatastore();finoraApplyTheme();alert('تنظیمات تجربه کاربری ذخیره شد.');
219
+ async function saveExperience(){
220
+ if(!requireWrite())return false;
221
+ const s=getMySettings();s.ui_theme=$('finora-theme-select').value;s.hotkey_ctrl_s=$('finora-hotkey-ctrls').checked;s.hotkey_ctrl_enter=$('finora-hotkey-ctrlenter').checked;s.hotkey_enter_save=$('finora-hotkey-enter').checked;s.hotkey_quick_zeros=$('finora-hotkey-zeros').checked;
222
+ if(!saveDatastore())return false;
223
+ // The queued autosync is not proof of persistence. Wait for server acknowledgement.
224
+ clearTimeout(syncTimer);
225
+ if(syncRunning){alert('ذخیره قبلی هنوز در جریان است؛ پس از پایان همگامسازی دوباره ذخیره کنید.');scheduleSync(300);return false;}
226
+ await runSync();
227
+ if(syncPending||syncFailCount>0||computeDiff().up.length||computeDiff().del.length){alert('تنظیمات روی سرور تأیید نشد. پس از بررسی اتصال دوباره ذخیره کنید.');return false;}
228
+ finoraApplyTheme();alert('تنظیمات روی سرور ذخیره شد.');return true;
229
}
230
window.finoraSaveExperienceSettings=saveExperience;
231
function activeSave(){
@@ -341,7 +349,10 @@ body.finora-theme-dark .form-group[style*="background"]{
349
function statsHtml(){const stats=[['کالا/خدمت',ownedRows('products').length],['اشخاص',ownedRows('contacts').length],['فاکتور فروش',ownedRows('invoices').length],['فاکتور خرید',ownedRows('purchases').length],['چک',ownedRows('cheques').length],['حساب',ownedRows('accounts').length],['پروژه',ownedRows('projects').length],['اسناد حسابداری',ownedRows('journalVouchers').length]];return '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:8px">'+stats.map(x=>'<div style="border:1px solid var(--border);border-radius:10px;padding:12px"><small>'+x[0]+'</small><div style="font-size:22px;font-weight:800">'+Number(x[1]).toLocaleString('fa-IR')+'</div></div>').join('')+'</div>'}
350
window.finoraRefreshDataStats=function(){const h=$('finora-data-stats');if(h)h.innerHTML=statsHtml()}
351
function installSettings(){
344
- const root=$('view-settings');if(!root||$('finora-experience-card'))return;try{if(typeof FINORA_MODULES!=='undefined'&&!FINORA_MODULES.settings.groups.some(g=>g.title==='تجربه کاربری'))FINORA_MODULES.settings.groups.splice(2,0,{title:'تجربه کاربری',items:[['ظاهر و میانبرها','view-settings','⌨','','experience'],['قالبهای Excel','view-settings','▦','','excel-templates'],['آمار دادهها','view-settings','◎','','data-stats']]})}catch(_){}
352
+ const root=$('view-settings');
353
+ // Rebind controls after a cloud refresh; the settings card is persistent in the DOM.
354
+ if(root&&$('finora-experience-card')){const prefs=getMySettings();const set=(id,value,checked=false)=>{const el=$(id);if(el)el[checked?'checked':'value']=value};set('finora-theme-select',prefs.ui_theme||'auto');set('finora-hotkey-ctrls',prefs.hotkey_ctrl_s!==false,true);set('finora-hotkey-ctrlenter',prefs.hotkey_ctrl_enter!==false,true);set('finora-hotkey-enter',!!prefs.hotkey_enter_save,true);set('finora-hotkey-zeros',!!prefs.hotkey_quick_zeros,true);return;}
355
+if(!root||$('finora-experience-card'))return;try{if(typeof FINORA_MODULES!=='undefined'&&!FINORA_MODULES.settings.groups.some(g=>g.title==='تجربه کاربری'))FINORA_MODULES.settings.groups.splice(2,0,{title:'تجربه کاربری',items:[['ظاهر و میانبرها','view-settings','⌨','','experience'],['قالبهای Excel','view-settings','▦','','excel-templates'],['آمار دادهها','view-settings','◎','','data-stats']]})}catch(_){}
356
const s=getMySettings(),exp=document.createElement('div');exp.id='finora-experience-card';exp.className='accordion-item open';exp.dataset.finoraTask='experience';exp.innerHTML='<div class="accordion-header" onclick="toggleAccordion(this)"><span>⌨ ظاهر و میانبرهای صفحهکلید</span><span>▼</span></div><div class="accordion-body"><div class="form-row"><div class="form-group"><label>تم ظاهری</label><select id="finora-theme-select" class="form-control"><option value="auto">خودکار (روز روشن / شب تاریک)</option><option value="light">روشن</option><option value="dark">تاریک</option></select></div></div><label><input type="checkbox" id="finora-hotkey-ctrls"> Ctrl+S برای ذخیره</label><br><label><input type="checkbox" id="finora-hotkey-ctrlenter"> Ctrl+Enter برای ذخیره</label><br><strong>F2 برای ذخیره یا تأیید فرم فعال</strong> (بدون قطعیکردن خودکار اسناد مالی)<br><label><input type="checkbox" id="finora-hotkey-enter"> Enter برای ذخیره فرم فعال</label><br><label><input type="checkbox" id="finora-hotkey-zeros"> + افزودن سه صفر و − افزودن دو صفر در فیلد مبلغ</label><p class="af-hint">Escape همیشه پنجره باز را میبندد. میانبرهای عددی فقط داخل فیلدهای مبلغ عمل میکنند.</p><button class="btn btn-primary" onclick="finoraSaveExperienceSettings()">ذخیره تنظیمات</button></div>';root.insertBefore(exp,root.firstElementChild?.nextSibling||null);
357
$('finora-theme-select').value=s.ui_theme||'auto';$('finora-hotkey-ctrls').checked=s.hotkey_ctrl_s!==false;$('finora-hotkey-ctrlenter').checked=s.hotkey_ctrl_enter!==false;$('finora-hotkey-enter').checked=!!s.hotkey_enter_save;$('finora-hotkey-zeros').checked=!!s.hotkey_quick_zeros;
358
const ex=document.createElement('div');ex.className='accordion-item';ex.dataset.finoraTask='excel-templates';ex.innerHTML='<div class="accordion-header" onclick="toggleAccordion(this)"><span>▦ قالبهای Excel و فیلدهای قابل انتخاب</span><span>▼</span></div><div class="accordion-body"><div class="form-group"><label>نوع قالب</label><select id="finora-excel-type" class="form-control" onchange="finoraRenderExcelFields()"><option value="products">کالا و خدمات</option><option value="contacts">اشخاص</option><option value="accounts">کدینگ حسابها</option><option value="saleItems">اقلام فاکتور فروش</option><option value="purchaseItems">اقلام فاکتور خرید</option></select></div><div id="finora-excel-fields"></div><div style="display:flex;gap:8px;flex-wrap:wrap"><button class="btn btn-primary" onclick="finoraSaveExcelFields()">ذخیره فیلدها</button><button class="btn btn-secondary" onclick="finoraDownloadConfiguredTemplate(document.getElementById(\'finora-excel-type\').value)">دانلود قالب نمونه</button><button class="btn btn-secondary" onclick="finoraExportConfiguredData(document.getElementById(\'finora-excel-type\').value)">خروجی دادههای فعلی</button></div></div>';root.appendChild(ex);renderExcelFields();