feat: upgrade to SQLite session & data store with zero-data-loss migration, dark theme, and Turkish i18n

This commit is contained in:
tyuXX 2026-11-09 20:54:26 +00:00
parent 1af973d001
commit 56274f479b
27 changed files with 4222 additions and 1360 deletions

View file

@ -13,6 +13,13 @@ document.addEventListener('DOMContentLoaded', () => {
const lessonCards = document.querySelectorAll('.lesson-card');
const sinifIdInput = document.getElementById('sinifId');
function t(key, params) {
if (typeof window.BeKulturT === 'function') {
return window.BeKulturT(key, params);
}
return key;
}
function showAlert(message, type = 'info', timeout = 4000) {
if (!alertBox) return;
alertBox.className = `alert alert-${type}`;
@ -44,9 +51,9 @@ document.addEventListener('DOMContentLoaded', () => {
const dersId = selectCourse.value;
const sinifId = sinifIdInput ? sinifIdInput.value : '';
selectUnit.innerHTML = '<option value="">Önce ders seçiniz...</option>';
selectUnit.innerHTML = `<option value="">${t('privateLessons.selectCourseFirst')}</option>`;
selectUnit.disabled = true;
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.innerHTML = `<option value="">${t('privateLessons.selectUnitFirst')}</option>`;
selectTopic.disabled = true;
if (btnSubmit) btnSubmit.disabled = true;
@ -59,7 +66,7 @@ document.addEventListener('DOMContentLoaded', () => {
const data = await res.json();
if (data.success && data.units && data.units.length > 0) {
selectUnit.innerHTML = '<option value="">Seçiniz...</option>';
selectUnit.innerHTML = `<option value="">${t('privateLessons.selectPrompt')}</option>`;
data.units.forEach(u => {
const opt = document.createElement('option');
opt.value = u.id;
@ -68,11 +75,11 @@ document.addEventListener('DOMContentLoaded', () => {
});
selectUnit.disabled = false;
} else {
selectUnit.innerHTML = '<option value="">Ünite bulunamadı</option>';
selectUnit.innerHTML = `<option value="">${t('privateLessons.noUnitFound')}</option>`;
}
} catch (err) {
console.error('Error fetching units:', err);
selectUnit.innerHTML = '<option value="">Hata oluştu</option>';
selectUnit.innerHTML = `<option value="">${t('privateLessons.errorOccurred')}</option>`;
} finally {
if (unitLoading) unitLoading.classList.add('hidden');
}
@ -85,7 +92,7 @@ document.addEventListener('DOMContentLoaded', () => {
hideFeedback();
const uniteId = selectUnit.value;
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.innerHTML = `<option value="">${t('privateLessons.selectUnitFirst')}</option>`;
selectTopic.disabled = true;
if (btnSubmit) btnSubmit.disabled = true;
@ -98,20 +105,20 @@ document.addEventListener('DOMContentLoaded', () => {
const data = await res.json();
if (data.success && data.topics && data.topics.length > 0) {
selectTopic.innerHTML = '<option value="">Seçiniz...</option>';
data.topics.forEach(t => {
selectTopic.innerHTML = `<option value="">${t('privateLessons.selectPrompt')}</option>`;
data.topics.forEach(tItem => {
const opt = document.createElement('option');
opt.value = t.id;
opt.textContent = t.name;
opt.value = tItem.id;
opt.textContent = tItem.name;
selectTopic.appendChild(opt);
});
selectTopic.disabled = false;
} else {
selectTopic.innerHTML = '<option value="">Konu bulunamadı</option>';
selectTopic.innerHTML = `<option value="">${t('privateLessons.noTopicFound')}</option>`;
}
} catch (err) {
console.error('Error fetching topics:', err);
selectTopic.innerHTML = '<option value="">Hata oluştu</option>';
selectTopic.innerHTML = `<option value="">${t('privateLessons.errorOccurred')}</option>`;
} finally {
if (topicLoading) topicLoading.classList.add('hidden');
}
@ -134,7 +141,7 @@ document.addEventListener('DOMContentLoaded', () => {
hideFeedback();
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
showFeedback('Çevrimdışı moddasınız. Yeni özel ders başvurusu yapmak için internet bağlantısı gereklidir.', 'error');
showFeedback(t('dashboard.offlineSyncAlert'), 'error');
return;
}
@ -152,7 +159,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (btnSubmit) {
btnSubmit.disabled = true;
btnSubmit.textContent = 'Gönderiliyor...';
btnSubmit.textContent = t('privateLessons.submittingBtn');
}
try {
@ -167,9 +174,9 @@ document.addEventListener('DOMContentLoaded', () => {
if (data.success) {
showFeedback(data.message || 'Özel ders talebiniz başarıyla iletildi!', 'success');
// Reset select elements
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.innerHTML = `<option value="">${t('privateLessons.selectUnitFirst')}</option>`;
selectTopic.disabled = true;
selectUnit.innerHTML = '<option value="">Önce ders seçiniz...</option>';
selectUnit.innerHTML = `<option value="">${t('privateLessons.selectCourseFirst')}</option>`;
selectUnit.disabled = true;
selectCourse.value = '';
} else {
@ -180,7 +187,7 @@ document.addEventListener('DOMContentLoaded', () => {
showFeedback('Bağlantı hatası oluştu. Lütfen tekrar deneyiniz.', 'error');
} finally {
if (btnSubmit) {
btnSubmit.textContent = 'Submit Request (Gönder)';
btnSubmit.textContent = t('privateLessons.submitBtn');
}
}
});
@ -208,26 +215,30 @@ document.addEventListener('DOMContentLoaded', () => {
// 6. Sync Lessons
if (btnSync) {
btnSync.addEventListener('click', async () => {
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
showAlert(t('dashboard.offlineSyncAlert'), 'danger');
return;
}
btnSync.disabled = true;
btnSync.textContent = 'Syncing...';
btnSync.textContent = t('privateLessons.syncing');
try {
const res = await fetch('/api/private-lessons/sync', { method: 'POST' });
const data = await res.json();
if (data.success) {
showAlert(`Successfully refreshed ${data.count} private lesson records.`, 'success');
showAlert(t('privateLessons.syncSuccess', { count: data.count }), 'info');
setTimeout(() => {
window.location.reload();
}, 800);
} else {
showAlert(data.error || 'Sync failed.', 'danger');
showAlert(data.error || t('dashboard.syncFailed'), 'danger');
}
} catch (err) {
showAlert('Network error while syncing private lessons.', 'danger');
showAlert(t('dashboard.networkError'), 'danger');
} finally {
btnSync.disabled = false;
btnSync.textContent = 'Sync Lessons';
btnSync.textContent = t('privateLessons.syncBtn');
}
});
}