Xóa scene con mà không xóa scene cha
This commit is contained in:
+42
-8
@@ -974,9 +974,46 @@ function closeActionModal() {
|
||||
/**
|
||||
* Mở modal xác nhận xóa scene
|
||||
*/
|
||||
window.deleteScene = function(sceneId) {
|
||||
window.deleteScene = async function(sceneId, sceneData = null) { // Thêm sceneData để tránh fetch lại
|
||||
sceneIdToDelete = sceneId;
|
||||
document.getElementById('delete-scene-confirm-modal').style.display = 'flex';
|
||||
const confirmModal = document.getElementById('delete-scene-confirm-modal');
|
||||
const confirmMessageElem = document.getElementById('delete-scene-confirm-message'); // Giả định có element này trong HTML
|
||||
|
||||
if (!confirmModal || !confirmMessageElem) {
|
||||
console.error("Delete confirmation modal elements not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('jwt');
|
||||
if (!token) {
|
||||
showNotification('Vui lòng đăng nhập để thực hiện thao tác này.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
let sceneToConfirm = sceneData;
|
||||
if (!sceneToConfirm) {
|
||||
try {
|
||||
// Fetch scene details nếu chưa có sẵn (ví dụ: xóa từ bản đồ)
|
||||
const response = await fetch(`${API_BASE_URL}/scenes/${sceneId}`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
sceneToConfirm = await response.json();
|
||||
|
||||
if (!response.ok) throw new Error(sceneToConfirm.message || 'Failed to fetch scene details for deletion.');
|
||||
} catch (error) {
|
||||
showNotification("Không thể chuẩn bị xóa scene: " + error.message, 'error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let message = '';
|
||||
if (sceneToConfirm.isChildScene) {
|
||||
message = `Bạn đang xóa cảnh "${sceneToConfirm.name || sceneToConfirm.title}". Cảnh này là một phần của tour khác. Việc xóa sẽ chỉ gỡ bỏ cảnh này và các liên kết đến nó. Các cảnh cha sẽ không bị ảnh hưởng. Bạn có chắc chắn muốn xóa?`;
|
||||
} else {
|
||||
message = `Bạn đang xóa cảnh "${sceneToConfirm.name || sceneToConfirm.title}". Cảnh này có thể là cảnh gốc hoặc cảnh không có liên kết đến. Việc xóa sẽ gỡ bỏ cảnh này VÀ TẤT CẢ CÁC CẢNH CON liên kết với nó trong tour. Thao tác này không thể hoàn tác. Bạn có chắc chắn muốn xóa?`;
|
||||
}
|
||||
confirmMessageElem.innerText = message;
|
||||
confirmModal.style.display = 'flex';
|
||||
};
|
||||
|
||||
window.closeDeleteSceneModal = function() {
|
||||
@@ -1549,12 +1586,9 @@ async function loadMyScenes() {
|
||||
openEditMetadataModal(scene, scene.isChildScene);
|
||||
};
|
||||
|
||||
// Xử lý nút Xóa (Sẽ được hoàn thiện ở Bước 4)
|
||||
document.getElementById(`delete-scene-${scene._id}`).onclick = () => {
|
||||
dashboardReturnTab = 'my-scenes';
|
||||
returnToDashboardAfterEdit = true;
|
||||
closeDashboard();
|
||||
deleteScene(scene._id);
|
||||
// Xử lý nút Xóa
|
||||
document.getElementById(`delete-scene-${scene._id}`).onclick = async () => {
|
||||
await deleteScene(scene._id, scene); // Truyền đối tượng scene đầy đủ
|
||||
};
|
||||
|
||||
// Xử lý nút Thống kê
|
||||
|
||||
Reference in New Issue
Block a user