feat: upgrade to SQLite session & data store with zero-data-loss migration, dark theme, and Turkish i18n
This commit is contained in:
parent
1af973d001
commit
56274f479b
27 changed files with 4222 additions and 1360 deletions
|
|
@ -18,6 +18,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
let currentSearch = '';
|
||||
let currentSubject = '';
|
||||
|
||||
function t(key, params) {
|
||||
if (typeof window.BeKulturT === 'function') {
|
||||
return window.BeKulturT(key, params);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
// Checkbox toggle
|
||||
if (assignmentList) {
|
||||
assignmentList.addEventListener('click', async (e) => {
|
||||
|
|
@ -26,7 +33,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
// Exclude / Restore button
|
||||
if (target.classList.contains('btn-exclude') || target.classList.contains('btn-disinclude')) {
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
alert('Çevrimdışı moddasınız. Ödev gizleme/geri alma işlemi için internet bağlantısı gereklidir.');
|
||||
alert(t('dashboard.offlineExcludeAlert'));
|
||||
return;
|
||||
}
|
||||
const assignmentId = target.dataset.id;
|
||||
|
|
@ -47,8 +54,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (data.success && data.stats) {
|
||||
card.dataset.excluded = newExcluded ? 'true' : 'false';
|
||||
card.classList.toggle('is-excluded', newExcluded);
|
||||
target.textContent = newExcluded ? 'Restore' : 'Exclude';
|
||||
target.title = newExcluded ? 'Restore this homework to your active list' : 'Exclude this homework (e.g. from another class)';
|
||||
target.textContent = newExcluded ? t('dashboard.btnRestore') : t('dashboard.btnExclude');
|
||||
target.title = newExcluded ? t('dashboard.btnRestoreTitle') : t('dashboard.btnExcludeTitle');
|
||||
|
||||
const checkbox = card.querySelector('.assignment-toggle');
|
||||
if (checkbox) checkbox.disabled = newExcluded;
|
||||
|
|
@ -59,7 +66,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (badgesContainer) {
|
||||
const b = document.createElement('span');
|
||||
b.className = 'badge badge-excluded';
|
||||
b.textContent = 'Excluded';
|
||||
b.textContent = t('dashboard.badgeExcluded');
|
||||
badgesContainer.insertBefore(b, target);
|
||||
}
|
||||
} else if (!newExcluded && badgeExcluded) {
|
||||
|
|
@ -84,7 +91,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
target.checked = !target.checked;
|
||||
alert('Çevrimdışı moddasınız. Ödev durumu internet bağlantısı olmadan değiştirilemez.');
|
||||
alert(t('dashboard.offlineToggleAlert'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -131,21 +138,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (existingStatusBadge) {
|
||||
if (status === 'completed') {
|
||||
existingStatusBadge.className = 'badge badge-completed';
|
||||
existingStatusBadge.textContent = 'Done';
|
||||
existingStatusBadge.textContent = t('dashboard.badgeCompleted');
|
||||
} else {
|
||||
const orig = card.dataset.status;
|
||||
if (orig === 'next-week') {
|
||||
existingStatusBadge.className = 'badge badge-next-week';
|
||||
existingStatusBadge.textContent = 'Next Week';
|
||||
existingStatusBadge.textContent = t('dashboard.badgeNextWeek');
|
||||
} else if (orig === 'due-soon') {
|
||||
existingStatusBadge.className = 'badge badge-due-soon';
|
||||
existingStatusBadge.textContent = 'Due Soon';
|
||||
existingStatusBadge.textContent = t('dashboard.badgeDueSoon');
|
||||
} else if (orig === 'overdue') {
|
||||
existingStatusBadge.className = 'badge badge-overdue';
|
||||
existingStatusBadge.textContent = 'Overdue';
|
||||
existingStatusBadge.textContent = t('dashboard.badgeOverdue');
|
||||
} else {
|
||||
existingStatusBadge.className = 'badge badge-active';
|
||||
existingStatusBadge.textContent = 'Active';
|
||||
existingStatusBadge.textContent = t('dashboard.badgeActive');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +169,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
const statTotal = document.getElementById('statTotalCount');
|
||||
|
||||
if (statCompRate) statCompRate.textContent = `${stats.completionRate}%`;
|
||||
if (statCompFrac) statCompFrac.textContent = `${stats.completed} / ${stats.total} done`;
|
||||
if (statCompFrac) statCompFrac.textContent = `${stats.completed} / ${stats.total} ${t('dashboard.statDoneUnit')}`;
|
||||
if (progressBar) progressBar.style.width = `${stats.completionRate}%`;
|
||||
if (statActive) statActive.textContent = stats.active;
|
||||
if (statNextWeek) statNextWeek.textContent = stats.checkedNextWeek;
|
||||
|
|
@ -310,7 +317,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
});
|
||||
|
||||
if (filteredCountText) {
|
||||
filteredCountText.textContent = `Showing ${visibleCount} assignments`;
|
||||
filteredCountText.textContent = t('dashboard.showingCount', { count: visibleCount });
|
||||
}
|
||||
|
||||
if (noResults) {
|
||||
|
|
@ -322,12 +329,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (btnSyncRecent) {
|
||||
btnSyncRecent.addEventListener('click', async () => {
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
showAlert('Çevrimdışı moddasınız. Senkronizasyon için internet bağlantısı gereklidir.', 'danger');
|
||||
showAlert(t('dashboard.offlineSyncAlert'), 'danger');
|
||||
return;
|
||||
}
|
||||
btnSyncRecent.disabled = true;
|
||||
btnSyncRecent.textContent = 'Syncing...';
|
||||
showAlert('Fetching recent assignments...', 'info');
|
||||
btnSyncRecent.textContent = t('dashboard.syncing');
|
||||
showAlert(t('dashboard.fetchingRecent'), 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sync', { method: 'POST' });
|
||||
|
|
@ -335,14 +342,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync failed: ${data.error}`, 'danger');
|
||||
showAlert(`${t('dashboard.syncFailed')} ${data.error}`, 'danger');
|
||||
btnSyncRecent.disabled = false;
|
||||
btnSyncRecent.textContent = 'Sync Recent';
|
||||
btnSyncRecent.textContent = t('dashboard.syncRecent');
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing.', 'danger');
|
||||
showAlert(t('dashboard.networkError'), 'danger');
|
||||
btnSyncRecent.disabled = false;
|
||||
btnSyncRecent.textContent = 'Sync Recent';
|
||||
btnSyncRecent.textContent = t('dashboard.syncRecent');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -350,12 +357,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (btnSyncAll) {
|
||||
btnSyncAll.addEventListener('click', async () => {
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
showAlert('Çevrimdışı moddasınız. Senkronizasyon için internet bağlantısı gereklidir.', 'danger');
|
||||
showAlert(t('dashboard.offlineSyncAlert'), 'danger');
|
||||
return;
|
||||
}
|
||||
btnSyncAll.disabled = true;
|
||||
btnSyncAll.textContent = 'Syncing all...';
|
||||
showAlert('Syncing full history from portal...', 'info');
|
||||
btnSyncAll.textContent = t('dashboard.syncingAll');
|
||||
showAlert(t('dashboard.fetchingAll'), 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sync-all', { method: 'POST' });
|
||||
|
|
@ -363,14 +370,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync all failed: ${data.error}`, 'danger');
|
||||
showAlert(`${t('dashboard.syncFailed')} ${data.error}`, 'danger');
|
||||
btnSyncAll.disabled = false;
|
||||
btnSyncAll.textContent = 'Sync Full History';
|
||||
btnSyncAll.textContent = t('dashboard.syncAll');
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing full history.', 'danger');
|
||||
showAlert(t('dashboard.networkError'), 'danger');
|
||||
btnSyncAll.disabled = false;
|
||||
btnSyncAll.textContent = 'Sync Full History';
|
||||
btnSyncAll.textContent = t('dashboard.syncAll');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
const modalTypeBtns = document.querySelectorAll('.modal-type-btn');
|
||||
const questionsGrid = document.getElementById('questionsGrid');
|
||||
const mistakeLoading = document.getElementById('mistakeLoading');
|
||||
const mistakeModalTitle = document.getElementById('mistakeModalTitle');
|
||||
const mistakeModalSubtitle = document.getElementById('mistakeModalSubtitle');
|
||||
|
||||
// Lightbox
|
||||
const imageLightbox = document.getElementById('imageLightbox');
|
||||
|
|
@ -39,6 +37,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
let activeTypeFilter = 'all'; // 'all' | 'wrong' | 'empty'
|
||||
let cachedWeaknesses = null;
|
||||
|
||||
function t(key, params) {
|
||||
if (typeof window.BeKulturT === 'function') {
|
||||
return window.BeKulturT(key, params);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Helper: Show Alert
|
||||
// ----------------------------------------------------
|
||||
|
|
@ -97,14 +102,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
// ----------------------------------------------------
|
||||
async function handleSync() {
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
showAlert('Çevrimdışı moddasınız. Sınav senkronizasyonu için internet bağlantısı gereklidir.', 'danger');
|
||||
showAlert(t('dashboard.offlineSyncAlert'), 'danger');
|
||||
return;
|
||||
}
|
||||
|
||||
const triggerBtn = btnSyncExams || btnEmptySync;
|
||||
if (triggerBtn) {
|
||||
triggerBtn.disabled = true;
|
||||
triggerBtn.textContent = 'Syncing...';
|
||||
triggerBtn.textContent = t('exams.syncing');
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -117,17 +122,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(data.error || 'Failed to sync exams', 'danger');
|
||||
showAlert(data.error || t('dashboard.syncFailed'), 'danger');
|
||||
if (triggerBtn) {
|
||||
triggerBtn.disabled = false;
|
||||
triggerBtn.textContent = 'Sync Exams';
|
||||
triggerBtn.textContent = t('exams.syncBtn');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Connection error while syncing exams.', 'danger');
|
||||
showAlert(t('dashboard.networkError'), 'danger');
|
||||
if (triggerBtn) {
|
||||
triggerBtn.disabled = false;
|
||||
triggerBtn.textContent = 'Sync Exams';
|
||||
triggerBtn.textContent = t('exams.syncBtn');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,14 +178,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
} else {
|
||||
weaknessContainer.innerHTML = `
|
||||
<div class="empty-lessons-card">
|
||||
<p>Bu sınav için henüz zayıf konu kaydı bulunamadı veya tüm konularda tam başarı sağlandı.</p>
|
||||
<p>${escapeHtml(t('exams.weaknessEmpty'))}</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
} catch (err) {
|
||||
weaknessLoading.classList.add('hidden');
|
||||
weaknessContainer.innerHTML = `
|
||||
<div class="alert alert-danger">Zayıf konu raporu yüklenirken bir hata oluştu.</div>
|
||||
<div class="alert alert-danger">${escapeHtml(t('exams.weaknessError'))}</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
|
@ -206,10 +211,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
<div class="score-progress-fill ${fillClass}" style="width: ${item.successRate}%;"></div>
|
||||
</div>
|
||||
<div class="weakness-stats">
|
||||
<span>Toplam: <strong>${item.totalCount}</strong></span>
|
||||
<span class="text-success">Doğru: <strong>${item.correctCount}</strong></span>
|
||||
<span class="text-danger">Yanlış: <strong>${item.wrongCount}</strong></span>
|
||||
<span class="text-muted">Boş: <strong>${item.emptyCount}</strong></span>
|
||||
<span>${escapeHtml(t('exams.weaknessTotal'))} <strong>${item.totalCount}</strong></span>
|
||||
<span class="text-success">${escapeHtml(t('exams.weaknessCorrect'))} <strong>${item.correctCount}</strong></span>
|
||||
<span class="text-danger">${escapeHtml(t('exams.weaknessWrong'))} <strong>${item.wrongCount}</strong></span>
|
||||
<span class="text-muted">${escapeHtml(t('exams.weaknessEmptyCount'))} <strong>${item.emptyCount}</strong></span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
|
@ -340,7 +345,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
} catch (err) {
|
||||
mistakeLoading.classList.add('hidden');
|
||||
questionsGrid.innerHTML = `
|
||||
<div class="alert alert-danger">Sorular yüklenirken bir hata oluştu.</div>
|
||||
<div class="alert alert-danger">${escapeHtml(t('exams.modalError'))}</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
|
@ -355,7 +360,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
let html = `
|
||||
<button type="button" class="modal-lesson-btn ${activeLessonFilter === 'ALL' ? 'active' : ''}" data-lesson="ALL">
|
||||
Tüm Yanlışlar (${totalAll})
|
||||
${escapeHtml(t('exams.modalAllMistakes'))} (${totalAll})
|
||||
</button>
|
||||
`;
|
||||
|
||||
|
|
@ -419,7 +424,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (filteredList.length === 0) {
|
||||
questionsGrid.innerHTML = `
|
||||
<div class="empty-lessons-card" style="grid-column: 1 / -1;">
|
||||
<p>Seçili filtrelere uygun soru bulunamadı.</p>
|
||||
<p>${escapeHtml(t('exams.modalNoMatch'))}</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
|
|
@ -429,32 +434,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
filteredList.forEach(q => {
|
||||
const isWrong = q.status === 'wrong';
|
||||
const studentClass = isWrong ? 'answer-student-wrong' : 'answer-student-empty';
|
||||
const studentText = isWrong ? q.studentAnswer : 'Boş';
|
||||
const studentText = isWrong ? q.studentAnswer : t('exams.emptyAnswerText');
|
||||
|
||||
html += `
|
||||
<div class="question-card">
|
||||
<div class="question-card-header">
|
||||
<span class="question-no-badge">Soru #${q.questionNumber}</span>
|
||||
<span class="question-no-badge">${escapeHtml(t('exams.questionNo', { num: q.questionNumber }))}</span>
|
||||
<span class="question-subject-badge">${escapeHtml(q.subjectName || '')}</span>
|
||||
</div>
|
||||
|
||||
<div class="question-card-answers">
|
||||
<span class="answer-pill answer-correct">
|
||||
Doğru: <strong>${escapeHtml(q.correctAnswer)}</strong>
|
||||
${escapeHtml(t('exams.correctAnswer'))} <strong>${escapeHtml(q.correctAnswer)}</strong>
|
||||
</span>
|
||||
<span class="answer-pill ${studentClass}">
|
||||
Öğrenci: <strong>${escapeHtml(studentText)}</strong>
|
||||
${escapeHtml(t('exams.studentAnswer'))} <strong>${escapeHtml(studentText)}</strong>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
${
|
||||
q.imageUrl
|
||||
? `
|
||||
<div class="question-img-wrapper" title="Büyütmek için tıklayınız">
|
||||
<div class="question-img-wrapper" title="${escapeHtml(t('exams.zoomHint'))}">
|
||||
<img src="${escapeHtml(q.imageUrl)}" alt="Soru ${q.questionNumber}" class="question-img" loading="lazy" />
|
||||
</div>
|
||||
`
|
||||
: `<div class="text-muted small">Soru görseli bulunamadı.</div>`
|
||||
: `<div class="text-muted small">${escapeHtml(t('exams.noImage'))}</div>`
|
||||
}
|
||||
</div>
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
122
public/js/pwa.js
122
public/js/pwa.js
|
|
@ -1,10 +1,98 @@
|
|||
/**
|
||||
* BeKultur - PWA & Offline State Manager
|
||||
* BeKultur - PWA, Theme & Offline State Manager
|
||||
*/
|
||||
(function () {
|
||||
let isOffline = !navigator.onLine;
|
||||
let bannerTimeout = null;
|
||||
|
||||
function t(key, params) {
|
||||
if (typeof window.BeKulturT === 'function') {
|
||||
return window.BeKulturT(key, params);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// 0. Dark / Light Theme Manager (System-Aware + Override)
|
||||
// ----------------------------------------------------
|
||||
function getSystemScheme() {
|
||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light';
|
||||
}
|
||||
|
||||
function getStoredScheme() {
|
||||
try {
|
||||
const val = localStorage.getItem('color-scheme');
|
||||
if (val === 'dark' || val === 'light') return val;
|
||||
} catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getResolvedScheme() {
|
||||
return getStoredScheme() || getSystemScheme();
|
||||
}
|
||||
|
||||
function applyThemeScheme(storedOverride) {
|
||||
const meta = document.querySelector('meta[name="color-scheme"]');
|
||||
const resolved = storedOverride === 'dark' || storedOverride === 'light'
|
||||
? storedOverride
|
||||
: getSystemScheme();
|
||||
|
||||
if (meta) {
|
||||
meta.content = storedOverride === 'dark' || storedOverride === 'light'
|
||||
? storedOverride
|
||||
: 'light dark';
|
||||
}
|
||||
document.documentElement.setAttribute('data-theme', resolved);
|
||||
}
|
||||
|
||||
function initThemeToggle() {
|
||||
// Ensure initial attribute is synced
|
||||
applyThemeScheme(getStoredScheme());
|
||||
|
||||
const toggleBtn = document.getElementById('themeToggleBtn');
|
||||
if (toggleBtn) {
|
||||
toggleBtn.addEventListener('click', () => {
|
||||
const currentRendered = getResolvedScheme();
|
||||
const target = currentRendered === 'dark' ? 'light' : 'dark';
|
||||
const sys = getSystemScheme();
|
||||
|
||||
try {
|
||||
if (target === sys) {
|
||||
// Revert to system default when target matches system preference
|
||||
localStorage.removeItem('color-scheme');
|
||||
applyThemeScheme(null);
|
||||
} else {
|
||||
localStorage.setItem('color-scheme', target);
|
||||
applyThemeScheme(target);
|
||||
}
|
||||
} catch (e) {
|
||||
applyThemeScheme(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Listen for OS theme changes when following system default
|
||||
if (window.matchMedia) {
|
||||
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
if (mql.addEventListener) {
|
||||
mql.addEventListener('change', () => {
|
||||
if (!getStoredScheme()) {
|
||||
applyThemeScheme(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Keep tabs in sync
|
||||
window.addEventListener('storage', (e) => {
|
||||
if (e.key === 'color-scheme') {
|
||||
applyThemeScheme(getStoredScheme());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 1. Service Worker Registration
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
|
|
@ -50,8 +138,8 @@
|
|||
banner.className = 'offline-banner active';
|
||||
banner.innerHTML = `
|
||||
<div class="offline-banner-content">
|
||||
<span class="offline-badge-pill">⚡ Offline</span>
|
||||
<span class="offline-banner-text">Showing locally cached data. Actions requiring connection are paused.</span>
|
||||
<span class="offline-badge-pill">${t('pwa.offlineBadge')}</span>
|
||||
<span class="offline-banner-text">${t('pwa.offlineText')}</span>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
|
@ -65,8 +153,8 @@
|
|||
banner.className = 'offline-banner online';
|
||||
banner.innerHTML = `
|
||||
<div class="offline-banner-content">
|
||||
<span class="online-badge-pill">✓ Online</span>
|
||||
<span class="offline-banner-text">Connection restored. Live features re-enabled.</span>
|
||||
<span class="online-badge-pill">${t('pwa.onlineBadge')}</span>
|
||||
<span class="offline-banner-text">${t('pwa.onlineText')}</span>
|
||||
</div>
|
||||
`;
|
||||
bannerTimeout = setTimeout(() => {
|
||||
|
|
@ -93,7 +181,7 @@
|
|||
|
||||
if (offline) {
|
||||
checkbox.disabled = true;
|
||||
checkbox.title = 'Offline mode: Homework status cannot be changed without connection.';
|
||||
checkbox.title = t('pwa.offlineCheckboxTitle');
|
||||
} else {
|
||||
// Only re-enable if not excluded
|
||||
checkbox.disabled = isExcluded;
|
||||
|
|
@ -105,16 +193,17 @@
|
|||
excludeButtons.forEach((btn) => {
|
||||
if (offline) {
|
||||
btn.disabled = true;
|
||||
btn.title = 'Offline mode: Homework cannot be excluded without connection.';
|
||||
btn.title = t('pwa.offlineExcludeTitle');
|
||||
} else {
|
||||
btn.disabled = false;
|
||||
btn.title = btn.textContent.trim() === 'Restore' ? 'Restore homework' : 'Exclude homework';
|
||||
const card = btn.closest('.assignment-card');
|
||||
const isExcl = card && card.dataset.excluded === 'true';
|
||||
btn.title = isExcl ? t('dashboard.btnRestoreTitle') : t('dashboard.btnExcludeTitle');
|
||||
}
|
||||
});
|
||||
|
||||
// --- B. Private Lesson Request Form ---
|
||||
const lessonForm = document.getElementById('privateLessonForm');
|
||||
const btnSubmitLesson = document.getElementById('btnSubmitRequest');
|
||||
const formSelects = document.querySelectorAll('#privateLessonForm select, #privateLessonForm button[type="submit"]');
|
||||
|
||||
let noticeEl = document.getElementById('privateLessonOfflineNotice');
|
||||
|
|
@ -123,7 +212,7 @@
|
|||
noticeEl.id = 'privateLessonOfflineNotice';
|
||||
noticeEl.className = 'alert alert-warning hidden';
|
||||
noticeEl.style.marginBottom = '12px';
|
||||
noticeEl.innerHTML = '⚡ <strong>Çevrimdışı mod:</strong> Yeni özel ders başvurusu yapmak için internet bağlantısı gereklidir.';
|
||||
noticeEl.innerHTML = t('pwa.offlinePrivateNotice');
|
||||
lessonForm.prepend(noticeEl);
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +234,7 @@
|
|||
stationButtons.forEach((btn) => {
|
||||
if (offline) {
|
||||
btn.classList.add('station-btn-offline');
|
||||
btn.title = 'Offline mode: Station selection requires connection.';
|
||||
btn.title = t('pwa.offlineStationTitle');
|
||||
} else {
|
||||
btn.classList.remove('station-btn-offline');
|
||||
btn.title = '';
|
||||
|
|
@ -172,8 +261,8 @@
|
|||
}
|
||||
btn.disabled = true;
|
||||
btn.classList.add('btn-offline-disabled');
|
||||
btn.title = 'Offline mode: Sync requires internet connection.';
|
||||
btn.textContent = `${btn.dataset.onlineLabel} (Offline)`;
|
||||
btn.title = t('pwa.offlineSyncTitle');
|
||||
btn.textContent = `${btn.dataset.onlineLabel} ${t('pwa.offlineSuffix')}`;
|
||||
} else {
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('btn-offline-disabled');
|
||||
|
|
@ -195,7 +284,7 @@
|
|||
if (target.classList && target.classList.contains('assignment-toggle')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
alert('Çevrimdışı moddasınız. Ödev durumu internet bağlantısı olmadan değiştirilemez.');
|
||||
alert(t('dashboard.offlineToggleAlert'));
|
||||
}
|
||||
},
|
||||
true
|
||||
|
|
@ -213,11 +302,13 @@
|
|||
// 6. Initial Application on DOM Ready
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initThemeToggle();
|
||||
if (!navigator.onLine) {
|
||||
applyOfflineState(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
initThemeToggle();
|
||||
if (!navigator.onLine) {
|
||||
applyOfflineState(true);
|
||||
}
|
||||
|
|
@ -226,6 +317,7 @@
|
|||
// Export helper globally
|
||||
window.BeKulturPWA = {
|
||||
isOffline: () => isOffline,
|
||||
refreshState: () => applyOfflineState(!navigator.onLine)
|
||||
refreshState: () => applyOfflineState(!navigator.onLine),
|
||||
getTheme: () => getResolvedScheme()
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
const btnSyncSyllabus = document.getElementById('btnSyncSyllabus');
|
||||
const syllabusAlert = document.getElementById('syllabusAlert');
|
||||
|
||||
function t(key, params) {
|
||||
if (typeof window.BeKulturT === 'function') {
|
||||
return window.BeKulturT(key, params);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
// 1. Station Pill Selection (AJAX)
|
||||
if (stationPills) {
|
||||
stationPills.addEventListener('click', async (e) => {
|
||||
|
|
@ -14,7 +21,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (!btn) return;
|
||||
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
showAlert('Çevrimdışı moddasınız. İstasyon seçimi için internet bağlantısı gereklidir.', 'danger');
|
||||
showAlert(t('syllabus.offlineStationAlert'), 'danger');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -80,28 +87,28 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
if (btnSyncSyllabus) {
|
||||
btnSyncSyllabus.addEventListener('click', async () => {
|
||||
if (window.BeKulturPWA && window.BeKulturPWA.isOffline()) {
|
||||
showAlert('Çevrimdışı moddasınız. Senkronizasyon için internet bağlantısı gereklidir.', 'danger');
|
||||
showAlert(t('dashboard.offlineSyncAlert'), 'danger');
|
||||
return;
|
||||
}
|
||||
btnSyncSyllabus.disabled = true;
|
||||
btnSyncSyllabus.textContent = 'Syncing...';
|
||||
showAlert('Fetching weekly timetable across all 5 days...', 'info');
|
||||
btnSyncSyllabus.textContent = t('syllabus.syncing');
|
||||
showAlert(t('syllabus.fetchingAlert'), 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/syllabus/sync', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
showAlert('Syllabus updated successfully!', 'info');
|
||||
showAlert(t('syllabus.updatedAlert'), 'info');
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync failed: ${data.error}`, 'danger');
|
||||
showAlert(`${t('dashboard.syncFailed')} ${data.error}`, 'danger');
|
||||
btnSyncSyllabus.disabled = false;
|
||||
btnSyncSyllabus.textContent = 'Sync Syllabus';
|
||||
btnSyncSyllabus.textContent = t('syllabus.syncBtn');
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing syllabus.', 'danger');
|
||||
showAlert(t('dashboard.networkError'), 'danger');
|
||||
btnSyncSyllabus.disabled = false;
|
||||
btnSyncSyllabus.textContent = 'Sync Syllabus';
|
||||
btnSyncSyllabus.textContent = t('syllabus.syncBtn');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue