#21 -- Fix file upload form

This commit is contained in:
Anton Romanov 2025-04-03 22:47:16 +04:00
parent 82823d6245
commit 3d69996091

View File

@ -12,84 +12,14 @@
<p th:text="${i.name}"></p>
<p th:text="${i.proofDocuments}"></p>
<p th:text="'Максимальное количество баллов за показатель: '+ ${i.max}"></p>
<div class="form-group">
<button class="form-control btn btn-danger" type="button" onclick="deleteAllFiles();">Удалить все
документы
</button>
</div>
<div id="input-file" class="form-group">
<button class="btn btn-primary btn-upload btn-choose pull-right" type="button">Обзор</button>
<button class="btn btn-success btn-upload" type="button" onclick="uploadFile();">Загрузить</button>
</div>
<div id="file-input-list" class="form-group">
<div class="mb-3">
<label for="formFile" class="form-label">Загрузка подтверждающих документов</label>
<input class="form-control" type="file" id="formFile">
<input class="form-control" type="file" id="formFile2">
<input class="form-control" type="file" id="formFile3">
</div>
</div>
<th:block layout:fragment="scripts">
<script src="/js/bootstrap.file-input.js"></script>
<script th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function() {
uploadFile = function(index = 0) {
const files = $('#input-file .input-ghost').prop('files');
if (index == 0) {
showFeedbackMessage();
$('button').prop('disabled', true);
}
if (index >= files.length) {
$('button').prop('disabled', false);
$('#input-file .input-ghost').val('');
return;
}
$('#file-' + index + ' i').removeClass('fa-circle-o').addClass('fa-circle-o-notch fa-spin');
$('#file-' + index).removeClass('alert-danger alert-success');
var response = false;
var formData = new FormData();
formData.append('file', files[index]);
uploadAjax('api/1.0/documents.upload', formData,
(result) => {
if (!result) {
return;
}
response = result.response;
},
null,
() => {
var resultIcon = 'fa-times-circle-o';
var resultStyle = 'alert-danger';
if (response) {
resultIcon = 'fa-check-circle-o';
resultStyle = 'alert-success';
}
$('#file-' + index + ' i').removeClass('fa-circle-o-notch fa-spin').addClass(resultIcon);
$('#file-' + index).addClass(resultStyle);
uploadFile(index + 1);
});
};
deleteAllFiles = function() {
$('#file-input-list').html('');
//input.replaceWith(input = input.val('').clone(true));
$('#spinner').show()
getAjax('api/1.0/documents.delete_all',
(result) => {
if (result.response) {
showFeedbackMessage('Удалено ' + result.response + ' документов');
}
if (result.error) {
showFeedbackMessage(result.error, 'danger');
}
},
null,
() => $('#spinner').hide(),
'DELETE'
);
};
$('#input-file').bootstrapFileInput(true);
});
/*]]>*/
</script>
</th:block>
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
<button name="delete"