feat(messages): add file upload input to compose form
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
22801b849d
commit
684428abce
@ -307,7 +307,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="POST" action="{{ url_for('messages_send') }}">
|
||||
<form method="POST" action="{{ url_for('messages_send') }}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if context_type %}
|
||||
<input type="hidden" name="context_type" value="{{ context_type }}">
|
||||
@ -354,6 +354,20 @@
|
||||
<textarea id="content" name="content" rows="8" required placeholder="Napisz wiadomosc..."></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Załączniki (maks. 3 pliki, 15MB łącznie)</label>
|
||||
<div class="file-upload-zone" id="file-drop-zone" style="border: 2px dashed var(--border-color); border-radius: var(--radius); padding: 20px; text-align: center; cursor: pointer; transition: border-color 0.2s;">
|
||||
<input type="file" name="attachments" id="file-input" multiple accept=".jpg,.jpeg,.png,.gif,.pdf,.docx,.xlsx" style="display: none;">
|
||||
<p style="margin: 0; color: var(--text-secondary); font-size: var(--font-size-sm);">
|
||||
Przeciągnij pliki tutaj lub <a href="#" onclick="document.getElementById('file-input').click(); return false;" style="color: var(--primary);">wybierz z dysku</a>
|
||||
</p>
|
||||
<p style="margin: 4px 0 0; color: var(--text-secondary); font-size: var(--font-size-xs);">
|
||||
JPG, PNG, GIF (5MB) · PDF, DOCX, XLSX (10MB)
|
||||
</p>
|
||||
</div>
|
||||
<div id="file-list" style="margin-top: 8px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Wyslij</button>
|
||||
<a href="{{ url_for('messages_inbox') }}" class="btn btn-secondary">Anuluj</a>
|
||||
@ -523,4 +537,63 @@
|
||||
});
|
||||
})();
|
||||
{% endif %}
|
||||
|
||||
// File attachment handling
|
||||
(function() {
|
||||
var dropZone = document.getElementById('file-drop-zone');
|
||||
var fileInput = document.getElementById('file-input');
|
||||
var fileList = document.getElementById('file-list');
|
||||
if (!dropZone) return;
|
||||
|
||||
dropZone.addEventListener('click', function(e) {
|
||||
if (e.target.tagName !== 'A') fileInput.click();
|
||||
});
|
||||
|
||||
dropZone.addEventListener('dragover', function(e) {
|
||||
e.preventDefault();
|
||||
dropZone.style.borderColor = 'var(--primary)';
|
||||
});
|
||||
|
||||
dropZone.addEventListener('dragleave', function() {
|
||||
dropZone.style.borderColor = 'var(--border-color)';
|
||||
});
|
||||
|
||||
dropZone.addEventListener('drop', function(e) {
|
||||
e.preventDefault();
|
||||
dropZone.style.borderColor = 'var(--border-color)';
|
||||
var dt = new DataTransfer();
|
||||
Array.from(e.dataTransfer.files).forEach(function(f) { dt.items.add(f); });
|
||||
Array.from(fileInput.files).forEach(function(f) { dt.items.add(f); });
|
||||
fileInput.files = dt.files;
|
||||
updateFileList();
|
||||
});
|
||||
|
||||
fileInput.addEventListener('change', updateFileList);
|
||||
|
||||
function updateFileList() {
|
||||
var files = Array.from(fileInput.files);
|
||||
if (files.length === 0) {
|
||||
fileList.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
fileList.innerHTML = files.map(function(f, i) {
|
||||
var sizeMB = (f.size / 1024 / 1024).toFixed(1);
|
||||
return '<div style="display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: var(--font-size-sm);">' +
|
||||
'<span style="color: var(--text-secondary);">📎</span> ' +
|
||||
'<span>' + f.name + '</span> ' +
|
||||
'<span style="color: var(--text-secondary);">(' + sizeMB + ' MB)</span> ' +
|
||||
'<a href="#" onclick="removeFile(' + i + '); return false;" style="color: var(--danger); margin-left: auto;">✕</a>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
window.removeFile = function(index) {
|
||||
var dt = new DataTransfer();
|
||||
Array.from(fileInput.files).forEach(function(f, i) {
|
||||
if (i !== index) dt.items.add(f);
|
||||
});
|
||||
fileInput.files = dt.files;
|
||||
updateFileList();
|
||||
};
|
||||
})();
|
||||
{% endblock %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user