فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

feat/a08-synthetic-performance-baseline
a02/strict-export-preflight-20261018 audit/a01-readonly-invoice-metadata-20261101 ci/a06-require-trusted-issuer-for-release ci/main-postmerge-phase-a-validation-20261020 ci/phase-a-controlled-public-release design/issue-5-commercial-corrections-adr docs/a01-a02-a05-oct23-verified-evidence docs/a01-cheque-endorsement-evidence-20261022 docs/a01-cheque-event-date-evidence-20261021 docs/a01-explicit-refund-reason-evidence-20261021 docs/a01-refund-auth-status-20261020 docs/a01-refund-trace-evidence-20261020 docs/a02-102-evidence-20261018 docs/a02-pr104-evidence-20261018 docs/a02-pr106-evidence-20261019 docs/a02-pr108-ten-tests-20261019 docs/a02-private-sql-backup-evidence-20261111 docs/a03-merge-status-sync-20261020 docs/a04-software-gate-acceptance-20261020 docs/feature-matrix-20261014 docs/finora-master-execution-playbook docs/four-phase-execution-20261014 docs/four-phase-roadmap-20261014 docs/holoo-lab-stabilization-phase1-20261111 docs/holoo-runtime-schema-audit-20261111 docs/ops-142-governance-5-1-3-20261030 docs/phase-a-a01-a02-a06-a08-verified-evidence-20261023 docs/phase-a-a01-a05-a06-evidence-20261023 docs/phase-a-independent-acceptance-evidence docs/phase-a-pr110-evidence-20261019 docs/project-status-phase-a-20261014 feat/a01-referenced-return-corrections feat/a01-referenced-returns-on-main feat/a02-atomic-opening-ledger-preflight feat/a02-holoo-compatibility-preflight feat/a02-holoo-declared-control-totals feat/a02-holoo-explicit-csv-gate feat/a02-holoo-safe-zip-intake-offline-webview2-20261030 feat/a02-offline-sql-server-provisioning-20261030 feat/a02-opening-balance-dry-run feat/a02-opening-ledger-admin-ui feat/a02-opt-in-isolated-sql-restore-executor-20261030 feat/a02-private-holoo-zip-staging-20261030 feat/a02-safe-isolated-restore-plan-20261030 feat/a02-sql-backup-header-verifyonly-20261030 feat/a03-audit-schema-atomic-events feat/a03-complete-manual-journal-audit feat/a05-cheque-treasury-reconciliation feat/a06-signed-offline-license-activation feat/a08-synthetic-performance-baseline feat/phase-a-accounting-benchmark-return-preview feat/phase-a-ledger-settlement-diagnostics feature/v2-reconciliation-20261013 fix/a01-atomic-confirm-ui-one-shot-20261031 fix/a01-cheque-clearance-explicit-account-20261023 fix/a01-cheque-contractual-due-date-validity-20261023 fix/a01-cheque-endorsement-counterparty-20261022 fix/a01-cheque-event-date-open-period-20261021 fix/a01-cumulative-return-amount-cap fix/a01-explicit-refund-reason-approval-20261021 fix/a01-manager-authorized-customer-refunds-20261020 fix/a01-no-implicit-refund fix/a01-one-shot-confirm-on-atomic-import-20261031 fix/a01-refund-and-overcollection-net-cash fix/a01-refund-correction-trace-20261020 fix/a02-atomic-excel-master-merge-20261031 fix/a02-canonical-mapping-contract-20261018 fix/a02-disable-destructive-excel-replace-20261031 fix/a02-holoo-invoice-line-coverage-20261023 fix/a02-holoo-preflight-required-invoice-lines-20261023 fix/a02-mapping-contract-20261018 fix/a02-opening-preflight-unbalanced-report fix/a02-orphan-mapping-20261018 fix/a02-private-excel-import-session-20261031 fix/a02-strict-export-input-20261019 fix/a03-append-only-full-backup-import fix/a03-append-only-write-guard fix/a03-block-transaction-clear-append-only-20261016 fix/a03-chain-validation-20261020 fix/a03-company-scoped-audit-data-access fix/a03-deny-direct-audit-write-20261019 fix/a03-escaped-expense-list-20261031 fix/a03-escaped-financial-record-ids-20261031 fix/a03-financial-ledger-actions-and-print-20261031 fix/a04-backup-checksum-preflight fix/a04-company-audit-replay-stable-compare fix/a04-company-backup-source-isolation-20261020 fix/a04-full-restore-posted-financial-integrity fix/a04-reject-mixed-company-backup-20261019 fix/a04-replace-immutable-posted-ledger fix/a04-restore-financial-journal-references fix/a04-service-source-company-boundary-20261020 fix/a05-block-inactive-treasury-settlements fix/a05-cheque-cash-evidence-reconciliation-20261023 fix/a05-cheque-ledger-and-bank-reconciliation-20261023 fix/a05-fiscal-close-invariant-gates fix/a06-backup-restore-user-privileges fix/a06-license-user-company-quota-20261023 fix/a06-malformed-trial-state-fail-closed fix/a06-offline-clock-fail-closed-20261019 fix/a07-indexeddb-blocked-startup fix/a07-offline-bundled-assets fix/a07-version-and-startup-banner fix/issue-7-company-backup-isolation fix/p0-deterministic-fractional-invoice-money-20261031 fix/p0-fractional-quantity-input-20261031 fix/p0-fractional-quantity-integrated-20261031 fix/p0-invoice-posting-invariants-20261031 fix/p0-legacy-stock-and-product-inputs-20261031 fix/p0-reports-immutable-cogs-20261101 fix/p0-verified-financial-percent-20261031 fix/p0-zero-discount-report-revenue-20261101 fix/phase-a-backup-app-version fix/phase-a-backup-integrity-checksum fix/phase-a-backup-record-id-validation-20261014 fix/phase-a-backup-version-validation-20261014 fix/phase-a-closure-pack3-20261101 fix/phase-a-entitlement-payload-validation fix/phase-a-gate-exact-evidence-20261019 fix/phase-a-pack4-stock-scope-20261101 fix/phase-a-pack5-integrated-evidence-20261101 fix/phase-a-pack6-atomic-legacy-20261101 fix/phase-a-restore-envelope-and-rollback fix/phase-a-settings-admin-gate fix/print-browser-header-footer-20261014 fix/q01-expense-security-probe-exact-option-20261031 fix/q01-financial-grid-labels-20261031 fix/q01-form-label-association-20261031 fix/q01-native-evidence-integrity-20261030 fix/q01-number-input-persian-decimal-20261031 fix/q01-responsive-dashboard-and-cheque-table-20261031 fix/q01-safe-ui-action-audit-coverage-20261031 fix/q01-visible-desktop-sidebar-and-safe-confirm-20261030 fix/roadmap-metadata-sync-20261014 gate/a03-audit-metadata-validation-20261019 integration/a02-windows-holoo-setup-candidate-20261030 license-server main perf/a07-lazy-load-excel perf/a08-cheque-reconciliation-account-index-20261023 perf/a08-paginated-reports-20261101 phase1-restore-hardening planning/holoo-execution-20261013 planning/roadmap-project-management-20261014 qa/native-click-coverage-audit-20261030 release/v2.0.0 test/a01-native-endorsement-mandatory-20261023 test/a01-native-purchase-return-guardrails test/a01-native-sale-return-financial-guardrails test/a01-safe-integer-boundary-20261019 test/a02-native-opening-dry-run-rejections test/a02-native-positive-opening-ledger test/a04-native-corrupt-fbackup-20261016 test/a04-native-encrypted-company-backup test/a04-native-encrypted-company-backup-main test/a04-native-late-transaction-rollback test/a04-native-windows-backup-recovery test/a04-real-edge-v6-v7-migration test/a04-real-native-interrupted-restore test/a05-native-draft-ledger-and-repeat-close-20261016 test/a05-native-fiscal-close-guardrails test/a07-native-multipage-print-engine test/a07-native-origin-provenance test/a07-native-webview2-offline-routes test/a07-windows-offline-startup-smoke test/a08-installed-webview2-60k-baseline test/a08-native-webview2-heap-metrics test/a08-windows-synthetic-performance-baseline test/github-write-access-20261009 test/native-win-ui-routes-after-finance-backup test/phase-a-combined-a01-a05-a08-final-evidence test/phase-a-combined-native-acceptance-matrix test/phase-a-ledger-invariants-20261014 test/phase-a-native-all-routes-on-merged-lab test/phase-a-native-encrypted-backup test/phase-a-native-finance-backup-matrix test/phase-a-native-ui-and-backup-smoke test/phase-a-windows-native-installer-lab work/a08-dispatch-activation-20261123 work/a08-memory-stability-20261123 work/finance-curated-20261123
js 871 lines 40.7 KB
Raw
1 // ============================================================
2 // SettingsView — صفحه‌ی تنظیمات، بکاپ، شرکت و Excel
3 // ============================================================
4
5 import { SettingsController } from '../controllers/SettingsController.js';
6 import { StorageService } from '../core/StorageService.js';
7 import { Theme } from '../core/Theme.js';
8 import { KeyboardShortcuts } from '../core/KeyboardShortcuts.js';
9 import { Modal } from '../core/Modal.js';
10 import { Toast } from '../core/Toast.js';
11 import { Formatters } from '../utils/Formatters.js';
12 import { Auth } from '../core/Auth.js';
13 import { ExcelController } from '../controllers/ExcelController.js';
14 import { inspectSettlementConsistency } from '../core/FinancialDiagnosticsService.js';
15
16 let cache = { company: {}, stats: {}, invoiceSettings: { numberingMode: 'auto', nextNumber: 1 } };
17
18 class SettingsViewImpl {
19 async render() {
20 await this.reload();
21 return `
22 <div class="page-title">
23 <h2>تنظیمات</h2>
24 <p>مدیریت اطلاعات شرکت، پشتیبان‌گیری، Excel و تنظیمات سیستم</p>
25 </div>
26
27 <div class="settings-grid">
28 ${this._renderCompanyCard()}
29 ${this._renderInvoiceSettingsCard()}
30 ${this._renderExcelCard()}
31 ${this._renderShortcutsCard()}
32 ${this._renderBackupCard()}
33 ${this._renderStatsCard()}
34 ${Auth.isAdmin() ? this._renderHealthCard() : ''}
35 ${this._renderThemeCard()}
36 ${this._renderAboutCard()}
37 </div>
38 `;
39 }
40
41 onMount() {
42 window.SettingsView = this;
43 }
44
45 async reload() {
46 const results = await Promise.allSettled([
47 SettingsController.getCompanyInfo(),
48 SettingsController.getInvoiceSettings(),
49 this._collectStats()
50 ]);
51 const defaults = [{}, { numberingMode: 'auto', nextNumber: 1 }, {}];
52 const values = results.map((result, index) => {
53 if (result.status === 'fulfilled') return result.value;
54 console.error('Settings load failed:', index, result.reason);
55 Toast.error('بخشی از تنظیمات بارگذاری نشد: ' + (result.reason?.message || 'خطای نامشخص'));
56 return defaults[index];
57 });
58 [cache.company, cache.invoiceSettings, cache.stats] = values;
59 }
60
61 async _collectStats() {
62 const user = Auth.current();
63 if (!user) return {};
64 const stores = ['products', 'contacts', 'invoices', 'cheques', 'treasury'];
65 const stats = {};
66 for (const s of stores) {
67 try {
68 const list = await StorageService.getByOwner(s, user.id);
69 if (s === 'treasury') {
70 stats.accounts = list.filter(x => x.recordType === 'account').length;
71 stats.transactions = list.filter(x => x.recordType === 'transaction').length;
72 } else {
73 stats[s] = list.length;
74 }
75 } catch (e) {
76 stats[s] = 0;
77 }
78 }
79 return stats;
80 }
81
82 // ============================================================
83 // کارت اطلاعات شرکت
84 // ============================================================
85 _renderCompanyCard() {
86 const c = cache.company;
87 return `
88 <div class="card settings-card">
89 <div class="settings-card-header">
90 <div class="settings-card-icon">🏢</div>
91 <div>
92 <h3 class="settings-card-title">اطلاعات شرکت / فروشگاه</h3>
93 <p class="settings-card-desc">این اطلاعات در سربرگ فاکتورهای چاپی نمایش داده می‌شود</p>
94 </div>
95 </div>
96 ${c.name ? `
97 <div class="company-preview">
98 <div style="font-weight:700;font-size:14px">${this._esc(c.name)}</div>
99 ${c.nationalId ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:3px">شناسه ملی: ${Formatters.toPersianDigits(c.nationalId)}</div>` : ''}
100 ${c.address ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:2px">${this._esc(c.address)}</div>` : ''}
101 ${c.phone ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:2px">تلفن: ${Formatters.phone(c.phone)}</div>` : ''}
102 </div>
103 ` : `
104 <div class="empty-mini">هنوز اطلاعاتی وارد نشده</div>
105 `}
106 <div style="display:flex;gap:8px;flex-wrap:wrap">
107 <button class="btn" onclick="window.SettingsView.openCompanyModal()">${c.name ? '✏️ ویرایش اطلاعات' : '➕ وارد کردن اطلاعات'}</button>
108 <button class="btn" onclick="window.SettingsView.openCompanySwitcher()">🔄 تغییر شرکت</button>
109 ${Auth.isAdmin() ? '<button class="btn" onclick="window.SettingsView.createCompany()">➕ شرکت جدید</button>' : ''}
110 </div>
111 </div>
112 `;
113 }
114
115 _renderInvoiceSettingsCard() {
116 const s = cache.invoiceSettings || { numberingMode: 'auto', nextNumber: 1 };
117 return `
118 <div class="card settings-card">
119 <div class="settings-card-header">
120 <div class="settings-card-icon">🧾</div>
121 <div>
122 <h3 class="settings-card-title">تنظیمات فاکتور</h3>
123 <p class="settings-card-desc">نحوه شماره‌گذاری فاکتورهای جدید</p>
124 </div>
125 </div>
126 <div class="form-group">
127 <label class="form-label">نحوه شماره‌گذاری</label>
128 <select class="form-control" id="invoiceNumberingMode">
129 <option value="auto" ${s.numberingMode === 'auto' ? 'selected' : ''}>خودکار</option>
130 <option value="manual" ${s.numberingMode === 'manual' ? 'selected' : ''}>دستی</option>
131 </select>
132 </div>
133 <div class="form-group">
134 <label class="form-label">شماره بعدی فاکتور</label>
135 <input class="form-control" id="invoiceNextNumber" type="number" min="1" value="${Number(s.nextNumber) || 1}" />
136 </div>
137 <button class="btn" onclick="window.SettingsView.saveInvoiceSettings()">💾 ذخیره تنظیمات فاکتور</button>
138 </div>
139 `;
140 }
141
142 async saveInvoiceSettings() {
143 const numberingMode = document.getElementById('invoiceNumberingMode').value;
144 const nextNumber = Number(document.getElementById('invoiceNextNumber').value);
145 if (!Number.isInteger(nextNumber) || nextNumber < 1) {
146 Toast.warning('شماره بعدی باید عدد صحیح بزرگ‌تر از صفر باشد');
147 return;
148 }
149 try {
150 cache.invoiceSettings = await SettingsController.saveInvoiceSettings({ numberingMode, nextNumber });
151 Toast.success('تنظیمات فاکتور ذخیره شد');
152 } catch (err) {
153 console.error('Invoice settings save failed:', err);
154 Toast.error('خطا در ذخیره تنظیمات فاکتور: ' + err.message);
155 }
156 }
157
158 // ============================================================
159 // کارت Excel (جدید)
160 // ============================================================
161 _renderExcelCard() {
162 const s = cache.stats;
163 return `
164 <div class="card settings-card" style="border-color:#bbf7d0;background:linear-gradient(135deg,#f0fdf4,#f8fafc)">
165 <div class="settings-card-header">
166 <div class="settings-card-icon" style="background:linear-gradient(135deg,#16a34a,#15803d)">📊</div>
167 <div>
168 <h3 class="settings-card-title">Excel — خروجی و ورودی</h3>
169 <p class="settings-card-desc">داده‌ها را به Excel ببر یا از Excel بیار</p>
170 </div>
171 </div>
172
173 <div style="font-size:12.5px;color:var(--text-muted);line-height:1.8;margin-bottom:12px;padding:10px 12px;background:rgba(255,255,255,.6);border-radius:8px">
174 <strong>💡 نکته:</strong> از این بخش می‌تونی کل داده‌ها رو در یه فایل Excel بگیری، یا از یه فایل Excel (که قبلاً آماده کردی) کالا و اشخاص اضافه کنی.
175 </div>
176
177 <div style="display:flex;gap:10px;flex-wrap:wrap;margin-bottom:12px">
178 <button class="btn" style="background:linear-gradient(135deg,#16a34a,#15803d)" onclick="window.SettingsView.exportAllExcel()">
179 📥 خروجی کامل (Excel)
180 </button>
181 <button class="btn btn-secondary" onclick="window.SettingsView.openExportSectionModal()">
182 🎯 خروجی انتخابی
183 </button>
184 </div>
185
186 <div style="margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)">
187 <div style="font-size:12.5px;font-weight:700;margin-bottom:10px;color:#166534">📤 ورود از Excel</div>
188 <div style="display:flex;gap:10px;flex-wrap:wrap">
189 <button class="btn btn-secondary" onclick="window.SettingsView.importProductsExcel()">
190 📦 ورود کالاها
191 </button>
192 <button class="btn btn-secondary" onclick="window.SettingsView.importContactsExcel()">
193 👥 ورود اشخاص
194 </button>
195 </div>
196 </div>
197
198 <div style="margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)">
199 <div style="font-size:12.5px;font-weight:700;margin-bottom:10px;color:#166534">📄 قالب‌های نمونه</div>
200 <div style="display:flex;gap:10px;flex-wrap:wrap">
201 <button class="btn btn-secondary btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.downloadProductsTemplate()">
202 📋 قالب کالاها
203 </button>
204 <button class="btn btn-secondary btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.downloadContactsTemplate()">
205 📋 قالب اشخاص
206 </button>
207 </div>
208 </div>
209 </div>
210 `;
211 }
212
213 async exportAllExcel() {
214 try {
215 Toast.info('در حال آماده‌سازی فایل Excel...');
216 const result = await ExcelController.exportAll();
217 Toast.success(`فایل Excel با ${Formatters.toPersianDigits(result.sheets)} شیت دانلود شد`);
218 } catch (err) {
219 console.error(err);
220 Toast.error('خطا در خروجی: ' + err.message);
221 }
222 }
223
224 openExportSectionModal() {
225 const body = `
226 <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">کدوم بخش رو می‌خوای به Excel ببری؟</p>
227 <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
228 <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('products')">
229 <div style="font-size:22px">📦</div>
230 <div style="font-size:12.5px">کالاها</div>
231 </button>
232 <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('contacts')">
233 <div style="font-size:22px">👥</div>
234 <div style="font-size:12.5px">اشخاص</div>
235 </button>
236 <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('invoices')">
237 <div style="font-size:22px">🧾</div>
238 <div style="font-size:12.5px">فاکتورها</div>
239 </button>
240 <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('cheques')">
241 <div style="font-size:22px">💳</div>
242 <div style="font-size:12.5px">چک‌ها</div>
243 </button>
244 <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('expenses')">
245 <div style="font-size:22px">💰</div>
246 <div style="font-size:12.5px">هزینه و درآمد</div>
247 </button>
248 </div>
249 `;
250 const footer = `<button class="btn btn-secondary" onclick="FINORA.Modal.close()">بستن</button>`;
251 Modal.open({ title: '🎯 خروجی انتخابی به Excel', body, footer, size: 'md' });
252 }
253
254 async _exportSection(section) {
255 try {
256 const result = await ExcelController.exportSection(section);
257 Toast.success(`فایل دانلود شد (${Formatters.number(result.count)} مورد)`);
258 Modal.close();
259 } catch (err) {
260 Toast.error('خطا: ' + err.message);
261 }
262 }
263
264 // ============================================================
265 // ورودی از Excel
266 // ============================================================
267 importProductsExcel() {
268 const input = document.createElement('input');
269 input.type = 'file';
270 input.accept = '.xlsx,.xls';
271 input.onchange = async (e) => {
272 const file = e.target.files[0];
273 if (!file) return;
274 await this._handleImportFile(file, 'products');
275 };
276 input.click();
277 }
278
279 importContactsExcel() {
280 const input = document.createElement('input');
281 input.type = 'file';
282 input.accept = '.xlsx,.xls';
283 input.onchange = async (e) => {
284 const file = e.target.files[0];
285 if (!file) return;
286 await this._handleImportFile(file, 'contacts');
287 };
288 input.click();
289 }
290
291 async _handleImportFile(file, kind) {
292 try {
293 Toast.info('در حال خواندن فایل...');
294 const preview = await ExcelController.previewFile(file);
295
296 const kindLabel = kind === 'products' ? 'کالاها' : 'اشخاص';
297 const sheetsHtml = preview.sheets.map(s => `
298 <div style="padding:8px 12px;background:var(--bg);border-radius:8px;margin-bottom:6px;font-size:12.5px">
299 <strong>${this._esc(s.name)}</strong>
300 <span style="color:var(--text-muted);margin-right:6px">(${Formatters.number(s.count)} سطر)</span>
301 </div>
302 `).join('');
303
304 const body = `
305 <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px">
306 فایل <strong>${this._esc(file.name)}</strong> خونده شد. شیت‌های موجود:
307 </p>
308 ${sheetsHtml}
309 <div class="form-group" style="margin-top:14px">
310 <label class="form-label">حالت ورود</label>
311 <select class="form-control" id="importMode">
312 <option value="merge">🔀 ادغام (Merge) — فقط موارد جدید اضافه می‌شن</option>
313 <option value="replace">🔄 جایگزینی (Replace) — همه‌ی ${kindLabel} فعلی پاک و از فایل جایگزین می‌شن</option>
314 </select>
315 </div>
316 `;
317 const footer = `
318 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
319 <button class="btn btn-success" onclick="window.SettingsView._confirmImport(${JSON.stringify(kind).replace(/"/g, "'")}, '${this._esc(file.name)}')">✅ شروع ایمپورت</button>
320 `;
321 Modal.open({ title: `📤 ورود ${kindLabel} از Excel`, body, footer, size: 'md' });
322
323 // ذخیره‌ی موقت داده
324 window.__importRawData = preview.raw;
325 window.__importKind = kind;
326 } catch (err) {
327 console.error(err);
328 Toast.error('خطا: ' + err.message);
329 }
330 }
331
332 async _confirmImport(kind, fileName) {
333 const mode = document.getElementById('importMode').value;
334 const rawData = window.__importRawData;
335
336 if (!rawData) {
337 Toast.error('داده‌ای برای ایمپورت نیست');
338 return;
339 }
340
341 try {
342 Toast.info('در حال ایمپورت...');
343 let result;
344 if (kind === 'products') {
345 result = await ExcelController.importProducts(rawData, { mode });
346 } else {
347 result = await ExcelController.importContacts(rawData, { mode });
348 }
349
350 Modal.close();
351 Toast.success(`ایمپورت انجام شد: ${Formatters.number(result.added)} اضافه، ${Formatters.number(result.skipped)} رد شده`);
352
353 // رفرش KPI ها
354 await this.reload();
355 const grid = document.querySelector('.settings-grid');
356 if (grid) grid.innerHTML = this._renderAllCards();
357 } catch (err) {
358 console.error(err);
359 Toast.error('خطا در ایمپورت: ' + err.message);
360 } finally {
361 window.__importRawData = null;
362 window.__importKind = null;
363 }
364 }
365
366 downloadProductsTemplate() {
367 ExcelController.downloadProductsTemplate();
368 Toast.success('قالب کالاها دانلود شد');
369 }
370
371 downloadContactsTemplate() {
372 ExcelController.downloadContactsTemplate();
373 Toast.success('قالب اشخاص دانلود شد');
374 }
375
376 // ============================================================
377 // کارت میانبرهای صفحه‌کلید
378 // ============================================================
379 _renderShortcutsCard() {
380 const s = KeyboardShortcuts.settings;
381
382 const toggle = (id, checked, label, hint) => `
383 <label style="display:flex;align-items:flex-start;gap:10px;padding:9px 0;cursor:pointer;border-bottom:1px solid var(--border)">
384 <input type="checkbox" id="${id}" ${checked ? 'checked' : ''} style="margin-top:3px;width:16px;height:16px;cursor:pointer" />
385 <div style="flex:1">
386 <div style="font-size:13px;font-weight:600">${label}</div>
387 <div style="font-size:11px;color:var(--text-muted);margin-top:2px;line-height:1.6">${hint}</div>
388 </div>
389 </label>
390 `;
391
392 return `
393 <div class="card settings-card" style="border-color:#ddd6fe;background:linear-gradient(135deg,#faf5ff,#f8fafc)">
394 <div class="settings-card-header">
395 <div class="settings-card-icon" style="background:linear-gradient(135deg,#8b5cf6,#6d28d9)">⌨️</div>
396 <div>
397 <h3 class="settings-card-title">میانبرهای صفحه‌کلید</h3>
398 <p class="settings-card-desc">با این میانبرها کار با برنامه سریع‌تر می‌شود</p>
399 </div>
400 </div>
401
402 ${toggle('scEnabled', s.enabled, 'فعال بودن میانبرها', 'کلاً همه‌ی میانبرهای زیر رو روشن یا خاموش می‌کند')}
403 ${toggle('scEnterConfirms', s.enterConfirms, 'تأیید با Enter', 'وقتی توی فرم هستید، Enter مثل دکمه‌ی ذخیره عمل می‌کند. Ctrl+Enter هم توی همه‌ی فیلدها کار می‌کند')}
404 ${toggle('scEscapeCloses', s.escapeCloses, 'بستن با Escape', 'فشار دادن Escape، مودال باز را می‌بندد')}
405 ${toggle('scCtrlSaves', s.ctrlSaves, 'ذخیره با Ctrl+S', 'داخل مودال‌ها، Ctrl+S فرم را ذخیره می‌کند')}
406 ${toggle('scPlusMinusZeros', s.plusMinusZeros, 'ضریب سریع صفر (+ و -)', 'روی فیلدهای مبلغ، کلید + صفر اضافه و کلید − صفر کم می‌کند')}
407
408 <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)">
409 <div class="form-group" style="margin-bottom:0">
410 <label class="form-label">تعداد صفرهای کلید +</label>
411 <input type="text" inputmode="numeric" class="form-control" id="scPlusZeros" value="${Formatters.toPersianDigits(s.plusZeros)}" />
412 </div>
413 <div class="form-group" style="margin-bottom:0">
414 <label class="form-label">تعداد صفرهای کلید −</label>
415 <input type="text" inputmode="numeric" class="form-control" id="scMinusZeros" value="${Formatters.toPersianDigits(s.minusZeros)}" />
416 </div>
417 </div>
418
419 <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px">
420 <button class="btn" onclick="window.SettingsView.saveShortcuts()">💾 ذخیره تنظیمات</button>
421 <button class="btn btn-secondary" onclick="window.SettingsView.resetShortcuts()">↺ بازگشت به پیش‌فرض</button>
422 </div>
423 </div>
424 `;
425 }
426
427 saveShortcuts() {
428 try {
429 const plusZeros = parseInt(Formatters.toLatinDigits(document.getElementById('scPlusZeros').value)) || 0;
430 const minusZeros = parseInt(Formatters.toLatinDigits(document.getElementById('scMinusZeros').value)) || 0;
431
432 const settings = {
433 enabled: document.getElementById('scEnabled').checked,
434 enterConfirms: document.getElementById('scEnterConfirms').checked,
435 escapeCloses: document.getElementById('scEscapeCloses').checked,
436 ctrlSaves: document.getElementById('scCtrlSaves').checked,
437 plusMinusZeros: document.getElementById('scPlusMinusZeros').checked,
438 plusZeros: Math.max(0, Math.min(12, plusZeros)),
439 minusZeros: Math.max(0, Math.min(12, minusZeros))
440 };
441
442 KeyboardShortcuts.saveSettings(settings);
443 Toast.success('تنظیمات میانبرهای صفحه‌کلید ذخیره شد');
444 } catch (err) {
445 Toast.error('خطا: ' + err.message);
446 }
447 }
448
449 resetShortcuts() {
450 Modal.confirm({
451 title: 'بازگشت به پیش‌فرض',
452 message: 'آیا می‌خواهید همه‌ی تنظیمات میانبرهای صفحه‌کلید به حالت پیش‌فرض برگردد؟',
453 confirmText: 'بازگردان',
454 onConfirm: () => {
455 KeyboardShortcuts.resetSettings();
456 Toast.success('تنظیمات به حالت پیش‌فرض برگشت');
457 const grid = document.querySelector('.settings-grid');
458 if (grid) grid.innerHTML = this._renderAllCards();
459 }
460 });
461 }
462
463 // ============================================================
464 // کارت بکاپ
465 // ============================================================
466 _renderBackupCard() {
467 return `
468 <div class="card settings-card" style="border-color:#bfdbfe;background:linear-gradient(135deg,#eff6ff,#f8fafc)">
469 <div class="settings-card-header">
470 <div class="settings-card-icon" style="background:linear-gradient(135deg,#3b82f6,#1e40af)">💾</div>
471 <div>
472 <h3 class="settings-card-title">پشتیبان‌گیری رمزگذاری‌شده</h3>
473 <p class="settings-card-desc">اطلاعات عملیاتی و حسابداری شرکت فعال؛ بازیابی بدون بازنویسی کاربران و تنظیمات سراسری</p>
474 </div>
475 </div>
476
477 <div class="backup-warning">
478 ⚠️ <strong>مهم:</strong> قبل از هر تغییر بزرگ در برنامه، حتماً بکاپ بگیرید.
479 </div>
480
481 <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px">
482 <button class="btn" onclick="window.SettingsView.downloadBackup()">
483 📥 دانلود فایل بکاپ
484 </button>
485 <button class="btn btn-secondary" onclick="window.SettingsView.openRestoreModal()">
486 📤 بازیابی از بکاپ
487 </button>
488 </div>
489
490 <div style="margin-top:16px;padding-top:14px;border-top:1px dashed var(--border)">
491 <button class="btn btn-danger btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.openWipeModal()">
492 🗑️ پاک کردن کامل داده‌ها
493 </button>
494 <small style="color:var(--text-muted);font-size:11px;display:block;margin-top:6px">این عمل قابل بازگشت نیست، حتماً قبلش بکاپ بگیرید</small>
495 </div>
496 </div>
497 `;
498 }
499
500 // ============================================================
501 // ابزار تشخیص مغایرت‌ها (فقط خواندنی و درخواستی)
502 // ============================================================
503 _renderHealthCard() {
504 return `
505 <div class="card settings-card">
506 <div class="settings-card-header">
507 <div class="settings-card-icon">🔎</div>
508 <div>
509 <h3 class="settings-card-title">کنترل سلامت تسویه‌های مالی</h3>
510 <p class="settings-card-desc">بررسی مغایرت فاکتورها، رسیدها و تخصیص‌ها در شرکت فعال؛ بدون تغییر اطلاعات</p>
511 </div>
512 </div>
513 <button class="btn btn-secondary" onclick="window.SettingsView.runFinancialDiagnostics()">
514 بررسی مغایرت‌ها
515 </button>
516 <small style="display:block;margin-top:8px;color:var(--text-muted)">بررسی فقط هنگام درخواست اجرا می‌شود و هیچ سندی را خودکار اصلاح نمی‌کند.</small>
517 </div>
518 `;
519 }
520
521 async runFinancialDiagnostics() {
522 if (!Auth.isAdmin()) { Toast.error('این بررسی فقط برای مدیر مجاز است'); return; }
523 try {
524 Toast.info('در حال بررسی تسویه‌ها...');
525 const report = await inspectSettlementConsistency({ maxIssues: 50 });
526 const names = {
527 ORPHAN_SETTLEMENT: 'تسویه بدون فاکتور معتبر',
528 INVALID_SETTLEMENT_AMOUNT: 'مبلغ نامعتبر تسویه',
529 MISSING_TREASURY_TRANSACTION: 'رسید یا تراکنش خزانه ناموجود',
530 SETTLEMENT_AMOUNT_OVERFLOW: 'سرریز مبلغ تسویه',
531 SETTLEMENT_TOTAL_MISMATCH: 'عدم تطابق مبلغ تسویه با فاکتور',
532 INVALID_INVOICE_AMOUNT: 'مبلغ نامعتبر فاکتور',
533 INVOICE_OVERPAID: 'تسویه بیش از مبلغ فاکتور',
534 INVOICE_REMAINING_MISMATCH: 'مانده فاکتور نادرست',
535 INVOICE_STATUS_MISMATCH: 'وضعیت تسویه ناهماهنگ'
536 };
537 const rows = report.issues.map(issue => `
538 <div style="padding:9px 0;border-bottom:1px solid var(--border)">
539 <strong>${this._esc(names[issue.code] || issue.code)}</strong>
540 <div style="font-size:12px;color:var(--text-muted)">شناسه سند: ${this._esc(issue.documentId)}</div>
541 </div>`).join('');
542 const body = `
543 <p>فاکتورهای کنترل‌شده: <strong>${Formatters.number(report.checkedInvoices)}</strong>
544 | تخصیص‌ها: <strong>${Formatters.number(report.checkedSettlements)}</strong>
545 | مغایرت‌ها: <strong>${Formatters.number(report.issueCount)}</strong></p>
546 <p style="color:var(--text-muted);font-size:12px">این گزارش تشخیصی است؛ پیش از هر اصلاح، سندهای مبنا را بررسی کنید.</p>
547 ${rows || '<p>در کنترل‌های فعلی مغایرتی یافت نشد.</p>'}
548 ${report.truncated ? '<p>فقط ۵۰ مغایرت نخست نمایش داده می‌شود.</p>' : ''}
549 `;
550 Modal.open({ title: 'گزارش کنترل سلامت تسویه‌ها', body,
551 footer: '<button class="btn" onclick="FINORA.Modal.close()">بستن</button>', size: 'lg' });
552 } catch (err) {
553 Toast.error('بررسی سلامت تسویه‌ها ناموفق بود: ' + err.message);
554 }
555 }
556
557 // ============================================================
558 // کارت آمار
559 // ============================================================
560 _renderStatsCard() {
561 const s = cache.stats;
562 const items = [
563 { label: 'کالا و خدمات', value: s.products || 0, icon: '📦' },
564 { label: 'اشخاص', value: s.contacts || 0, icon: '👥' },
565 { label: 'فاکتورها', value: s.invoices || 0, icon: '🧾' },
566 { label: 'چک‌ها', value: s.cheques || 0, icon: '💳' },
567 { label: 'حساب‌ها', value: s.accounts || 0, icon: '🏦' },
568 { label: 'تراکنش‌ها', value: s.transactions || 0, icon: '💸' }
569 ];
570 return `
571 <div class="card settings-card">
572 <div class="settings-card-header">
573 <div class="settings-card-icon" style="background:linear-gradient(135deg,#0ea5e9,#0369a1)">📊</div>
574 <div>
575 <h3 class="settings-card-title">آمار داده‌ها</h3>
576 <p class="settings-card-desc">خلاصه‌ی داده‌های ذخیره‌شده در سیستم</p>
577 </div>
578 </div>
579 <div class="stats-grid">
580 ${items.map(i => `
581 <div class="stat-mini">
582 <div style="font-size:18px;margin-bottom:4px">${i.icon}</div>
583 <div style="font-size:18px;font-weight:800;color:var(--primary)">${Formatters.number(i.value)}</div>
584 <div style="font-size:11px;color:var(--text-muted);margin-top:2px">${i.label}</div>
585 </div>
586 `).join('')}
587 </div>
588 </div>
589 `;
590 }
591
592 // ============================================================
593 // کارت تم
594 // ============================================================
595 _renderThemeCard() {
596 const current = Theme.current();
597 return `
598 <div class="card settings-card">
599 <div class="settings-card-header">
600 <div class="settings-card-icon" style="background:linear-gradient(135deg,#8b5cf6,#6d28d9)">🎨</div>
601 <div>
602 <h3 class="settings-card-title">ظاهر و تم</h3>
603 <p class="settings-card-desc">حالت نمایش برنامه</p>
604 </div>
605 </div>
606 <div style="display:flex;gap:10px;margin-top:8px">
607 <button class="btn ${current === 'light' ? '' : 'btn-secondary'}" onclick="window.SettingsView.setTheme('light')">☀️ روشن</button>
608 <button class="btn ${current === 'dark' ? '' : 'btn-secondary'}" onclick="window.SettingsView.setTheme('dark')">🌙 تاریک</button>
609 </div>
610 </div>
611 `;
612 }
613
614 // ============================================================
615 // کارت درباره
616 // ============================================================
617 _renderAboutCard() {
618 return `
619 <div class="card settings-card">
620 <div class="settings-card-header">
621 <div class="settings-card-icon">ℹ️</div>
622 <div>
623 <h3 class="settings-card-title">درباره فینورا پرو</h3>
624 <p class="settings-card-desc">نسخه ۲.۰.۳</p>
625 </div>
626 </div>
627 <div style="font-size:13px;line-height:1.9;color:var(--text-muted)">
628 <div><strong>طراح و توسعه‌دهنده:</strong> داوود مهربان</div>
629 <div><strong>تماس:</strong> <span dir="ltr">0912-437-6991</span></div>
630 <div style="margin-top:8px;padding-top:10px;border-top:1px dashed var(--border)">
631 <a href="https://wa.me/989124376991" target="_blank" class="btn btn-inline" style="background:linear-gradient(135deg,#25D366,#128C7E);font-size:12.5px;min-height:36px">💬 واتس‌اپ پشتیبانی</a>
632 </div>
633 </div>
634 </div>
635 `;
636 }
637
638 _renderAllCards() {
639 return this._renderCompanyCard()
640 + this._renderInvoiceSettingsCard()
641 + this._renderExcelCard()
642 + this._renderShortcutsCard()
643 + this._renderBackupCard()
644 + this._renderStatsCard()
645 + (Auth.isAdmin() ? this._renderHealthCard() : '')
646 + this._renderThemeCard()
647 + this._renderAboutCard();
648 }
649
650 // ============================================================
651 // فرم اطلاعات شرکت
652 // ============================================================
653 async openCompanySwitcher() {
654 const companies = await globalThis.FINORA.Company.list();
655 const body = companies.map(c => `<button class="btn" style="width:100%;margin:4px 0" onclick="window.SettingsView.selectCompany('${c.id}')">${this._esc(c.name || 'شرکت')}</button>`).join('');
656 Modal.open({ title: 'تغییر شرکت فعال', body: body || '<div class="empty-mini">شرکتی یافت نشد</div>', footer: '', size: 'sm' });
657 }
658
659 async selectCompany(id) {
660 await globalThis.FINORA.Company.select(id); Modal.close(); await this.reload(); Toast.success('شرکت فعال تغییر کرد');
661 }
662
663 async createCompany() {
664 const name = prompt('نام شرکت جدید را وارد کنید:'); if (!name?.trim()) return;
665 const company = await globalThis.FINORA.Company.create({ name: name.trim(), entityType: 'legal' });
666 await globalThis.FINORA.Company.select(company.id); await this.reload(); Toast.success('شرکت جدید ایجاد شد');
667 }
668
669 openCompanyModal() {
670 const c = cache.company;
671 const body = `
672 <div class="form-row">
673 <div class="form-group">
674 <label class="form-label">نوع شخص</label>
675 <select class="form-control" id="coEntityType">
676 <option value="legal" ${c.entityType === 'legal' ? 'selected' : ''}>حقوقی</option>
677 <option value="natural" ${c.entityType === 'natural' ? 'selected' : ''}>حقیقی</option>
678 </select>
679 </div>
680 <div class="form-group">
681 <label class="form-label">نام شرکت / فروشگاه <span class="req">*</span></label>
682 <input type="text" class="form-control" id="coName" value="${this._esc(c.name)}" />
683 </div>
684 </div>
685 <div class="form-row">
686 <div class="form-group">
687 <label class="form-label">شناسه ملی / کد ملی</label>
688 <input type="text" class="form-control" id="coNationalId" value="${this._esc(c.nationalId)}" />
689 </div>
690 <div class="form-group">
691 <label class="form-label">کد اقتصادی</label>
692 <input type="text" class="form-control" id="coEconomicCode" value="${this._esc(c.economicCode)}" />
693 </div>
694 </div>
695 <div class="form-row">
696 <div class="form-group">
697 <label class="form-label">شماره ثبت</label>
698 <input type="text" class="form-control" id="coRegNumber" value="${this._esc(c.regNumber)}" />
699 </div>
700 <div class="form-group">
701 <label class="form-label">کد پستی</label>
702 <input type="text" class="form-control" id="coPostalCode" value="${this._esc(c.postalCode)}" />
703 </div>
704 </div>
705 <div class="form-row">
706 <div class="form-group">
707 <label class="form-label">تلفن</label>
708 <input type="tel" class="form-control" id="coPhone" value="${this._esc(c.phone)}" />
709 </div>
710 <div class="form-group">
711 <label class="form-label">موبایل</label>
712 <input type="tel" class="form-control" id="coMobile" value="${this._esc(c.mobile)}" />
713 </div>
714 </div>
715 <div class="form-group">
716 <label class="form-label">نشانی</label>
717 <textarea class="form-control" id="coAddress" rows="2">${this._esc(c.address)}</textarea>
718 </div>
719 <div class="form-group">
720 <label class="form-label">پاورقی فاکتور</label>
721 <textarea class="form-control" id="coFooter" rows="2" placeholder="مثلاً: از خرید شما سپاسگزاریم">${this._esc(c.footer)}</textarea>
722 </div>
723 `;
724 const footer = `
725 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
726 <button class="btn" onclick="window.SettingsView.saveCompany()">💾 ذخیره</button>
727 `;
728 Modal.open({ title: 'اطلاعات شرکت', body, footer, size: 'md' });
729 }
730
731 async saveCompany() {
732 const data = {
733 name: document.getElementById('coName').value,
734 entityType: document.getElementById('coEntityType').value,
735 nationalId: document.getElementById('coNationalId').value,
736 economicCode: document.getElementById('coEconomicCode').value,
737 regNumber: document.getElementById('coRegNumber').value,
738 postalCode: document.getElementById('coPostalCode').value,
739 phone: document.getElementById('coPhone').value,
740 mobile: document.getElementById('coMobile').value,
741 address: document.getElementById('coAddress').value,
742 footer: document.getElementById('coFooter').value
743 };
744 if (!data.name.trim()) { Toast.warning('نام الزامی است'); return; }
745 try {
746 await SettingsController.saveCompanyInfo(data);
747 Toast.success('اطلاعات ذخیره شد');
748 Modal.close();
749 await this.reload();
750 const grid = document.querySelector('.settings-grid');
751 if (grid) grid.innerHTML = this._renderAllCards();
752 } catch (err) {
753 Toast.error('خطا: ' + err.message);
754 }
755 }
756
757 // ============================================================
758 // بکاپ JSON
759 // ============================================================
760 async downloadBackup() {
761 try {
762 Toast.info('در حال آماده‌سازی بکاپ...');
763 const result = await SettingsController.downloadBackup();
764 Toast.success(`بکاپ دانلود شد (${result.filename})`, 'موفق');
765 } catch (err) {
766 Toast.error('خطا در بکاپ: ' + err.message);
767 }
768 }
769
770 openRestoreModal() {
771 const body = `
772 <div class="backup-warning" style="margin-bottom:14px">
773 ⚠️ <strong>هشدار:</strong> در حالت Merge، داده‌های تکراری skip می‌شن. در حالت Replace، فقط رکوردهای دارای شناسه یکسان بازنویسی می‌شوند و سایر داده‌ها حذف نمی‌شوند.
774 </div>
775
776 <div class="form-group">
777 <label class="form-label">فایل بکاپ رمزگذاری‌شده یا JSON</label>
778 <input type="file" class="form-control" id="restoreFile" accept=".json,.fbackup,application/json,application/octet-stream" />
779 </div>
780
781 <div class="form-group">
782 <label class="form-label">حالت بازیابی</label>
783 <select class="form-control" id="restoreMode">
784 <option value="merge">🔀 ادغام (Merge) — داده‌های جدید اضافه می‌شن</option>
785 <option value="replace">🔄 بازنویسی شناسه‌های یکسان (Replace) — بدون حذف سایر رکوردها</option>
786 </select>
787 </div>
788 `;
789 const footer = `
790 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
791 <button class="btn" onclick="window.SettingsView.restoreBackup()">📤 بازیابی</button>
792 `;
793 Modal.open({ title: 'بازیابی از بکاپ', body, footer, size: 'md' });
794 }
795
796 async restoreBackup() {
797 const fileInput = document.getElementById('restoreFile');
798 const file = fileInput.files[0];
799 if (!file) { Toast.warning('فایل بکاپ رو انتخاب کنید'); return; }
800
801 const mode = document.getElementById('restoreMode').value;
802
803 try {
804 Toast.info('در حال بازیابی...');
805 const content = await SettingsController.readFileAsText(file);
806 const counts = await SettingsController.importBackup(content, { mode });
807 Modal.close();
808 Toast.success(`بازیابی انجام شد: ${counts.added} مورد اضافه، ${counts.skipped} مورد skip`);
809 setTimeout(() => location.reload(), 1500);
810 } catch (err) {
811 Toast.error('خطا: ' + err.message);
812 }
813 }
814
815 // ============================================================
816 // پاک کردن کامل
817 // ============================================================
818 openWipeModal() {
819 const body = `
820 <div style="text-align:center;padding:10px 0">
821 <div style="font-size:48px;margin-bottom:12px">⚠️</div>
822 <h3 style="color:var(--danger);margin-bottom:8px">پاک کردن کامل داده‌ها</h3>
823 <p style="color:var(--text-muted);font-size:13px;line-height:1.8;margin-bottom:16px">
824 این عمل همه‌ی کالاها، اشخاص، فاکتورها، چک‌ها، تراکنش‌ها و تنظیمات رو برای همیشه پاک می‌کند.
825 <br><strong>قابل بازگشت نیست!</strong>
826 </p>
827 <p style="font-size:12px;color:var(--danger);margin-bottom:16px">
828 لطفاً برای تأیید، کلمه‌ی <code style="background:var(--danger);color:#fff;padding:2px 8px;border-radius:4px">حذف</code> رو تایپ کنید
829 </p>
830 <input type="text" class="form-control" id="wipeConfirm" placeholder="حذف" style="text-align:center;max-width:200px;margin:0 auto" />
831 </div>
832 `;
833 const footer = `
834 <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button>
835 <button class="btn btn-danger" onclick="window.SettingsView.confirmWipe()">🗑️ پاک کن</button>
836 `;
837 Modal.open({ title: 'تأیید پاک کردن', body, footer, size: 'sm' });
838 }
839
840 async confirmWipe() {
841 const confirmText = document.getElementById('wipeConfirm').value.trim();
842 if (confirmText !== 'حذف') {
843 Toast.warning('متن تأیید اشتباه است');
844 return;
845 }
846 try {
847 await SettingsController.wipeAll();
848 Toast.success('همه‌ی داده‌ها پاک شد');
849 setTimeout(() => location.reload(), 800);
850 } catch (err) {
851 Toast.error('خطا: ' + err.message);
852 }
853 }
854
855 // ============================================================
856 // Theme
857 // ============================================================
858 setTheme(theme) {
859 Theme.apply(theme);
860 const grid = document.querySelector('.settings-grid');
861 if (grid) grid.innerHTML = this._renderAllCards();
862 }
863
864 _esc(s) {
865 if (!s) return '';
866 return String(s).replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
867 }
868 }
869
870 export const SettingsView = new SettingsViewImpl();
871 window.SettingsView = SettingsView;