stat2025 commited on
Commit
c08d4b4
·
verified ·
1 Parent(s): d54bdf8

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +1 -106
app.js CHANGED
@@ -182,109 +182,4 @@ document.addEventListener("input",(e)=>{
182
  });
183
 
184
  /* Toast */
185
- function toast(msg){
186
- const t = document.getElementById("toast");
187
- t.textContent = msg; t.hidden = false;
188
- t.classList.remove("show"); void t.offsetWidth; t.classList.add("show");
189
- setTimeout(()=>{ t.hidden = true; }, 2400);
190
- }
191
-
192
- /* تصدير/مشاركة Excel: Web Share أولاً ثم تنزيل كبديل */
193
- async function exportExcel(){
194
- const rows = readTable();
195
- if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
196
-
197
- const aoa = [EXPORT_COLUMNS, ...rows.map(r=>EXPORT_COLUMNS.map(c=>r[c]||""))];
198
- const ws = XLSX.utils.aoa_to_sheet(aoa);
199
- ws["!rtl"] = true;
200
- const wb = XLSX.utils.book_new();
201
- XLSX.utils.book_append_sheet(wb, ws, "التذاكر");
202
-
203
- const now = new Date();
204
- const ts = now.toISOString().replace(/\D/g,'').slice(0,14);
205
- const base = (document.getElementById("fname").value || "Ticket").trim() || "Ticket";
206
- const filename = `${base}_${ts}.xlsx`;
207
-
208
- const wbArray = XLSX.write(wb, { bookType: "xlsx", type: "array" });
209
- const blob = new Blob([wbArray], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
210
- const file = new File([blob], filename, { type: blob.type });
211
-
212
- if (navigator.canShare && navigator.canShare({ files: [file] })) {
213
- try { await navigator.share({ files: [file], title: "ملف التذاكر" }); toast("تمت المشاركة/الحفظ بنجاح."); return; }
214
- catch(e){ /* المستخدم أغلق ورقة المشاركة */ }
215
- }
216
- const url = URL.createObjectURL(blob);
217
- const a = document.createElement("a"); a.href = url; a.download = filename;
218
- document.body.appendChild(a); a.click(); a.remove();
219
- setTimeout(()=>URL.revokeObjectURL(url), 1000);
220
- toast("تم تنزيل الملف.");
221
- }
222
-
223
- /* نسخ الجدول كـTSV للصق مباشر في Excel */
224
- async function copyToClipboardTSV(){
225
- const rows = readTable();
226
- if(!rows.length){ toast("لا يوجد بيانات لنسخها."); return; }
227
- const header = EXPORT_COLUMNS.join("\t");
228
- const body = rows.map(r=>EXPORT_COLUMNS.map(c=>(r[c]||"").replace(/\t/g," ")).join("\t")).join("\n");
229
- const tsv = `${header}\n${body}`;
230
- try{ await navigator.clipboard.writeText(tsv); toast("تم النسخ — الصق/ي مباشرة في Excel."); }
231
- catch(e){
232
- const ta = document.createElement("textarea"); ta.value = tsv; document.body.appendChild(ta);
233
- ta.select(); document.execCommand("copy"); document.body.removeChild(ta);
234
- toast("تم النسخ — الصق/ي مباشرة في Excel.");
235
- }
236
- }
237
-
238
- /* المثال المطلوب (تذكرة واحدة) */
239
- const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
240
- وقت حدوث المشكلة: 21/8/2025
241
- اسم صاحب المشكلة : نوف الناصر
242
- رقم الهوية: 1234567890
243
- رقم الجهاز: 01234
244
- رقم الجوال: 0558174717
245
- اسم المسح: الخبر
246
- المنطقة: الشرقية`;
247
-
248
- /* تهيئة وربط الأزرار + اختصارات + حفظ تلقائي */
249
- function init(){
250
- const parseBtn = document.getElementById("btn-parse");
251
- const exportBtn = document.getElementById("btn-export");
252
- const copyBtn = document.getElementById("btn-copy");
253
- const clearBtn = document.getElementById("btn-clear");
254
- const sampleBtn = document.getElementById("btn-sample");
255
- const rawEl = document.getElementById("raw");
256
-
257
- // استرجاع الإدخال السابق إن وُجد
258
- const saved = localStorage.getItem("rawTickets");
259
- if(!rawEl.value && saved){ rawEl.value = saved; }
260
-
261
- parseBtn.addEventListener("click", ()=>{
262
- const raw = rawEl.value || SAMPLE;
263
- const rows = parseTickets(raw);
264
- buildTable(rows);
265
- validateCells();
266
- updateBadge(rows.length);
267
- setButtonsEnabled(rows.length>0);
268
- localStorage.setItem("rawTickets", raw);
269
- toast(`تم استخراج ${rows.length} ${rows.length===1 ? "تذكرة" : "تذاكر"}.`);
270
- });
271
- exportBtn.addEventListener("click", exportExcel);
272
- copyBtn.addEventListener("click", copyToClipboardTSV);
273
- clearBtn.addEventListener("click", ()=>{
274
- rawEl.value = ""; document.getElementById("tbody").innerHTML = "";
275
- updateBadge(0); setButtonsEnabled(false);
276
- });
277
- sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
278
-
279
- // اختصارات لوحة المفاتيح
280
- document.addEventListener("keydown", (e)=>{
281
- const ctrl = e.ctrlKey || e.metaKey;
282
- if(ctrl && e.key === "Enter"){ e.preventDefault(); parseBtn.click(); }
283
- else if(ctrl && e.key.toLowerCase() === "e"){ e.preventDefault(); exportBtn.click(); }
284
- else if(ctrl && e.shiftKey && e.key.toLowerCase() === "c"){ e.preventDefault(); copyBtn.click(); }
285
- else if(e.key === "Escape"){ e.preventDefault(); clearBtn.click(); }
286
- });
287
-
288
- setButtonsEnabled(false); // مبدئيًا
289
- }
290
- init(); // لدينا defer في index.html
 
182
  });
183
 
184
  /* Toast */
185
+ function toast(ms