clear2
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
// auth.js - Аутентификация и авторизация
|
||||
let currentUser = null;
|
||||
|
||||
async function checkAuth() {
|
||||
try {
|
||||
const response = await fetch('/api/user');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
showMainInterface();
|
||||
} else {
|
||||
showLoginInterface();
|
||||
}
|
||||
} catch (error) {
|
||||
showLoginInterface();
|
||||
}
|
||||
}
|
||||
|
||||
function showLoginInterface() {
|
||||
document.getElementById('login-modal').style.display = 'block';
|
||||
document.querySelector('.container').style.display = 'none';
|
||||
}
|
||||
|
||||
function showMainInterface() {
|
||||
document.getElementById('login-modal').style.display = 'none';
|
||||
document.querySelector('.container').style.display = 'block';
|
||||
|
||||
let userInfo = `Вы вошли как: ${currentUser.name}`;
|
||||
if (currentUser.auth_type === 'ldap') {
|
||||
userInfo += ` (LDAP)`;
|
||||
}
|
||||
|
||||
// Показываем только группы, которые влияют на роль
|
||||
if (currentUser.groups && currentUser.groups.length > 0) {
|
||||
// Получаем все группы ролей из конфигурации
|
||||
const roleGroups = [];
|
||||
|
||||
// Администраторы
|
||||
if (window.ALLOWED_GROUPS) {
|
||||
roleGroups.push(...window.ALLOWED_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// Секретари
|
||||
if (window.SECRETARY_GROUPS) {
|
||||
roleGroups.push(...window.SECRETARY_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// Группа помощи
|
||||
if (window.HELP_GROUPS) {
|
||||
roleGroups.push(...window.HELP_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// IT поддержка
|
||||
if (window.ITHELP_GROUPS) {
|
||||
roleGroups.push(...window.ITHELP_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// Заявки
|
||||
if (window.REQUEST_GROUPS) {
|
||||
roleGroups.push(...window.REQUEST_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// Задачи
|
||||
if (window.TASKS_GROUPS) {
|
||||
roleGroups.push(...window.TASKS_GROUPS.split(',').map(g => g.trim()));
|
||||
}
|
||||
|
||||
// Фильтруем группы пользователя, оставляя только те, что влияют на роль
|
||||
const relevantGroups = currentUser.groups.filter(group =>
|
||||
roleGroups.includes(group)
|
||||
);
|
||||
|
||||
// Также всегда показываем роль пользователя
|
||||
if (currentUser.role) {
|
||||
userInfo += ` | Роль: ${getRoleDisplayName(currentUser.role)}`;
|
||||
}
|
||||
|
||||
// Показываем группы только если есть релевантные
|
||||
if (relevantGroups.length > 0) {
|
||||
userInfo += ` | Группы ролей: ${relevantGroups.join(', ')}`;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('current-user').textContent = userInfo;
|
||||
|
||||
document.getElementById('tasks-controls').style.display = 'block';
|
||||
|
||||
const showDeletedLabel = document.querySelector('.show-deleted-label');
|
||||
if (showDeletedLabel) {
|
||||
if (currentUser.role === 'admin') {
|
||||
showDeletedLabel.style.display = 'flex';
|
||||
} else {
|
||||
showDeletedLabel.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
loadUsers();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
showSection('tasks');
|
||||
|
||||
showingTasksWithoutDate = false;
|
||||
const btn = document.getElementById('tasks-no-date-btn');
|
||||
if (btn) btn.classList.remove('active');
|
||||
}
|
||||
|
||||
// Вспомогательная функция для отображения понятного имени роли
|
||||
function getRoleDisplayName(role) {
|
||||
const roleNames = {
|
||||
'admin': 'Администратор',
|
||||
'secretary': 'Секретарь',
|
||||
'help': 'Помощь',
|
||||
'ithelp': 'IT поддержка',
|
||||
'request': 'Заявки',
|
||||
'tasks': 'Адмиинистрация',
|
||||
'teacher': 'Учитель'
|
||||
};
|
||||
return roleNames[role] || role;
|
||||
}
|
||||
|
||||
async function login(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const login = document.getElementById('login').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ login, password })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
currentUser = data.user;
|
||||
showMainInterface();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка входа');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка подключения к серверу');
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await fetch('/api/logout', { method: 'POST' });
|
||||
currentUser = null;
|
||||
showLoginInterface();
|
||||
} catch (error) {
|
||||
console.error('Ошибка выхода:', error);
|
||||
}
|
||||
}
|
||||
@@ -1,558 +0,0 @@
|
||||
// tasks.js - Основные операции с задачами
|
||||
let tasks = [];
|
||||
let expandedTasks = new Set();
|
||||
let showingTasksWithoutDate = false;
|
||||
|
||||
async function loadTasks() {
|
||||
try {
|
||||
showingTasksWithoutDate = false;
|
||||
const btn = document.getElementById('tasks-no-date-btn');
|
||||
if (btn) btn.classList.remove('active');
|
||||
|
||||
const search = document.getElementById('search-tasks')?.value || '';
|
||||
const statusFilter = document.getElementById('status-filter')?.value || 'active,in_progress,assigned,overdue,rework';
|
||||
const creatorFilter = document.getElementById('creator-filter')?.value || '';
|
||||
const assigneeFilter = document.getElementById('assignee-filter')?.value || '';
|
||||
const deadlineFilter = document.getElementById('deadline-filter')?.value || '';
|
||||
const showDeleted = document.getElementById('show-deleted')?.checked || false;
|
||||
|
||||
let url = '/api/tasks?';
|
||||
if (search) url += `search=${encodeURIComponent(search)}&`;
|
||||
if (statusFilter) url += `status=${encodeURIComponent(statusFilter)}&`;
|
||||
if (creatorFilter) url += `creator=${encodeURIComponent(creatorFilter)}&`;
|
||||
if (assigneeFilter) url += `assignee=${encodeURIComponent(assigneeFilter)}&`;
|
||||
if (deadlineFilter) url += `deadline=${encodeURIComponent(deadlineFilter)}&`;
|
||||
if (showDeleted) url += `showDeleted=true&`;
|
||||
|
||||
const response = await fetch(url);
|
||||
tasks = await response.json();
|
||||
|
||||
// Загружаем файлы для всех задач
|
||||
await Promise.all(tasks.map(async (task) => {
|
||||
try {
|
||||
const filesResponse = await fetch(`/api/tasks/${task.id}/files`);
|
||||
if (filesResponse.ok) {
|
||||
task.files = await filesResponse.json();
|
||||
} else {
|
||||
task.files = [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Ошибка загрузки файлов для задачи ${task.id}:`, error);
|
||||
task.files = [];
|
||||
}
|
||||
}));
|
||||
|
||||
renderTasks();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки задач:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function showTasksWithoutDate() {
|
||||
showingTasksWithoutDate = true;
|
||||
const btn = document.getElementById('tasks-no-date-btn');
|
||||
if (btn) btn.classList.add('active');
|
||||
loadTasksWithoutDate();
|
||||
}
|
||||
|
||||
async function loadTasksWithoutDate() {
|
||||
try {
|
||||
const response = await fetch('/api/tasks');
|
||||
if (!response.ok) throw new Error('Ошибка загрузки задач');
|
||||
|
||||
const allTasks = await response.json();
|
||||
tasks = allTasks.filter(task => {
|
||||
const hasTaskDueDate = !task.due_date;
|
||||
const hasAssignmentDueDates = task.assignments &&
|
||||
task.assignments.every(assignment => !assignment.due_date);
|
||||
return hasTaskDueDate && hasAssignmentDueDates;
|
||||
});
|
||||
|
||||
// Загружаем файлы для всех задач
|
||||
await Promise.all(tasks.map(async (task) => {
|
||||
try {
|
||||
const filesResponse = await fetch(`/api/tasks/${task.id}/files`);
|
||||
if (filesResponse.ok) {
|
||||
task.files = await filesResponse.json();
|
||||
} else {
|
||||
task.files = [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Ошибка загрузки файлов для задачи ${task.id}:`, error);
|
||||
task.files = [];
|
||||
}
|
||||
}));
|
||||
|
||||
renderTasks();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки задач без срока:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function createTask(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!currentUser) {
|
||||
alert('Требуется аутентификация');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('title', document.getElementById('title').value);
|
||||
formData.append('description', document.getElementById('description').value);
|
||||
|
||||
const dueDate = document.getElementById('due-date').value;
|
||||
if (!dueDate) {
|
||||
alert('Дата и время выполнения обязательны');
|
||||
return;
|
||||
}
|
||||
formData.append('dueDate', dueDate);
|
||||
|
||||
// Используем selectedUsers вместо прямого доступа к DOM
|
||||
if (selectedUsers.length === 0) {
|
||||
alert('Выберите хотя бы одного исполнителя');
|
||||
return;
|
||||
}
|
||||
selectedUsers.forEach(userId => {
|
||||
formData.append('assignedUsers', userId);
|
||||
});
|
||||
|
||||
const files = document.getElementById('files').files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
formData.append('files', files[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/tasks', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача успешно создана!');
|
||||
document.getElementById('create-task-form').reset();
|
||||
document.getElementById('file-list').innerHTML = '';
|
||||
document.getElementById('user-search').value = '';
|
||||
selectedUsers = [];
|
||||
renderUsersChecklist();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
showSection('tasks');
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка создания задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка создания задачи');
|
||||
}
|
||||
}
|
||||
|
||||
async function openEditModal(taskId) {
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}`);
|
||||
if (!response.ok) {
|
||||
if (response.status === 404) {
|
||||
alert('Задача не найдена или у вас нет прав доступа');
|
||||
}
|
||||
throw new Error('Ошибка загрузки задачи');
|
||||
}
|
||||
|
||||
const task = await response.json();
|
||||
|
||||
if (!canUserEditTask(task)) {
|
||||
alert('У вас нет прав для редактирования этой задачи');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('edit-task-id').value = task.id;
|
||||
document.getElementById('edit-title').value = task.title;
|
||||
document.getElementById('edit-description').value = task.description || '';
|
||||
|
||||
document.getElementById('edit-due-date').value = task.due_date ? formatDateTimeForInput(task.due_date) : '';
|
||||
|
||||
// Устанавливаем выбранных пользователей
|
||||
editSelectedUsers = task.assignments ? task.assignments.map(a => a.user_id) : [];
|
||||
renderEditUsersChecklist(users);
|
||||
|
||||
// Показываем существующие файлы
|
||||
currentEditTaskFiles = task.files || [];
|
||||
updateEditFileList();
|
||||
|
||||
document.getElementById('edit-task-modal').style.display = 'block';
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка загрузки задачи');
|
||||
}
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
document.getElementById('edit-task-modal').style.display = 'none';
|
||||
document.getElementById('edit-file-list').innerHTML = '';
|
||||
document.getElementById('edit-user-search').value = '';
|
||||
editSelectedUsers = [];
|
||||
currentEditTaskFiles = [];
|
||||
filterEditUsers();
|
||||
}
|
||||
|
||||
async function updateTask(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const taskId = document.getElementById('edit-task-id').value;
|
||||
const title = document.getElementById('edit-title').value;
|
||||
const description = document.getElementById('edit-description').value;
|
||||
const dueDate = document.getElementById('edit-due-date').value;
|
||||
|
||||
if (!dueDate) {
|
||||
alert('Дата и время выполнения обязательны');
|
||||
return;
|
||||
}
|
||||
|
||||
// Используем editSelectedUsers
|
||||
const assignedUserIds = editSelectedUsers;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('title', title);
|
||||
formData.append('description', description);
|
||||
formData.append('assignedUsers', JSON.stringify(assignedUserIds));
|
||||
formData.append('dueDate', dueDate);
|
||||
|
||||
const files = document.getElementById('edit-files').files;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
formData.append('files', files[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}`, {
|
||||
method: 'PUT',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача успешно обновлена!');
|
||||
closeEditModal();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления задачи');
|
||||
}
|
||||
}
|
||||
|
||||
function openCopyModal(taskId) {
|
||||
document.getElementById('copy-task-id').value = taskId;
|
||||
|
||||
// Устанавливаем дату по умолчанию (через 7 дней)
|
||||
const defaultDate = new Date();
|
||||
defaultDate.setDate(defaultDate.getDate() + 7);
|
||||
document.getElementById('copy-due-date').value = defaultDate.toISOString().substring(0, 16);
|
||||
|
||||
// Сбрасываем выбранных пользователей
|
||||
copySelectedUsers = [];
|
||||
renderCopyUsersChecklist(users);
|
||||
|
||||
document.getElementById('copy-task-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeCopyModal() {
|
||||
document.getElementById('copy-task-modal').style.display = 'none';
|
||||
document.getElementById('copy-user-search').value = '';
|
||||
copySelectedUsers = [];
|
||||
filterCopyUsers();
|
||||
}
|
||||
|
||||
async function copyTask(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const taskId = document.getElementById('copy-task-id').value;
|
||||
const dueDate = document.getElementById('copy-due-date').value;
|
||||
|
||||
if (!dueDate) {
|
||||
alert('Дата и время выполнения обязательны для копии задачи');
|
||||
return;
|
||||
}
|
||||
|
||||
// Используем copySelectedUsers
|
||||
const assignedUserIds = copySelectedUsers;
|
||||
|
||||
if (assignedUserIds.length === 0) {
|
||||
alert('Выберите хотя бы одного исполнителя для копии задачи');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/copy`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
assignedUsers: assignedUserIds,
|
||||
dueDate: dueDate
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Копия задачи успешно создана!');
|
||||
closeCopyModal();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка создания копии задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка создания копии задачи');
|
||||
}
|
||||
}
|
||||
|
||||
async function closeTask(taskId) {
|
||||
if (!confirm('Вы уверены, что хотите закрыть эту задачу? Исполнители больше не будут видеть её.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/close`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача закрыта!');
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка закрытия задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка закрытия задачи');
|
||||
}
|
||||
}
|
||||
|
||||
async function reopenTask(taskId) {
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/reopen`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача открыта!');
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка открытия задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка открытия задачи');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTask(taskId) {
|
||||
if (!confirm('Вы уверены, что хотите удалить эту задачу?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача удалена!');
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка удаления задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка удаления задачи');
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreTask(taskId) {
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/restore`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача восстановлена!');
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка восстановления задачи');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка восстановления задачи');
|
||||
}
|
||||
}
|
||||
|
||||
function openEditAssignmentModal(taskId, userId) {
|
||||
const task = tasks.find(t => t.id === taskId);
|
||||
if (!task) return;
|
||||
|
||||
const assignment = task.assignments.find(a => a.user_id === userId);
|
||||
if (!assignment) return;
|
||||
|
||||
document.getElementById('edit-assignment-task-id').value = taskId;
|
||||
document.getElementById('edit-assignment-user-id').value = userId;
|
||||
document.getElementById('edit-assignment-due-date').value = assignment.due_date ? formatDateTimeForInput(assignment.due_date) : '';
|
||||
|
||||
document.getElementById('edit-assignment-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeEditAssignmentModal() {
|
||||
document.getElementById('edit-assignment-modal').style.display = 'none';
|
||||
}
|
||||
|
||||
async function updateAssignment(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const taskId = document.getElementById('edit-assignment-task-id').value;
|
||||
const userId = document.getElementById('edit-assignment-user-id').value;
|
||||
const dueDate = document.getElementById('edit-assignment-due-date').value;
|
||||
|
||||
if (!dueDate) {
|
||||
alert('Дата и время выполнения обязательны');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/assignment/${userId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dueDate: dueDate
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Сроки исполнителя обновлены!');
|
||||
closeEditAssignmentModal();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления сроков');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления сроков');
|
||||
}
|
||||
}
|
||||
|
||||
function openReworkModal(taskId) {
|
||||
document.getElementById('rework-task-id').value = taskId;
|
||||
document.getElementById('rework-task-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeReworkModal() {
|
||||
document.getElementById('rework-task-modal').style.display = 'none';
|
||||
document.getElementById('rework-comment').value = '';
|
||||
}
|
||||
|
||||
async function sendForRework(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const taskId = document.getElementById('rework-task-id').value;
|
||||
const comment = document.getElementById('rework-comment').value;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/rework`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ comment })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Задача возвращена на доработку!');
|
||||
closeReworkModal();
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка возврата задачи на доработку');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка возврата задачи на доработку');
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStatus(taskId, userId, status) {
|
||||
try {
|
||||
const response = await fetch(`/api/tasks/${taskId}/status`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ userId, status })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
loadTasks();
|
||||
loadActivityLogs();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления статуса');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления статуса');
|
||||
}
|
||||
}
|
||||
|
||||
function canUserEditTask(task) {
|
||||
if (!currentUser) return false;
|
||||
|
||||
// Администратор может всё
|
||||
if (currentUser.role === 'admin') return true;
|
||||
|
||||
// Создатель может редактировать свою задачу
|
||||
if (parseInt(task.created_by) === currentUser.id) {
|
||||
// Но если задача уже назначена другим пользователям,
|
||||
// создатель может только просматривать
|
||||
if (task.assignments && task.assignments.length > 0) {
|
||||
// Проверяем, назначена ли задача другим пользователям (не только себе)
|
||||
const assignedToOthers = task.assignments.some(assignment =>
|
||||
parseInt(assignment.user_id) !== currentUser.id
|
||||
);
|
||||
|
||||
if (assignedToOthers) {
|
||||
// Создатель может только просматривать и закрывать задачу
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Исполнитель может менять только свой статус
|
||||
if (task.assignments) {
|
||||
const isExecutor = task.assignments.some(assignment =>
|
||||
parseInt(assignment.user_id) === currentUser.id
|
||||
);
|
||||
if (isExecutor) {
|
||||
// Исполнитель может менять только статус
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
// users.js - Управление пользователями
|
||||
let users = [];
|
||||
let allUsers = [];
|
||||
let filteredUsers = [];
|
||||
let selectedUsers = [];
|
||||
let editSelectedUsers = [];
|
||||
let copySelectedUsers = [];
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const response = await fetch('/api/users');
|
||||
const allUsersData = await response.json();
|
||||
//users = await response.json();
|
||||
// Сохраняем всех пользователей
|
||||
allUsers = allUsersData;
|
||||
// Фильтруем пользователей в зависимости от прав текущего пользователя
|
||||
users = filterAssignableUsers(allUsersData);
|
||||
filteredUsers = [...users];
|
||||
renderUsersChecklist();
|
||||
renderEditUsersChecklist();
|
||||
renderCopyUsersChecklist();
|
||||
populateFilterDropdowns();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки пользователей:', error);
|
||||
}
|
||||
}
|
||||
function filterAssignableUsers(allUsers) {
|
||||
if (!currentUser) return [];
|
||||
|
||||
// Администратор видит всех пользователей
|
||||
if (currentUser.role === 'admin') {
|
||||
return allUsers.filter(user => user.id !== currentUser.id);
|
||||
}
|
||||
if (currentUser.role === 'secretary') {
|
||||
return allUsers.filter(user => user.id !== currentUser.id);
|
||||
}
|
||||
if (currentUser.role === 'ithelp') {
|
||||
return allUsers.filter(user =>
|
||||
(user.role === 'teacher' || user.role === 'tasks' || user.role === 'help' || user.role === 'request' || user.role === 'ithelp') &&
|
||||
user.id !== currentUser.id
|
||||
);
|
||||
}
|
||||
if (currentUser.role === 'request') {
|
||||
return allUsers.filter(user =>
|
||||
(user.role === 'teacher' || user.role === 'tasks' || user.role === 'help' || user.role === 'request' || user.role === 'ithelp') &&
|
||||
user.id !== currentUser.id
|
||||
);
|
||||
}
|
||||
// tasks видит учителей и других tasks
|
||||
if (currentUser.role === 'help') {
|
||||
return allUsers.filter(user =>
|
||||
(user.role === 'teacher' || user.role === 'tasks' || user.role === 'help' || user.role === 'request' || user.role === 'ithelp') &&
|
||||
user.id !== currentUser.id
|
||||
);
|
||||
}
|
||||
// tasks видит учителей и других tasks
|
||||
if (currentUser.role === 'tasks') {
|
||||
return allUsers.filter(user =>
|
||||
(user.role === 'teacher' || user.role === 'tasks' || user.role === 'help' || user.role === 'request' || user.role === 'ithelp') &&
|
||||
user.id !== currentUser.id
|
||||
);
|
||||
}
|
||||
// Учитель видит только учителей
|
||||
if (currentUser.role === 'teacher') {
|
||||
return allUsers.filter(user =>
|
||||
(user.role === 'help' || user.role === 'request' || user.role === 'ithelp') &&
|
||||
user.id !== currentUser.id
|
||||
);
|
||||
}
|
||||
// Проверяем группы пользователя для определения прав
|
||||
const userGroups = currentUser.groups || [];
|
||||
|
||||
// Загружаем конфигурацию групп из настроек
|
||||
// (предполагается, что эти переменные определены в глобальной области)
|
||||
const allowedGroups = getGroupsForCurrentUser();
|
||||
|
||||
// Если у пользователя нет специальных групп, возвращаем пустой массив
|
||||
if (allowedGroups.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Фильтруем пользователей по группам
|
||||
return allUsers.filter(user => {
|
||||
// Пользователь не может назначать задачи себе
|
||||
if (user.id === currentUser.id) return false;
|
||||
|
||||
// Если у пользователя есть группы, проверяем пересечение
|
||||
if (user.groups && Array.isArray(user.groups)) {
|
||||
return user.groups.some(group => allowedGroups.includes(group));
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// Функция для получения групп, которым текущий пользователь может назначать задачи
|
||||
function getGroupsForCurrentUser() {
|
||||
const allowedGroups = [];
|
||||
const userGroups = currentUser.groups || [];
|
||||
|
||||
// Определяем, какие группы доступны для назначения
|
||||
// На основе ролей и групп текущего пользователя
|
||||
|
||||
// Пример: пользователи с ролью 'secretary' могут назначать задачи группам 'teachers'
|
||||
if (currentUser.role === 'secretary') {
|
||||
allowedGroups.push('teachers', 'staff');
|
||||
}
|
||||
|
||||
// Пример: пользователи из группы 'department_head' могут назначать своей группе
|
||||
if (userGroups.includes('department_head')) {
|
||||
allowedGroups.push('department_head', 'teachers');
|
||||
}
|
||||
|
||||
// Пример: для помощи (help) можно назначать всем
|
||||
if (currentUser.role === 'help') {
|
||||
// Можно указать конкретные группы или 'all' для всех
|
||||
allowedGroups.push('teachers', 'staff', 'administration');
|
||||
}
|
||||
|
||||
// Пример: для IT поддержки
|
||||
if (currentUser.role === 'ithelp') {
|
||||
allowedGroups.push('teachers', 'staff', 'administration', 'it_department');
|
||||
}
|
||||
|
||||
// Пример: пользователи с ролью 'request' могут создавать заявки для всех
|
||||
if (currentUser.role === 'request') {
|
||||
allowedGroups.push('all'); // Специальное значение "все"
|
||||
}
|
||||
|
||||
// Пример: пользователи с ролью 'tasks' (задачи) могут назначать учителям
|
||||
if (currentUser.role === 'tasks') {
|
||||
allowedGroups.push('teachers');
|
||||
}
|
||||
|
||||
// Если массив содержит 'all', возвращаем специальный маркер
|
||||
if (allowedGroups.includes('all')) {
|
||||
return ['all']; // Это будет обрабатываться в фильтрации
|
||||
}
|
||||
|
||||
return [...new Set(allowedGroups)]; // Убираем дубликаты
|
||||
}
|
||||
function populateFilterDropdowns() {
|
||||
const creatorFilter = document.getElementById('creator-filter');
|
||||
const assigneeFilter = document.getElementById('assignee-filter');
|
||||
|
||||
creatorFilter.innerHTML = '<option value="">Все заказчики</option>';
|
||||
assigneeFilter.innerHTML = '<option value="">Все исполнители</option>';
|
||||
|
||||
users.forEach(user => {
|
||||
const creatorOption = document.createElement('option');
|
||||
creatorOption.value = user.id;
|
||||
creatorOption.textContent = `${user.name} (${user.login})`;
|
||||
creatorFilter.appendChild(creatorOption.cloneNode(true));
|
||||
|
||||
const assigneeOption = creatorOption.cloneNode(true);
|
||||
assigneeFilter.appendChild(assigneeOption);
|
||||
});
|
||||
}
|
||||
|
||||
function filterUsers() {
|
||||
const search = document.getElementById('user-search').value.toLowerCase();
|
||||
filteredUsers = users.filter(user =>
|
||||
user.name.toLowerCase().includes(search) ||
|
||||
user.login.toLowerCase().includes(search) ||
|
||||
user.email.toLowerCase().includes(search)
|
||||
);
|
||||
renderUsersChecklist();
|
||||
}
|
||||
|
||||
function filterEditUsers() {
|
||||
const search = document.getElementById('edit-user-search').value.toLowerCase();
|
||||
const filtered = users.filter(user =>
|
||||
user.name.toLowerCase().includes(search) ||
|
||||
user.login.toLowerCase().includes(search) ||
|
||||
user.email.toLowerCase().includes(search)
|
||||
);
|
||||
renderEditUsersChecklist(filtered);
|
||||
}
|
||||
|
||||
function filterCopyUsers() {
|
||||
const search = document.getElementById('copy-user-search').value.toLowerCase();
|
||||
const filtered = users.filter(user =>
|
||||
user.name.toLowerCase().includes(search) ||
|
||||
user.login.toLowerCase().includes(search) ||
|
||||
user.email.toLowerCase().includes(search)
|
||||
);
|
||||
renderCopyUsersChecklist(filtered);
|
||||
}
|
||||
|
||||
function renderUsersChecklist() {
|
||||
const container = document.getElementById('users-checklist');
|
||||
container.innerHTML = filteredUsers
|
||||
.filter(user => user.id !== currentUser.id)
|
||||
.map(user => `
|
||||
<div class="checkbox-item">
|
||||
<label>
|
||||
<input type="checkbox" name="assignedUsers" value="${user.id}"
|
||||
onchange="toggleUserSelection(this, ${user.id})">
|
||||
${user.name} (${user.email})
|
||||
${user.auth_type === 'ldap' ? '<small style="color: #666;"> - LDAP</small>' : ''}
|
||||
</label>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function renderEditUsersChecklist(filtered = users) {
|
||||
const container = document.getElementById('edit-users-checklist');
|
||||
container.innerHTML = filtered
|
||||
.filter(user => user.id !== currentUser.id)
|
||||
.map(user => `
|
||||
<div class="checkbox-item">
|
||||
<label>
|
||||
<input type="checkbox" name="assignedUsers" value="${user.id}"
|
||||
onchange="toggleEditUserSelection(this, ${user.id})">
|
||||
${user.name} (${user.email})
|
||||
${user.auth_type === 'ldap' ? '<small style="color: #666;"> - LDAP</small>' : ''}
|
||||
</label>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function renderCopyUsersChecklist(filtered = users) {
|
||||
const container = document.getElementById('copy-users-checklist');
|
||||
container.innerHTML = filtered
|
||||
.filter(user => user.id !== currentUser.id)
|
||||
.map(user => `
|
||||
<div class="checkbox-item">
|
||||
<label>
|
||||
<input type="checkbox" name="assignedUsers" value="${user.id}"
|
||||
onchange="toggleCopyUserSelection(this, ${user.id})">
|
||||
${user.name} (${user.email})
|
||||
${user.auth_type === 'ldap' ? '<small style="color: #666;"> - LDAP</small>' : ''}
|
||||
</label>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function toggleUserSelection(checkbox, userId) {
|
||||
if (checkbox.checked) {
|
||||
selectedUsers.push(userId);
|
||||
} else {
|
||||
selectedUsers = selectedUsers.filter(id => id !== userId);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleEditUserSelection(checkbox, userId) {
|
||||
if (checkbox.checked) {
|
||||
editSelectedUsers.push(userId);
|
||||
} else {
|
||||
editSelectedUsers = editSelectedUsers.filter(id => id !== userId);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCopyUserSelection(checkbox, userId) {
|
||||
if (checkbox.checked) {
|
||||
copySelectedUsers.push(userId);
|
||||
} else {
|
||||
copySelectedUsers = copySelectedUsers.filter(id => id !== userId);
|
||||
}
|
||||
}
|
||||
1058
public/doc.html
1058
public/doc.html
File diff suppressed because it is too large
Load Diff
@@ -1,646 +0,0 @@
|
||||
// documents.js - Работа с документами для согласования
|
||||
|
||||
let documentTypes = [];
|
||||
|
||||
async function loadDocumentTypes() {
|
||||
try {
|
||||
const response = await fetch('/api/document-types');
|
||||
documentTypes = await response.json();
|
||||
populateDocumentTypeSelect();
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки типов документов:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function populateDocumentTypeSelect() {
|
||||
const select = document.getElementById('document-type');
|
||||
if (!select) return;
|
||||
|
||||
select.innerHTML = '<option value="">Выберите тип документа...</option>';
|
||||
|
||||
documentTypes.forEach(type => {
|
||||
const option = document.createElement('option');
|
||||
option.value = type.id;
|
||||
option.textContent = type.name;
|
||||
select.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
function initializeDocumentForm() {
|
||||
const form = document.getElementById('create-document-form');
|
||||
if (form) {
|
||||
form.addEventListener('submit', createDocumentTask);
|
||||
}
|
||||
|
||||
// Инициализация даты по умолчанию
|
||||
const today = new Date();
|
||||
const todayStr = today.toISOString().split('T')[0];
|
||||
const dateInput = document.getElementById('document-date');
|
||||
if (dateInput) {
|
||||
dateInput.value = todayStr;
|
||||
}
|
||||
|
||||
loadDocumentTypes();
|
||||
}
|
||||
|
||||
async function createDocumentTask() {
|
||||
console.log('📝 Создание документа...');
|
||||
|
||||
// Собираем данные формы
|
||||
const formData = new FormData();
|
||||
|
||||
// Обязательное поле - только название
|
||||
const title = document.getElementById('doc-title').value.trim();
|
||||
if (!title) {
|
||||
showNotification('Название документа обязательно', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
formData.append('title', title);
|
||||
formData.append('description', document.getElementById('doc-description').value);
|
||||
formData.append('dueDate', document.getElementById('doc-due-date').value);
|
||||
|
||||
// Тип документа - опционально
|
||||
const documentTypeSelect = document.getElementById('doc-type');
|
||||
if (documentTypeSelect && documentTypeSelect.value) {
|
||||
formData.append('documentTypeId', documentTypeSelect.value);
|
||||
}
|
||||
|
||||
// Остальные поля - опционально
|
||||
formData.append('documentNumber', document.getElementById('doc-number')?.value || '');
|
||||
formData.append('documentDate', document.getElementById('doc-date')?.value || '');
|
||||
formData.append('pagesCount', document.getElementById('doc-pages')?.value || '');
|
||||
|
||||
const urgencySelect = document.getElementById('doc-urgency');
|
||||
if (urgencySelect) {
|
||||
formData.append('urgencyLevel', urgencySelect.value);
|
||||
}
|
||||
|
||||
formData.append('comment', document.getElementById('doc-comment')?.value || '');
|
||||
|
||||
// Добавляем файлы (опционально)
|
||||
const fileInput = document.getElementById('doc-files');
|
||||
if (fileInput && fileInput.files) {
|
||||
for (let i = 0; i < fileInput.files.length; i++) {
|
||||
formData.append('files', fileInput.files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Показываем индикатор загрузки
|
||||
const submitBtn = document.querySelector('#new-doc-form button[type="submit"]');
|
||||
const originalText = submitBtn.innerHTML;
|
||||
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Создание...';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
console.log('📤 Отправка запроса на создание документа...');
|
||||
|
||||
const response = await fetch('/api/documents', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
console.log('✅ Документ создан успешно:', result);
|
||||
|
||||
// Показываем сообщение об успехе
|
||||
showNotification('Документ успешно создан и отправлен на согласование', 'success');
|
||||
|
||||
// Закрываем модальное окно
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('newDocModal'));
|
||||
if (modal) modal.hide();
|
||||
|
||||
// Очищаем форму
|
||||
const form = document.getElementById('new-doc-form');
|
||||
if (form) form.reset();
|
||||
|
||||
// Обновляем список документов
|
||||
await loadMyDocuments();
|
||||
|
||||
} else {
|
||||
console.error('❌ Ошибка создания документа:', result);
|
||||
showNotification(`Ошибка: ${result.error || 'Неизвестная ошибка'}`, 'error');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка сети при создании документа:', error);
|
||||
showNotification('Ошибка сети при создании документа', 'error');
|
||||
} finally {
|
||||
// Восстанавливаем кнопку
|
||||
if (submitBtn) {
|
||||
submitBtn.innerHTML = originalText;
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateDocumentFileList() {
|
||||
const fileInput = document.getElementById('document-files');
|
||||
const fileList = document.getElementById('document-file-list');
|
||||
|
||||
const files = fileInput.files;
|
||||
if (files.length === 0) {
|
||||
fileList.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '<ul>';
|
||||
let totalSize = 0;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
totalSize += file.size;
|
||||
html += `<li>${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)</li>`;
|
||||
}
|
||||
|
||||
html += '</ul>';
|
||||
html += `<p><strong>Общий размер: ${(totalSize / 1024 / 1024).toFixed(2)} MB / 300 MB</strong></p>`;
|
||||
|
||||
fileList.innerHTML = html;
|
||||
}
|
||||
|
||||
// Функции для работы с документами
|
||||
async function loadMyDocuments() {
|
||||
try {
|
||||
const response = await fetch('/api/documents/my');
|
||||
const documents = await response.json();
|
||||
renderMyDocuments(documents);
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки документов:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSecretaryDocuments() {
|
||||
try {
|
||||
const response = await fetch('/api/documents/secretary');
|
||||
const documents = await response.json();
|
||||
renderSecretaryDocuments(documents);
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки документов секретаря:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function renderMyDocuments(documents) {
|
||||
console.log('📄 Рендеринг документов:', documents);
|
||||
|
||||
const container = document.getElementById('my-docs-list');
|
||||
|
||||
if (!documents || !Array.isArray(documents)) {
|
||||
console.error('❌ documents не является массивом:', documents);
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<p>Ошибка загрузки документов</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (documents.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-file-alt"></i>
|
||||
<p>У вас нет документов для согласования</p>
|
||||
<button class="btn btn-primary" onclick="showNewDocModal()">
|
||||
<i class="fas fa-plus"></i> Создать документ
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = documents.map(doc => {
|
||||
// Определяем статус
|
||||
let statusClass = 'status-pending';
|
||||
let statusText = 'На согласовании';
|
||||
|
||||
if (doc.assignment_status === 'completed' || doc.assignment_status === 'approved') {
|
||||
statusClass = 'status-completed';
|
||||
statusText = 'Согласован';
|
||||
} else if (doc.assignment_status === 'refused') {
|
||||
statusClass = 'status-cancelled';
|
||||
statusText = 'Отказано';
|
||||
} else if (doc.closed_at) {
|
||||
statusClass = 'status-cancelled';
|
||||
statusText = 'Отозван';
|
||||
}
|
||||
|
||||
// Форматируем дату
|
||||
const createdDate = new Date(doc.created_at).toLocaleDateString('ru-RU');
|
||||
const dueDate = doc.due_date ? new Date(doc.due_date).toLocaleDateString('ru-RU') : 'Не указана';
|
||||
|
||||
// Определяем уровень срочности
|
||||
let urgencyBadge = '';
|
||||
if (doc.urgency_level === 'urgent') {
|
||||
urgencyBadge = '<span class="badge bg-warning">Срочно</span>';
|
||||
} else if (doc.urgency_level === 'very_urgent') {
|
||||
urgencyBadge = '<span class="badge bg-danger">Очень срочно</span>';
|
||||
}
|
||||
|
||||
// Проверяем наличие типа документа
|
||||
const documentType = doc.document_type_name || 'Не указан';
|
||||
|
||||
return `
|
||||
<div class="doc-card">
|
||||
<div class="doc-header">
|
||||
<h4>${doc.title.replace('Документ: ', '')}</h4>
|
||||
<span class="${statusClass}">${statusText}</span>
|
||||
</div>
|
||||
|
||||
<div class="doc-info">
|
||||
<div class="info-row">
|
||||
<span class="info-label">Тип:</span>
|
||||
<span>${documentType}</span>
|
||||
</div>
|
||||
|
||||
${doc.document_number ? `
|
||||
<div class="info-row">
|
||||
<span class="info-label">Номер:</span>
|
||||
<span>${doc.document_number}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.document_date ? `
|
||||
<div class="info-row">
|
||||
<span class="info-label">Дата документа:</span>
|
||||
<span>${new Date(doc.document_date).toLocaleDateString('ru-RU')}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<div class="info-row">
|
||||
<span class="info-label">Создан:</span>
|
||||
<span>${createdDate}</span>
|
||||
</div>
|
||||
|
||||
<div class="info-row">
|
||||
<span class="info-label">Срок согласования:</span>
|
||||
<span>${dueDate}</span>
|
||||
</div>
|
||||
|
||||
${doc.urgency_level && doc.urgency_level !== 'normal' ? `
|
||||
<div class="info-row">
|
||||
<span class="info-label">Срочность:</span>
|
||||
<span>${urgencyBadge}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.assignee_name ? `
|
||||
<div class="info-row">
|
||||
<span class="info-label">Согласующий:</span>
|
||||
<span>${doc.assignee_name}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.refusal_reason ? `
|
||||
<div class="info-row">
|
||||
<span class="info-label">Причина отказа:</span>
|
||||
<span class="text-danger">${doc.refusal_reason}</span>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
|
||||
${doc.description ? `
|
||||
<div class="doc-description">
|
||||
<p>${doc.description}</p>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.comment ? `
|
||||
<div class="doc-comment">
|
||||
<strong><i class="fas fa-comment"></i> Комментарий:</strong>
|
||||
<p>${doc.comment}</p>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.files && doc.files.length > 0 ? `
|
||||
<div class="doc-files">
|
||||
<strong><i class="fas fa-paperclip"></i> Файлы:</strong>
|
||||
<div class="files-list">
|
||||
${doc.files.map(file => `
|
||||
<a href="/api/files/${file.id}/download" class="file-link">
|
||||
<i class="fas fa-file"></i> ${file.original_name} (${formatFileSize(file.file_size)})
|
||||
</a>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${!doc.closed_at && doc.assignment_status !== 'completed' &&
|
||||
doc.assignment_status !== 'approved' && doc.assignment_status !== 'refused' ? `
|
||||
<div class="doc-actions">
|
||||
<button class="btn btn-danger" onclick="cancelDocument(${doc.document_id})">
|
||||
<i class="fas fa-times"></i> Отозвать
|
||||
</button>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function formatFileSize(bytes) {
|
||||
if (bytes === 0) return '0 Б';
|
||||
const k = 1024;
|
||||
const sizes = ['Б', 'КБ', 'МБ', 'ГБ'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
// Исправьте функцию loadMyDocuments:
|
||||
async function loadMyDocuments() {
|
||||
console.log('📥 Загрузка моих документов...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/documents/my');
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const documents = await response.json();
|
||||
console.log('✅ Получены документы:', documents);
|
||||
renderMyDocuments(documents);
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка загрузки документов:', error);
|
||||
showNotification('Ошибка загрузки документов', 'error');
|
||||
|
||||
const container = document.getElementById('my-docs-list');
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<p>Ошибка загрузки документов: ${error.message}</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
function renderSecretaryDocuments(documents) {
|
||||
const container = document.getElementById('secretary-documents-list');
|
||||
if (!container) return;
|
||||
|
||||
if (documents.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state">Нет документов для согласования</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = documents.map(doc => `
|
||||
<div class="document-card" data-document-id="${doc.id}">
|
||||
<div class="document-header">
|
||||
<div class="document-title">
|
||||
<span class="document-number">Документ №${doc.document_number || doc.id}</span>
|
||||
<strong>${doc.title}</strong>
|
||||
<span class="document-status ${getDocumentStatusClass(doc.status)}">${getDocumentStatusText(doc.status)}</span>
|
||||
${doc.urgency_level === 'urgent' ? '<span class="urgency-badge urgent">Срочно</span>' : ''}
|
||||
${doc.urgency_level === 'very_urgent' ? '<span class="urgency-badge very-urgent">Очень срочно</span>' : ''}
|
||||
</div>
|
||||
<div class="document-meta">
|
||||
<small>От: ${doc.creator_name}</small>
|
||||
<small>Создан: ${formatDateTime(doc.created_at)}</small>
|
||||
${doc.due_date ? `<small>Срок: ${formatDateTime(doc.due_date)}</small>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="document-details">
|
||||
<div class="document-info">
|
||||
<p><strong>Тип:</strong> ${doc.document_type_name || 'Не указан'}</p>
|
||||
<p><strong>Номер:</strong> ${doc.document_number || 'Не указан'}</p>
|
||||
<p><strong>Дата документа:</strong> ${doc.document_date ? formatDate(doc.document_date) : 'Не указана'}</p>
|
||||
<p><strong>Количество страниц:</strong> ${doc.pages_count || 'Не указано'}</p>
|
||||
${doc.comment ? `<p><strong>Комментарий автора:</strong> ${doc.comment}</p>` : ''}
|
||||
</div>
|
||||
|
||||
<div class="document-files">
|
||||
${doc.files && doc.files.length > 0 ? `
|
||||
<strong>Файлы:</strong>
|
||||
<div class="file-icons-container">
|
||||
${doc.files.map(file => renderFileIcon(file)).join('')}
|
||||
</div>
|
||||
` : '<strong>Файлы:</strong> <span class="no-files">нет файлов</span>'}
|
||||
</div>
|
||||
|
||||
<div class="secretary-actions" id="secretary-actions-${doc.id}">
|
||||
${doc.status === 'assigned' ? `
|
||||
<button onclick="updateDocumentStatus(${doc.id}, 'in_progress')" class="btn-primary">Взять в работу</button>
|
||||
` : ''}
|
||||
|
||||
${doc.status === 'in_progress' ? `
|
||||
<div class="status-buttons">
|
||||
<button onclick="showApproveModal(${doc.id})" class="btn-success">Согласовать</button>
|
||||
<button onclick="showReceiveModal(${doc.id})" class="btn-primary">Получен (оригинал)</button>
|
||||
<button onclick="showRefuseModal(${doc.id})" class="btn-warning">Отказать</button>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.status === 'approved' ? `
|
||||
<div class="status-buttons">
|
||||
<button onclick="showReceiveModal(${doc.id})" class="btn-primary">Получен (оригинал)</button>
|
||||
<button onclick="updateDocumentStatus(${doc.id}, 'refused')" class="btn-warning">Отказать</button>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.status === 'received' ? `
|
||||
<div class="status-buttons">
|
||||
<button onclick="updateDocumentStatus(${doc.id}, 'signed')" class="btn-success">Подписан</button>
|
||||
<button onclick="updateDocumentStatus(${doc.id}, 'refused')" class="btn-warning">Отказать</button>
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
${doc.status === 'refused' ? `
|
||||
<p class="refusal-info"><strong>Причина отказа:</strong> ${doc.refusal_reason}</p>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function getDocumentStatusClass(status) {
|
||||
switch(status) {
|
||||
case 'assigned': return 'status-assigned';
|
||||
case 'in_progress': return 'status-in-progress';
|
||||
case 'approved': return 'status-approved';
|
||||
case 'received': return 'status-received';
|
||||
case 'signed': return 'status-signed';
|
||||
case 'refused': return 'status-refused';
|
||||
case 'cancelled': return 'status-cancelled';
|
||||
default: return 'status-assigned';
|
||||
}
|
||||
}
|
||||
|
||||
function getDocumentStatusText(status) {
|
||||
switch(status) {
|
||||
case 'assigned': return 'Назначена';
|
||||
case 'in_progress': return 'В работе';
|
||||
case 'approved': return 'Согласован';
|
||||
case 'received': return 'Получен';
|
||||
case 'signed': return 'Подписан';
|
||||
case 'refused': return 'Отказано';
|
||||
case 'cancelled': return 'Отозвано';
|
||||
default: return status;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(dateString) {
|
||||
if (!dateString) return '';
|
||||
return new Date(dateString).toLocaleDateString('ru-RU');
|
||||
}
|
||||
|
||||
// Модальные окна для секретаря
|
||||
function showApproveModal(documentId) {
|
||||
currentDocumentId = documentId;
|
||||
document.getElementById('approve-document-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeApproveModal() {
|
||||
document.getElementById('approve-document-modal').style.display = 'none';
|
||||
document.getElementById('approve-comment').value = '';
|
||||
}
|
||||
|
||||
function showReceiveModal(documentId) {
|
||||
currentDocumentId = documentId;
|
||||
document.getElementById('receive-document-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeReceiveModal() {
|
||||
document.getElementById('receive-document-modal').style.display = 'none';
|
||||
document.getElementById('receive-comment').value = '';
|
||||
}
|
||||
|
||||
function showRefuseModal(documentId) {
|
||||
currentDocumentId = documentId;
|
||||
document.getElementById('refuse-document-modal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeRefuseModal() {
|
||||
document.getElementById('refuse-document-modal').style.display = 'none';
|
||||
document.getElementById('refuse-reason').value = '';
|
||||
}
|
||||
|
||||
let currentDocumentId = null;
|
||||
|
||||
// Функции для работы с API
|
||||
async function updateDocumentStatus(documentId, status, comment = '', refusalReason = '') {
|
||||
try {
|
||||
const response = await fetch(`/api/documents/${documentId}/status`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
status: status,
|
||||
comment: comment,
|
||||
refusalReason: refusalReason
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Статус документа обновлен!');
|
||||
|
||||
// Закрываем модальные окна
|
||||
closeApproveModal();
|
||||
closeReceiveModal();
|
||||
closeRefuseModal();
|
||||
|
||||
// Обновляем список документов
|
||||
if (isSecretary()) {
|
||||
loadSecretaryDocuments();
|
||||
}
|
||||
loadMyDocuments();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка обновления статуса');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка обновления статуса');
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelDocument(documentId) {
|
||||
if (!confirm('Вы уверены, что хотите отозвать документ?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/documents/${documentId}/cancel`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
alert('Документ отозван!');
|
||||
loadMyDocuments();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка отзыва документа');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка отзыва документа');
|
||||
}
|
||||
}
|
||||
|
||||
async function reworkDocument(documentId) {
|
||||
// Здесь можно открыть форму для повторной отправки
|
||||
alert('Функция исправления и повторной отправки будет реализована в следующей версии');
|
||||
}
|
||||
|
||||
async function downloadDocumentPackage(documentId) {
|
||||
try {
|
||||
const response = await fetch(`/api/documents/${documentId}/package`);
|
||||
if (response.ok) {
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `document_${documentId}_package.zip`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Ошибка скачивания пакета документов');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ошибка:', error);
|
||||
alert('Ошибка скачивания пакета документов');
|
||||
}
|
||||
}
|
||||
|
||||
function isSecretary() {
|
||||
return currentUser && currentUser.groups && currentUser.groups.includes('Секретарь');
|
||||
}
|
||||
|
||||
function showDocumentSection(sectionName) {
|
||||
// Скрываем все секции
|
||||
document.querySelectorAll('.document-section').forEach(section => {
|
||||
section.style.display = 'none';
|
||||
});
|
||||
|
||||
// Показываем выбранную секцию
|
||||
const targetSection = document.getElementById(`${sectionName}-section`);
|
||||
if (targetSection) {
|
||||
targetSection.style.display = 'block';
|
||||
}
|
||||
|
||||
// Загружаем данные для секции
|
||||
if (sectionName === 'my-documents') {
|
||||
loadMyDocuments();
|
||||
} else if (sectionName === 'secretary-documents' && isSecretary()) {
|
||||
loadSecretaryDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
// Инициализация при загрузке страницы
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
if (window.location.pathname === '/doc') {
|
||||
initializeDocumentForm();
|
||||
|
||||
// Показываем соответствующие секции
|
||||
if (isSecretary()) {
|
||||
document.getElementById('secretary-tab').style.display = 'block';
|
||||
}
|
||||
|
||||
// По умолчанию показываем создание документа
|
||||
showDocumentSection('create-document');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user