added ability to rename files on service record page.
This commit is contained in:
@@ -30,14 +30,7 @@
|
||||
@if (Model.Files.Any())
|
||||
{
|
||||
<div>
|
||||
<label>Uploaded Documents</label>
|
||||
@foreach (UploadedFiles filesUploaded in Model.Files)
|
||||
{
|
||||
<div class="d-flex justify-content-between">
|
||||
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteServiceRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
|
||||
</div>
|
||||
}
|
||||
@await Html.PartialAsync("_UploadedFiles", Model.Files)
|
||||
<label for="serviceRecordFiles">Upload more documents</label>
|
||||
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="serviceRecordFiles">
|
||||
</div>
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal fade" id="serviceRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal fade" data-bs-focus="false" id="serviceRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content" id="serviceRecordModalContent">
|
||||
|
||||
|
||||
16
Views/Vehicle/_UploadedFiles.cshtml
Normal file
16
Views/Vehicle/_UploadedFiles.cshtml
Normal file
@@ -0,0 +1,16 @@
|
||||
@model List<UploadedFiles>
|
||||
<label>Uploaded Documents</label>
|
||||
<ul class="list-group">
|
||||
@foreach (UploadedFiles filesUploaded in Model)
|
||||
{
|
||||
<li class="list-group-item">
|
||||
<div class="d-flex justify-content-between">
|
||||
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
|
||||
<div class="d-flex align-items-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="editFileName('@filesUploaded.Location', this)"><i class="bi bi-pencil"></i></button>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteFileFromUploadedFiles('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@@ -121,8 +121,4 @@ function getAndValidateServiceRecordValues() {
|
||||
files: uploadedFiles,
|
||||
addReminderRecord: addReminderRecord
|
||||
}
|
||||
}
|
||||
function deleteServiceRecordFile(fileLocation, event) {
|
||||
event.parentElement.remove();
|
||||
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
|
||||
}
|
||||
@@ -213,4 +213,33 @@ function getVehicleHaveImportantReminders(vehicleId) {
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function deleteFileFromUploadedFiles(fileLocation, event) {
|
||||
event.parentElement.remove();
|
||||
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
|
||||
}
|
||||
function editFileName(fileLocation, event) {
|
||||
Swal.fire({
|
||||
title: 'Rename File',
|
||||
html: `
|
||||
<input type="text" id="newFileName" class="swal2-input" placeholder="New File Name">
|
||||
`,
|
||||
confirmButtonText: 'Rename',
|
||||
focusConfirm: false,
|
||||
preConfirm: () => {
|
||||
const newFileName = $("#newFileName").val();
|
||||
if (!newFileName) {
|
||||
Swal.showValidationMessage(`Please enter a valid file name`)
|
||||
}
|
||||
return { newFileName }
|
||||
},
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
var linkDisplayObject = $(event.parentElement.parentElement).find('a')[0];
|
||||
linkDisplayObject.text = result.value.newFileName;
|
||||
var editFileIndex = uploadedFiles.findIndex(x => x.location == fileLocation);
|
||||
uploadedFiles[editFileIndex].name = result.value.newFileName;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user