Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -112,10 +112,7 @@ function extractFields(ticketText){
|
|
| 112 |
return data;
|
| 113 |
}
|
| 114 |
|
| 115 |
-
function parseTickets(raw){
|
| 116 |
-
const tickets = splitTickets(raw||"");
|
| 117 |
-
return tickets.map(extractFields);
|
| 118 |
-
}
|
| 119 |
|
| 120 |
function buildTable(rows){
|
| 121 |
const theadRow = document.getElementById("theadRow");
|
|
@@ -151,10 +148,12 @@ function readTable(){
|
|
| 151 |
}
|
| 152 |
|
| 153 |
function updateCount(n){
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
| 156 |
}
|
| 157 |
-
|
| 158 |
function toast(msg){
|
| 159 |
const t = document.getElementById("toast");
|
| 160 |
t.textContent = msg;
|
|
@@ -165,9 +164,11 @@ function toast(msg){
|
|
| 165 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 166 |
}
|
| 167 |
|
| 168 |
-
|
|
|
|
| 169 |
const rows = readTable();
|
| 170 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
|
|
|
| 171 |
const aoa = [EXPORT_COLUMNS, ...rows.map(r=>EXPORT_COLUMNS.map(c=>r[c]||""))];
|
| 172 |
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
| 173 |
ws["!rtl"] = true;
|
|
@@ -177,10 +178,31 @@ function exportExcel(){
|
|
| 177 |
const now = new Date();
|
| 178 |
const ts = now.toISOString().replace(/\D/g,'').slice(0,14);
|
| 179 |
const base = (document.getElementById("fname").value || "Ticket").trim() || "Ticket";
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
}
|
| 183 |
|
|
|
|
| 184 |
async function copyToClipboardTSV(){
|
| 185 |
const rows = readTable();
|
| 186 |
if(!rows.length){ toast("لا يوجد بيانات لنسخها."); return; }
|
|
@@ -191,7 +213,6 @@ async function copyToClipboardTSV(){
|
|
| 191 |
await navigator.clipboard.writeText(tsv);
|
| 192 |
toast("تم النسخ — الصق/ي مباشرة في Excel.");
|
| 193 |
}catch(e){
|
| 194 |
-
// بديل: تحديد نص مخفي
|
| 195 |
const ta = document.createElement("textarea");
|
| 196 |
ta.value = tsv; document.body.appendChild(ta);
|
| 197 |
ta.select(); document.execCommand("copy"); document.body.removeChild(ta);
|
|
@@ -199,11 +220,7 @@ async function copyToClipboardTSV(){
|
|
| 199 |
}
|
| 200 |
}
|
| 201 |
|
| 202 |
-
|
| 203 |
-
document.getElementById("btn-export").disabled = !hasRows;
|
| 204 |
-
document.getElementById("btn-copy").disabled = !hasRows;
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 208 |
وقت حدوث المشكلة: 21/8/2025
|
| 209 |
اسم صاحب المشكلة : نوف الناصر
|
|
@@ -242,6 +259,4 @@ document.addEventListener("DOMContentLoaded", ()=>{
|
|
| 242 |
|
| 243 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
|
| 244 |
|
| 245 |
-
// تعطيل أزرار التصدير/النسخ مبدئيًا
|
| 246 |
setButtonsEnabled(false);
|
| 247 |
-
});
|
|
|
|
| 112 |
return data;
|
| 113 |
}
|
| 114 |
|
| 115 |
+
function parseTickets(raw){ return splitTickets(raw||"").map(extractFields); }
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
function buildTable(rows){
|
| 118 |
const theadRow = document.getElementById("theadRow");
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
function updateCount(n){
|
| 151 |
+
document.getElementById("countChip").textContent = `عدد التذاكر: ${n}`;
|
| 152 |
+
}
|
| 153 |
+
function setButtonsEnabled(hasRows){
|
| 154 |
+
document.getElementById("btn-export").disabled = !hasRows;
|
| 155 |
+
document.getElementById("btn-copy").disabled = !hasRows;
|
| 156 |
}
|
|
|
|
| 157 |
function toast(msg){
|
| 158 |
const t = document.getElementById("toast");
|
| 159 |
t.textContent = msg;
|
|
|
|
| 164 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 165 |
}
|
| 166 |
|
| 167 |
+
/* تصدير/مشاركة Excel: يجرّب Web Share أولاً ثم تنزيل كبديل */
|
| 168 |
+
async function exportExcel(){
|
| 169 |
const rows = readTable();
|
| 170 |
if(!rows.length){ toast("لا يوجد بيانات لتصديرها."); return; }
|
| 171 |
+
|
| 172 |
const aoa = [EXPORT_COLUMNS, ...rows.map(r=>EXPORT_COLUMNS.map(c=>r[c]||""))];
|
| 173 |
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
| 174 |
ws["!rtl"] = true;
|
|
|
|
| 178 |
const now = new Date();
|
| 179 |
const ts = now.toISOString().replace(/\D/g,'').slice(0,14);
|
| 180 |
const base = (document.getElementById("fname").value || "Ticket").trim() || "Ticket";
|
| 181 |
+
const filename = `${base}_${ts}.xlsx`;
|
| 182 |
+
|
| 183 |
+
const wbArray = XLSX.write(wb, { bookType: "xlsx", type: "array" });
|
| 184 |
+
const blob = new Blob([wbArray], {
|
| 185 |
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 186 |
+
});
|
| 187 |
+
const file = new File([blob], filename, { type: blob.type });
|
| 188 |
+
|
| 189 |
+
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
| 190 |
+
try {
|
| 191 |
+
await navigator.share({ files: [file], title: "ملف التذاكر" });
|
| 192 |
+
toast("تمت المشاركة/الحفظ بنجاح.");
|
| 193 |
+
return;
|
| 194 |
+
} catch(e) { /* أُغلقت ورقة المشاركة – نكمل بالتنزيل */ }
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
const url = URL.createObjectURL(blob);
|
| 198 |
+
const a = document.createElement("a");
|
| 199 |
+
a.href = url; a.download = filename;
|
| 200 |
+
document.body.appendChild(a); a.click(); a.remove();
|
| 201 |
+
setTimeout(()=>URL.revokeObjectURL(url), 1000);
|
| 202 |
+
toast("تم تنزيل الملف.");
|
| 203 |
}
|
| 204 |
|
| 205 |
+
/* نسخ الجدول كـTSV للصق مباشر في Excel */
|
| 206 |
async function copyToClipboardTSV(){
|
| 207 |
const rows = readTable();
|
| 208 |
if(!rows.length){ toast("لا يوجد بيانات لنسخها."); return; }
|
|
|
|
| 213 |
await navigator.clipboard.writeText(tsv);
|
| 214 |
toast("تم النسخ — الصق/ي مباشرة في Excel.");
|
| 215 |
}catch(e){
|
|
|
|
| 216 |
const ta = document.createElement("textarea");
|
| 217 |
ta.value = tsv; document.body.appendChild(ta);
|
| 218 |
ta.select(); document.execCommand("copy"); document.body.removeChild(ta);
|
|
|
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
| 223 |
+
/* المثال المطلوب */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 225 |
وقت حدوث المشكلة: 21/8/2025
|
| 226 |
اسم صاحب المشكلة : نوف الناصر
|
|
|
|
| 259 |
|
| 260 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
|
| 261 |
|
|
|
|
| 262 |
setButtonsEnabled(false);
|
|
|