Spaces:
Running
Running
Upload 10 files
Browse files- src/views/InstructorView.js +69 -39
src/views/InstructorView.js
CHANGED
|
@@ -299,10 +299,10 @@ export async function renderInstructorView() {
|
|
| 299 |
<button id="group-photo-btn" class="hidden bg-gradient-to-r from-pink-600 to-purple-600 hover:from-pink-500 hover:to-purple-500 text-white font-bold py-2 px-4 rounded-lg transition-all shadow-lg border border-pink-400/30 flex items-center space-x-2">
|
| 300 |
<span>📸 大合照</span>
|
| 301 |
</button>
|
| 302 |
-
<button id="nav-instructors-btn" class="hidden bg-indigo-600 hover:bg-indigo-500 text-white font-bold py-2 px-4 rounded-lg transition-all border border-indigo-400/30 mr-2">
|
| 303 |
👥 管理講師
|
| 304 |
</button>
|
| 305 |
-
<button id="nav-admin-btn" class="hidden bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-lg transition-all border border-gray-600">
|
| 306 |
管理題目
|
| 307 |
</button>
|
| 308 |
<div id="create-room-container" class="flex items-center space-x-2">
|
|
@@ -802,31 +802,38 @@ const checkPermissions = (instructor) => {
|
|
| 802 |
|
| 803 |
currentInstructor = instructor;
|
| 804 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 805 |
// 1. Create Room Permission
|
| 806 |
-
if (
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
|
|
|
|
|
|
| 813 |
}
|
| 814 |
|
| 815 |
// 2. Add Question Permission (Admin Button)
|
| 816 |
-
if (
|
| 817 |
if (instructor.permissions?.includes('add_question')) {
|
| 818 |
-
|
| 819 |
} else {
|
| 820 |
-
|
| 821 |
}
|
| 822 |
}
|
| 823 |
|
| 824 |
// 3. Manage Instructors Permission
|
| 825 |
-
if (
|
| 826 |
if (instructor.permissions?.includes('manage_instructors')) {
|
| 827 |
-
|
| 828 |
} else {
|
| 829 |
-
|
| 830 |
}
|
| 831 |
}
|
| 832 |
};
|
|
@@ -1394,34 +1401,57 @@ if (navInstBtn) {
|
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1397 |
const btnAddInst = document.getElementById('btn-add-inst');
|
| 1398 |
if (btnAddInst) {
|
| 1399 |
-
btnAddInst.
|
| 1400 |
-
const email = document.getElementById('new-inst-email').value.trim();
|
| 1401 |
-
const name = document.getElementById('new-inst-name').value.trim();
|
| 1402 |
-
const perms = [];
|
| 1403 |
-
if (document.getElementById('perm-room').checked) perms.push('create_room');
|
| 1404 |
-
if (document.getElementById('perm-q').checked) perms.push('add_question');
|
| 1405 |
-
if (document.getElementById('perm-inst').checked) perms.push('manage_instructors');
|
| 1406 |
-
|
| 1407 |
-
if (!email || !name) {
|
| 1408 |
-
alert("請輸入 Email 和姓名");
|
| 1409 |
-
return;
|
| 1410 |
-
}
|
| 1411 |
-
|
| 1412 |
-
try {
|
| 1413 |
-
await addInstructor(email, name, perms);
|
| 1414 |
-
alert("新增成功");
|
| 1415 |
-
document.getElementById('new-inst-email').value = '';
|
| 1416 |
-
document.getElementById('new-inst-name').value = '';
|
| 1417 |
-
loadInstructorList();
|
| 1418 |
-
} catch (e) {
|
| 1419 |
-
console.error(e);
|
| 1420 |
-
alert("新增失敗: " + e.message);
|
| 1421 |
-
}
|
| 1422 |
-
});
|
| 1423 |
}
|
| 1424 |
|
|
|
|
| 1425 |
window.removeInst = async (email) => {
|
| 1426 |
if (confirm(`確定要移除 ${email} 嗎?`)) {
|
| 1427 |
try {
|
|
|
|
| 299 |
<button id="group-photo-btn" class="hidden bg-gradient-to-r from-pink-600 to-purple-600 hover:from-pink-500 hover:to-purple-500 text-white font-bold py-2 px-4 rounded-lg transition-all shadow-lg border border-pink-400/30 flex items-center space-x-2">
|
| 300 |
<span>📸 大合照</span>
|
| 301 |
</button>
|
| 302 |
+
<button id="nav-instructors-btn" onclick="window.openInstructorPanel()" class="hidden bg-indigo-600 hover:bg-indigo-500 text-white font-bold py-2 px-4 rounded-lg transition-all border border-indigo-400/30 mr-2">
|
| 303 |
👥 管理講師
|
| 304 |
</button>
|
| 305 |
+
<button id="nav-admin-btn" onclick="window.openAdminPanel()" class="hidden bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-lg transition-all border border-gray-600">
|
| 306 |
管理題目
|
| 307 |
</button>
|
| 308 |
<div id="create-room-container" class="flex items-center space-x-2">
|
|
|
|
| 802 |
|
| 803 |
currentInstructor = instructor;
|
| 804 |
|
| 805 |
+
// UI References (Live Query)
|
| 806 |
+
const liveCreateBtn = document.getElementById('create-room-btn');
|
| 807 |
+
const liveNavAdminBtn = document.getElementById('nav-admin-btn');
|
| 808 |
+
const liveNavInstBtn = document.getElementById('nav-instructors-btn');
|
| 809 |
+
|
| 810 |
// 1. Create Room Permission
|
| 811 |
+
if (liveCreateBtn) {
|
| 812 |
+
if (instructor.permissions?.includes('create_room')) {
|
| 813 |
+
liveCreateBtn.classList.remove('hidden', 'opacity-50', 'cursor-not-allowed');
|
| 814 |
+
liveCreateBtn.disabled = false;
|
| 815 |
+
} else {
|
| 816 |
+
liveCreateBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
| 817 |
+
liveCreateBtn.disabled = true;
|
| 818 |
+
liveCreateBtn.title = "無此權限";
|
| 819 |
+
}
|
| 820 |
}
|
| 821 |
|
| 822 |
// 2. Add Question Permission (Admin Button)
|
| 823 |
+
if (liveNavAdminBtn) {
|
| 824 |
if (instructor.permissions?.includes('add_question')) {
|
| 825 |
+
liveNavAdminBtn.classList.remove('hidden');
|
| 826 |
} else {
|
| 827 |
+
liveNavAdminBtn.classList.add('hidden');
|
| 828 |
}
|
| 829 |
}
|
| 830 |
|
| 831 |
// 3. Manage Instructors Permission
|
| 832 |
+
if (liveNavInstBtn) {
|
| 833 |
if (instructor.permissions?.includes('manage_instructors')) {
|
| 834 |
+
liveNavInstBtn.classList.remove('hidden');
|
| 835 |
} else {
|
| 836 |
+
liveNavInstBtn.classList.add('hidden');
|
| 837 |
}
|
| 838 |
}
|
| 839 |
};
|
|
|
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
+
// Expose Nav Functions Globally
|
| 1405 |
+
window.openAdminPanel = () => {
|
| 1406 |
+
// Validation handled by UI visibility, but double check
|
| 1407 |
+
if (!currentInstructor?.permissions?.includes('add_question')) return alert("無權限");
|
| 1408 |
+
|
| 1409 |
+
// Use a simple prompt for now or open a modal
|
| 1410 |
+
// For now, let's just toggle the admin view (or navigate)
|
| 1411 |
+
// Since we reverted AdminView, we might just show an alert or a different modal
|
| 1412 |
+
// Based on original code, it seemed to just show an alert or navigate?
|
| 1413 |
+
alert("管理功能尚未開放 (Admin Function Placeholder)");
|
| 1414 |
+
};
|
| 1415 |
+
|
| 1416 |
+
window.openInstructorPanel = async () => {
|
| 1417 |
+
if (!currentInstructor?.permissions?.includes('manage_instructors')) return alert("無權限");
|
| 1418 |
+
|
| 1419 |
+
const modal = document.getElementById('instructor-modal');
|
| 1420 |
+
if (modal) {
|
| 1421 |
+
modal.classList.remove('hidden');
|
| 1422 |
+
await loadInstructorList();
|
| 1423 |
+
}
|
| 1424 |
+
};
|
| 1425 |
+
|
| 1426 |
+
// Add Instructor Event
|
| 1427 |
+
window.addInstructorHandler = async () => {
|
| 1428 |
+
const email = document.getElementById('new-inst-email').value.trim();
|
| 1429 |
+
const name = document.getElementById('new-inst-name').value.trim();
|
| 1430 |
+
const perms = [];
|
| 1431 |
+
if (document.getElementById('perm-room').checked) perms.push('create_room');
|
| 1432 |
+
if (document.getElementById('perm-q').checked) perms.push('add_question');
|
| 1433 |
+
if (document.getElementById('perm-inst').checked) perms.push('manage_instructors');
|
| 1434 |
+
|
| 1435 |
+
if (!email || !name) return alert("請輸入完整資料");
|
| 1436 |
+
|
| 1437 |
+
try {
|
| 1438 |
+
await addInstructor(email, name, perms);
|
| 1439 |
+
alert("新增成功");
|
| 1440 |
+
await loadInstructorList(); // Reload
|
| 1441 |
+
document.getElementById('new-inst-email').value = '';
|
| 1442 |
+
document.getElementById('new-inst-name').value = '';
|
| 1443 |
+
} catch (e) {
|
| 1444 |
+
console.error(e);
|
| 1445 |
+
alert("新增失敗: " + e.message);
|
| 1446 |
+
}
|
| 1447 |
+
};
|
| 1448 |
+
|
| 1449 |
const btnAddInst = document.getElementById('btn-add-inst');
|
| 1450 |
if (btnAddInst) {
|
| 1451 |
+
btnAddInst.onclick = window.addInstructorHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1452 |
}
|
| 1453 |
|
| 1454 |
+
|
| 1455 |
window.removeInst = async (email) => {
|
| 1456 |
if (confirm(`確定要移除 ${email} 嗎?`)) {
|
| 1457 |
try {
|