Tasks Module Stage 3: Attachments
- Add migration for task_attachments table - Create TaskAttachmentModel with file handling methods - Add TaskService methods for upload/delete attachments - Add API routes for attachments (upload, delete, download) - Add controller methods for attachment operations - Add UI section in task view with file upload form - Add JavaScript handlers for AJAX file operations
This commit is contained in:
@@ -140,6 +140,53 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Вложения #}
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-header bg-light d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0">
|
||||
<i class="fa-solid fa-paperclip me-2"></i>Вложения
|
||||
{% if task.attachments_count %}
|
||||
<span class="badge bg-secondary ms-2">{{ task.attachments_count }}</span>
|
||||
{% endif %}
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if task.attachments %}
|
||||
<ul class="list-group list-group-flush mb-3" id="attachments-list">
|
||||
{% for attachment in task.attachments %}
|
||||
<li class="list-group-item d-flex align-items-center gap-2" data-attachment-id="{{ attachment.id }}">
|
||||
<i class="fa-solid fa-file text-muted"></i>
|
||||
<a href="{{ base_url('/tasks/' ~ task.id ~ '/attachments/' ~ attachment.id ~ '/download') }}"
|
||||
target="_blank" class="flex-grow-1 text-decoration-none">
|
||||
{{ attachment.file_name }}
|
||||
</a>
|
||||
<small class="text-muted">
|
||||
{{ attachment.file_size|filesize }}
|
||||
</small>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm"
|
||||
onclick="deleteAttachment({{ task.id }}, {{ attachment.id }})"
|
||||
title="Удалить">
|
||||
<i class="fa-solid fa-times"></i>
|
||||
</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p class="text-muted text-center mb-3">Нет вложений</p>
|
||||
{% endif %}
|
||||
|
||||
<form action="{{ base_url('/tasks/' ~ task.id ~ '/attachments/upload') }}" method="post"
|
||||
class="d-flex gap-2 attachment-form" enctype="multipart/form-data"
|
||||
onsubmit="uploadAttachment(event, {{ task.id }})">
|
||||
{{ csrf_field()|raw }}
|
||||
<input type="file" name="file" class="form-control" required>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fa-solid fa-upload"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Комментарии #}
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-light">
|
||||
@@ -314,5 +361,67 @@ function deleteSubtask(taskId, subtaskId) {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// ========== Вложения ==========
|
||||
|
||||
function uploadAttachment(event, taskId) {
|
||||
event.preventDefault();
|
||||
const form = event.target;
|
||||
const fileInput = form.querySelector('input[name="file"]');
|
||||
const file = fileInput.files[0];
|
||||
|
||||
if (!file) {
|
||||
alert('Выберите файл');
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('csrf_token', form.querySelector('input[name="csrf_token"]').value);
|
||||
|
||||
fetch(`/tasks/${taskId}/attachments/upload`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.error || 'Ошибка при загрузке файла');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Ошибка при загрузке файла');
|
||||
});
|
||||
}
|
||||
|
||||
function deleteAttachment(taskId, attachmentId) {
|
||||
if (!confirm('Удалить вложение?')) return;
|
||||
|
||||
fetch(`/tasks/${taskId}/attachments/${attachmentId}/delete`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: ''
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert(data.error || 'Ошибка');
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user