Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -134,6 +134,8 @@ function buildTable(rows){
|
|
| 134 |
tbody.appendChild(tr);
|
| 135 |
});
|
| 136 |
}
|
|
|
|
|
|
|
| 137 |
function readTable(){
|
| 138 |
const tbody = document.getElementById("tbody");
|
| 139 |
const rows = [];
|
|
@@ -144,17 +146,50 @@ function readTable(){
|
|
| 144 |
});
|
| 145 |
return rows;
|
| 146 |
}
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
function setButtonsEnabled(hasRows){
|
| 149 |
document.getElementById("btn-export").disabled = !hasRows;
|
| 150 |
document.getElementById("btn-copy").disabled = !hasRows;
|
| 151 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
function toast(msg){
|
| 153 |
const t = document.getElementById("toast");
|
| 154 |
t.textContent = msg; t.hidden = false;
|
| 155 |
t.classList.remove("show"); void t.offsetWidth; t.classList.add("show");
|
| 156 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 157 |
}
|
|
|
|
| 158 |
/* تصدير/مشاركة Excel: Web Share أولاً ثم تنزيل كبديل */
|
| 159 |
async function exportExcel(){
|
| 160 |
const rows = readTable();
|
|
@@ -185,6 +220,7 @@ async function exportExcel(){
|
|
| 185 |
setTimeout(()=>URL.revokeObjectURL(url), 1000);
|
| 186 |
toast("تم تنزيل الملف.");
|
| 187 |
}
|
|
|
|
| 188 |
/* نسخ الجدول كـTSV للصق مباشر في Excel */
|
| 189 |
async function copyToClipboardTSV(){
|
| 190 |
const rows = readTable();
|
|
@@ -200,7 +236,7 @@ async function copyToClipboardTSV(){
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
| 203 |
-
/* المثال المطلوب */
|
| 204 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 205 |
وقت حدوث المشكلة: 21/8/2025
|
| 206 |
اسم صاحب المشكلة : نوف الناصر
|
|
@@ -210,7 +246,7 @@ const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاست
|
|
| 210 |
اسم المسح: الخبر
|
| 211 |
المنطقة: الشرقية`;
|
| 212 |
|
| 213 |
-
/* تهيئة وربط الأزرار */
|
| 214 |
function init(){
|
| 215 |
const parseBtn = document.getElementById("btn-parse");
|
| 216 |
const exportBtn = document.getElementById("btn-export");
|
|
@@ -219,22 +255,38 @@ function init(){
|
|
| 219 |
const sampleBtn = document.getElementById("btn-sample");
|
| 220 |
const rawEl = document.getElementById("raw");
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
parseBtn.addEventListener("click", ()=>{
|
| 223 |
const raw = rawEl.value || SAMPLE;
|
| 224 |
const rows = parseTickets(raw);
|
| 225 |
buildTable(rows);
|
|
|
|
| 226 |
updateCount(rows.length);
|
|
|
|
| 227 |
setButtonsEnabled(rows.length>0);
|
|
|
|
| 228 |
toast(`تم استخراج ${rows.length} ${rows.length===1 ? "تذكرة" : "تذاكر"}.`);
|
| 229 |
});
|
| 230 |
exportBtn.addEventListener("click", exportExcel);
|
| 231 |
copyBtn.addEventListener("click", copyToClipboardTSV);
|
| 232 |
clearBtn.addEventListener("click", ()=>{
|
| 233 |
rawEl.value = ""; document.getElementById("tbody").innerHTML = "";
|
| 234 |
-
updateCount(0); setButtonsEnabled(false);
|
| 235 |
});
|
| 236 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
setButtonsEnabled(false); // مبدئيًا
|
| 239 |
}
|
| 240 |
-
init(); //
|
|
|
|
| 134 |
tbody.appendChild(tr);
|
| 135 |
});
|
| 136 |
}
|
| 137 |
+
|
| 138 |
+
/* قراءة الجدول */
|
| 139 |
function readTable(){
|
| 140 |
const tbody = document.getElementById("tbody");
|
| 141 |
const rows = [];
|
|
|
|
| 146 |
});
|
| 147 |
return rows;
|
| 148 |
}
|
| 149 |
+
|
| 150 |
+
/* عدّاد وشارة */
|
| 151 |
+
function updateCount(n){
|
| 152 |
+
document.getElementById("countChip").textContent = `عدد التذاكر: ${n}`;
|
| 153 |
+
}
|
| 154 |
+
function updateBadge(n){
|
| 155 |
+
const b = document.getElementById("countBadge");
|
| 156 |
+
b.textContent = n; b.hidden = (n===0);
|
| 157 |
+
}
|
| 158 |
function setButtonsEnabled(hasRows){
|
| 159 |
document.getElementById("btn-export").disabled = !hasRows;
|
| 160 |
document.getElementById("btn-copy").disabled = !hasRows;
|
| 161 |
}
|
| 162 |
+
|
| 163 |
+
/* إبراز الخلايا غير الصحيحة (هوية/جوال) */
|
| 164 |
+
function validateCells(){
|
| 165 |
+
const tbody=document.getElementById("tbody");
|
| 166 |
+
const idxPhone = EXPORT_COLUMNS.indexOf("رقم الجوال");
|
| 167 |
+
const idxID = EXPORT_COLUMNS.indexOf("رقم الهوية");
|
| 168 |
+
[...tbody.rows].forEach(tr=>{
|
| 169 |
+
if(idxPhone>=0){
|
| 170 |
+
const td=tr.children[idxPhone], v=td.textContent.trim();
|
| 171 |
+
const ok=/^05\d{8}$/.test(v); td.classList.toggle("invalid", v && !ok);
|
| 172 |
+
}
|
| 173 |
+
if(idxID>=0){
|
| 174 |
+
const td=tr.children[idxID], v=td.textContent.trim();
|
| 175 |
+
const ok=/^1\d{9}$/.test(v); td.classList.toggle("invalid", v && !ok);
|
| 176 |
+
}
|
| 177 |
+
});
|
| 178 |
+
}
|
| 179 |
+
document.addEventListener("input",(e)=>{
|
| 180 |
+
if(e.target && e.target.closest && e.target.closest("#tbody")){
|
| 181 |
+
validateCells();
|
| 182 |
+
}
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
/* Toast */
|
| 186 |
function toast(msg){
|
| 187 |
const t = document.getElementById("toast");
|
| 188 |
t.textContent = msg; t.hidden = false;
|
| 189 |
t.classList.remove("show"); void t.offsetWidth; t.classList.add("show");
|
| 190 |
setTimeout(()=>{ t.hidden = true; }, 2400);
|
| 191 |
}
|
| 192 |
+
|
| 193 |
/* تصدير/مشاركة Excel: Web Share أولاً ثم تنزيل كبديل */
|
| 194 |
async function exportExcel(){
|
| 195 |
const rows = readTable();
|
|
|
|
| 220 |
setTimeout(()=>URL.revokeObjectURL(url), 1000);
|
| 221 |
toast("تم تنزيل الملف.");
|
| 222 |
}
|
| 223 |
+
|
| 224 |
/* نسخ الجدول كـTSV للصق مباشر في Excel */
|
| 225 |
async function copyToClipboardTSV(){
|
| 226 |
const rows = readTable();
|
|
|
|
| 236 |
}
|
| 237 |
}
|
| 238 |
|
| 239 |
+
/* المثال المطلوب (تذكرة واحدة) */
|
| 240 |
const SAMPLE = `نوع المشكلة : لا استطيع اكمال الاستمارة بسبب تعليق
|
| 241 |
وقت حدوث المشكلة: 21/8/2025
|
| 242 |
اسم صاحب المشكلة : نوف الناصر
|
|
|
|
| 246 |
اسم المسح: الخبر
|
| 247 |
المنطقة: الشرقية`;
|
| 248 |
|
| 249 |
+
/* تهيئة وربط الأزرار + اختصارات + حفظ تلقائي */
|
| 250 |
function init(){
|
| 251 |
const parseBtn = document.getElementById("btn-parse");
|
| 252 |
const exportBtn = document.getElementById("btn-export");
|
|
|
|
| 255 |
const sampleBtn = document.getElementById("btn-sample");
|
| 256 |
const rawEl = document.getElementById("raw");
|
| 257 |
|
| 258 |
+
// استرجاع الإدخال السابق إن وُجد
|
| 259 |
+
const saved = localStorage.getItem("rawTickets");
|
| 260 |
+
if(!rawEl.value && saved){ rawEl.value = saved; }
|
| 261 |
+
|
| 262 |
parseBtn.addEventListener("click", ()=>{
|
| 263 |
const raw = rawEl.value || SAMPLE;
|
| 264 |
const rows = parseTickets(raw);
|
| 265 |
buildTable(rows);
|
| 266 |
+
validateCells();
|
| 267 |
updateCount(rows.length);
|
| 268 |
+
updateBadge(rows.length);
|
| 269 |
setButtonsEnabled(rows.length>0);
|
| 270 |
+
localStorage.setItem("rawTickets", raw);
|
| 271 |
toast(`تم استخراج ${rows.length} ${rows.length===1 ? "تذكرة" : "تذاكر"}.`);
|
| 272 |
});
|
| 273 |
exportBtn.addEventListener("click", exportExcel);
|
| 274 |
copyBtn.addEventListener("click", copyToClipboardTSV);
|
| 275 |
clearBtn.addEventListener("click", ()=>{
|
| 276 |
rawEl.value = ""; document.getElementById("tbody").innerHTML = "";
|
| 277 |
+
updateCount(0); updateBadge(0); setButtonsEnabled(false);
|
| 278 |
});
|
| 279 |
sampleBtn.addEventListener("click", ()=>{ rawEl.value = SAMPLE; });
|
| 280 |
|
| 281 |
+
// اختصارات لوحة المفاتيح
|
| 282 |
+
document.addEventListener("keydown", (e)=>{
|
| 283 |
+
const ctrl = e.ctrlKey || e.metaKey;
|
| 284 |
+
if(ctrl && e.key === "Enter"){ e.preventDefault(); parseBtn.click(); }
|
| 285 |
+
else if(ctrl && e.key.toLowerCase() === "e"){ e.preventDefault(); exportBtn.click(); }
|
| 286 |
+
else if(ctrl && e.shiftKey && e.key.toLowerCase() === "c"){ e.preventDefault(); copyBtn.click(); }
|
| 287 |
+
else if(e.key === "Escape"){ e.preventDefault(); clearBtn.click(); }
|
| 288 |
+
});
|
| 289 |
+
|
| 290 |
setButtonsEnabled(false); // مبدئيًا
|
| 291 |
}
|
| 292 |
+
init(); // لدينا defer في index.html
|