allow users to attach a link as a document to a record.

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD 2025-06-18 13:15:10 -06:00
parent 2eab072e6d
commit 16f9740b6c
17 changed files with 183 additions and 187 deletions

View File

@ -1868,7 +1868,7 @@ namespace CarCareTracker.Controllers
{ {
if (documents.Any()) if (documents.Any())
{ {
List<UploadedFiles> uploadedFiles = new List<UploadedFiles>(); List<UploadedFileExportModel> uploadedFiles = new List<UploadedFileExportModel>();
string uploadDirectory = "documents/"; string uploadDirectory = "documents/";
string uploadPath = Path.Combine(_webEnv.ContentRootPath, "data", uploadDirectory); string uploadPath = Path.Combine(_webEnv.ContentRootPath, "data", uploadDirectory);
if (!Directory.Exists(uploadPath)) if (!Directory.Exists(uploadPath))
@ -1881,10 +1881,11 @@ namespace CarCareTracker.Controllers
{ {
document.CopyTo(stream); document.CopyTo(stream);
} }
uploadedFiles.Add(new UploadedFiles uploadedFiles.Add(new UploadedFileExportModel
{ {
Location = Path.Combine("/", uploadDirectory, fileName), Location = Path.Combine("/", uploadDirectory, fileName),
Name = Path.GetFileName(document.FileName) Name = Path.GetFileName(document.FileName),
UploadType = FileUploadType.File.ToString()
}); });
} }
return Json(uploadedFiles); return Json(uploadedFiles);

View File

@ -172,4 +172,10 @@ namespace CarCareTracker.Models
[JsonConverter(typeof(FromBoolOptional))] [JsonConverter(typeof(FromBoolOptional))]
public string IsRoot { get; set; } public string IsRoot { get; set; }
} }
public class UploadedFileExportModel
{
public string Name { get; set; }
public string Location { get; set; }
public string UploadType { get; set; }
}
} }

View File

@ -57,26 +57,19 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="collisionRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="collisionRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="collisionRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="collisionRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) @if (isNew)
{ {
<div> <div class="form-check">
@await Html.PartialAsync("_UploadedFiles", Model.Files) <input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
@await Html.PartialAsync("_FileUploader", true) <label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div> </div>
} }
else <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
@if (isNew) @await Html.PartialAsync("_FileUploader", Model.Files.Any())
{ </div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
<label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div>
}
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -114,7 +107,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "collisionRecordCost" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "collisionRecordCost" })
<script> <script>
var uploadedFiles = [];
var selectedSupplies = []; var selectedSupplies = [];
var copySuppliesAttachments = false; var copySuppliesAttachments = false;
var recurringReminderRecordId = []; var recurringReminderRecordId = [];

View File

@ -9,16 +9,12 @@
@model bool @model bool
<label for="@uploaderId">@translator.Translate(userLanguage, Model ? "Upload more documents" : "Upload documents(optional)")</label> <label for="@uploaderId">@translator.Translate(userLanguage, Model ? "Upload more documents" : "Upload documents(optional)")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="d-none" id="@uploaderId"> <input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="d-none" id="@uploaderId">
<div class="lubelogger-uploader d-flex justify-content-center align-items-center align-content-center" onclick="toggleUploadFileBrowser(this)"> <div class="lubelogger-uploader d-flex justify-content-center align-items-center align-content-center" onclick="toggleUploadFileBrowser(this)" ondragover="handlePotentialFileDrop(event)" ondragleave="handleNoFileDrop(event)" ondrop="handleEndFileDrop(event)">
<div class="lubelogger-link-uploader"><button class="btn btn-sm btn-primary" type="button" onclick="uploadVehicleLinksAsync(event)">Attach Link</button></div> <div class="lubelogger-link-uploader"><button class="btn btn-sm btn-primary" type="button" onclick="uploadVehicleLinksAsync(event)">@translator.Translate(userLanguage, "Attach Link")</button></div>
<span class="text-center"><span class="lead"><i class="bi bi-upload"></i></span><br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small></span> <span class="text-center"><span class="lead"><i class="bi bi-upload"></i></span><br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small></span>
</div> </div>
<script> <script>
function getUploaderId(){ function getUploaderId(){
return {uploaderId: '@uploaderId'}; return {uploaderId: '@uploaderId'};
} }
function toggleUploadFileBrowser(sender){
let uploaderId = getUploaderId().uploaderId;
$(`#${uploaderId}`).trigger('click');
}
</script> </script>

View File

@ -102,17 +102,10 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="gasRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="gasRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="gasRecordNotes" class="form-control" rows="5">@Model.GasRecord.Notes</textarea> <textarea id="gasRecordNotes" class="form-control" rows="5">@Model.GasRecord.Notes</textarea>
@if (Model.GasRecord.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.GasRecord.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.GasRecord.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.GasRecord.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -135,7 +128,6 @@
} }
</div> </div>
<script> <script>
var uploadedFiles = [];
function getGasRecordModelData(){ function getGasRecordModelData(){
return { id: @Model.GasRecord.Id} return { id: @Model.GasRecord.Id}
} }

View File

@ -30,17 +30,10 @@
<textarea class="form-control vehicleNoteContainer" id="noteTextArea">@Model.NoteText</textarea> <textarea class="form-control vehicleNoteContainer" id="noteTextArea">@Model.NoteText</textarea>
</div> </div>
<div class="col-12"> <div class="col-12">
@if (Model.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
<div class="col-12"> <div class="col-12">
@ -72,7 +65,6 @@
} }
</div> </div>
<script> <script>
var uploadedFiles = [];
function getNoteModelData(){ function getNoteModelData(){
return { id: @Model.Id} return { id: @Model.Id}
} }

View File

@ -77,17 +77,10 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="odometerRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="odometerRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="odometerRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="odometerRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -116,7 +109,6 @@
} }
</div> </div>
<script> <script>
var uploadedFiles = [];
//Trip Recording Variables //Trip Recording Variables
var tripTimer = undefined; //interval to check GPS Location every 5 seconds. var tripTimer = undefined; //interval to check GPS Location every 5 seconds.
var tripWakeLock = undefined; //wakelock handler to prevent screen from going to sleep. var tripWakeLock = undefined; //wakelock handler to prevent screen from going to sleep.

View File

@ -50,17 +50,10 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="planRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="planRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="planRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="planRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -96,7 +89,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" })
<script> <script>
var uploadedFiles = [];
var selectedSupplies = []; var selectedSupplies = [];
var copySuppliesAttachments = false; var copySuppliesAttachments = false;
function getPlanRecordModelData() { function getPlanRecordModelData() {

View File

@ -45,17 +45,10 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="planRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="planRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="planRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="planRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -76,7 +69,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "planRecordCost" })
<script> <script>
var uploadedFiles = [];
var selectedSupplies = []; var selectedSupplies = [];
var copySuppliesAttachments = @Model.CopySuppliesAttachment.ToString().ToLower(); var copySuppliesAttachments = @Model.CopySuppliesAttachment.ToString().ToLower();
getSelectedSuppliesFromModel(); getSelectedSuppliesFromModel();

View File

@ -57,26 +57,19 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="serviceRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="serviceRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="serviceRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="serviceRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) @if (isNew)
{ {
<div> <div class="form-check">
@await Html.PartialAsync("_UploadedFiles", Model.Files) <input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
@await Html.PartialAsync("_FileUploader", true) <label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div> </div>
} }
else <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
@if (isNew) @await Html.PartialAsync("_FileUploader", Model.Files.Any())
{ </div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
<label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage,"Add Reminder")
</label>
</div>
}
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -114,7 +107,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "serviceRecordCost" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "serviceRecordCost" })
<script> <script>
var uploadedFiles = [];
var selectedSupplies = []; var selectedSupplies = [];
var recurringReminderRecordId = []; var recurringReminderRecordId = [];
var copySuppliesAttachments = false; var copySuppliesAttachments = false;

View File

@ -55,17 +55,10 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="supplyRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="supplyRecordNotes">@translator.Translate(userLanguage,"Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="supplyRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="supplyRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
<div> @await Html.PartialAsync("_FileUploader", Model.Files.Any())
@await Html.PartialAsync("_UploadedFiles", Model.Files) </div>
@await Html.PartialAsync("_FileUploader", true)
</div>
}
else
{
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -93,7 +86,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "" })
<script> <script>
var uploadedFiles = [];
function getSupplyRecordModelData() { function getSupplyRecordModelData() {
return { id: @Model.Id} return { id: @Model.Id}
} }

View File

@ -61,26 +61,19 @@
<!option value="ThreeYears" @(Model.RecurringInterval == ReminderMonthInterval.ThreeYears ? "selected" : "")>@translator.Translate(userLanguage, "3 Years")</!option> <!option value="ThreeYears" @(Model.RecurringInterval == ReminderMonthInterval.ThreeYears ? "selected" : "")>@translator.Translate(userLanguage, "3 Years")</!option>
<!option value="FiveYears" @(Model.RecurringInterval == ReminderMonthInterval.FiveYears ? "selected" : "")>@translator.Translate(userLanguage, "5 Years")</!option> <!option value="FiveYears" @(Model.RecurringInterval == ReminderMonthInterval.FiveYears ? "selected" : "")>@translator.Translate(userLanguage, "5 Years")</!option>
</select> </select>
@if (Model.Files.Any()) @if (isNew)
{ {
<div> <div class="form-check">
@await Html.PartialAsync("_UploadedFiles", Model.Files) <input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
@await Html.PartialAsync("_FileUploader", true) <label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div> </div>
} }
else <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
@if (isNew) @await Html.PartialAsync("_FileUploader", Model.Files.Any())
{ </div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
<label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage,"Add Reminder")
</label>
</div>
}
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -103,7 +96,6 @@
} }
</div> </div>
<script> <script>
var uploadedFiles = [];
var customMonthInterval = @Model.CustomMonthInterval; var customMonthInterval = @Model.CustomMonthInterval;
var customMonthIntervalUnit = decodeHTMLEntities('@Model.CustomMonthIntervalUnit'); var customMonthIntervalUnit = decodeHTMLEntities('@Model.CustomMonthIntervalUnit');
var recurringReminderRecordId = []; var recurringReminderRecordId = [];

View File

@ -57,26 +57,19 @@
<div class="col-md-6 col-12"> <div class="col-md-6 col-12">
<label for="upgradeRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label> <label for="upgradeRecordNotes">@translator.Translate(userLanguage, "Notes(optional)")<a class="link-underline link-underline-opacity-0" onclick="showLinks(this)"><i class="bi bi-markdown ms-2"></i></a></label>
<textarea id="upgradeRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> <textarea id="upgradeRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any()) @if (isNew)
{ {
<div> <div class="form-check">
@await Html.PartialAsync("_UploadedFiles", Model.Files) <input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
@await Html.PartialAsync("_FileUploader", true) <label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div> </div>
} }
else <div>
{ @await Html.PartialAsync("_UploadedFiles", Model.Files)
@if (isNew) @await Html.PartialAsync("_FileUploader", Model.Files.Any())
{ </div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="addReminderCheck">
<label class="form-check-label" for="addReminderCheck">
@translator.Translate(userLanguage, "Add Reminder")
</label>
</div>
}
@await Html.PartialAsync("_FileUploader", false)
}
<div id="filesPendingUpload"></div> <div id="filesPendingUpload"></div>
</div> </div>
</div> </div>
@ -114,7 +107,6 @@
</div> </div>
@await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "upgradeRecordCost" }) @await Html.PartialAsync("_SupplyRequisitionHistory", new SupplyRequisitionHistory { RequisitionHistory = Model.RequisitionHistory, CostInputId = "upgradeRecordCost" })
<script> <script>
var uploadedFiles = [];
var selectedSupplies = []; var selectedSupplies = [];
var recurringReminderRecordId = []; var recurringReminderRecordId = [];
var copySuppliesAttachments = false; var copySuppliesAttachments = false;

View File

@ -6,26 +6,30 @@
var userLanguage = userConfig.UserLanguage; var userLanguage = userConfig.UserLanguage;
} }
@model List<UploadedFiles> @model List<UploadedFiles>
<label id="uploadedDocumentsLabel">@translator.Translate(userLanguage, "Uploaded Documents")</label> @if (Model.Any())
<ul class="list-group" id="uploadedDocumentsList"> {
@foreach (UploadedFiles filesUploaded in Model) <label id="uploadedDocumentsLabel">@translator.Translate(userLanguage, "Uploaded Documents")</label>
{ <ul class="list-group" id="uploadedDocumentsList">
<li class="list-group-item"> @foreach (UploadedFiles filesUploaded in Model)
<div class="d-flex justify-content-between align-items-center"> {
<a class="uploadedFileName d-flex align-items-center text-truncate" href="@filesUploaded.Location" title="@filesUploaded.Name" target="_blank"> <li class="list-group-item">
<span class="lead me-2"><i class="bi @StaticHelper.GetIconByFileExtension(filesUploaded.UploadType, filesUploaded.FileExtension)"></i></span><span class="text-link">@filesUploaded.Name</span> <div class="d-flex justify-content-between align-items-center">
</a> <a class="uploadedFileName d-flex align-items-center text-truncate" href="@filesUploaded.Location" title="@filesUploaded.Name" target="_blank">
<div class="d-flex align-items-center"> <span class="lead me-2"><i class="bi @StaticHelper.GetIconByFileExtension(filesUploaded.UploadType, filesUploaded.FileExtension)"></i></span><span class="text-link">@filesUploaded.Name</span>
<button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="editFileName('@filesUploaded.Location', this)"><i class="bi bi-pencil"></i></button> </a>
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteFileFromUploadedFiles('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button> <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> </div>
</div> </li>
</li> }
} </ul>
</ul> }
<script> <script>
@foreach (UploadedFiles filesUploaded in Model) var uploadedFiles = [];
{ @foreach (UploadedFiles filesUploaded in Model)
{
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location", uploadType: "@filesUploaded.UploadType" }); @:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location", uploadType: "@filesUploaded.UploadType" });
} }
</script> </script>

View File

@ -566,3 +566,7 @@ html[data-bs-theme="light"] .api-method:hover {
border-top-left-radius: 0; border-top-left-radius: 0;
border-bottom-right-radius: 0; border-bottom-right-radius: 0;
} }
.lubelogger-uploader.solid {
border-style: solid;
}

File diff suppressed because one or more lines are too long

View File

@ -583,38 +583,66 @@ function uploadVehicleFilesAsync(event) {
} }
}); });
} }
function uploadVehicleLinksAsync(event) {
event.stopPropagation();
Swal.fire({
title: 'Add Link',
html: `
<input type="text" id="newLinkName" class="swal2-input" placeholder="Link Name" onkeydown="handleSwalEnter(event)">
<input type="text" id="newLinkLocation" class="swal2-input" placeholder="Link Location" onkeydown="handleSwalEnter(event)">
`,
confirmButtonText: 'Add Link',
focusConfirm: false,
preConfirm: () => {
const newLinkName = $("#newLinkName").val();
const newLinkLocation = $("#newLinkLocation").val();
if (!newLinkName) {
Swal.showValidationMessage(`Please enter a valid link name`);
}
if (!newLinkLocation) {
Swal.showValidationMessage(`Please enter a valid link location`);
}
return { newLinkName, newLinkLocation }
},
}).then(function (result) {
if (result.isConfirmed) {
uploadedFiles.push({ name: result.value.newLinkName, location: result.value.newLinkLocation, uploadType: 1, isPending: true });
$.post('/Vehicle/GetFilesPendingUpload', { uploadedFiles: uploadedFiles }, function (viewData) {
$("#filesPendingUpload").html(viewData);
});
}
});
}
function deleteFileFromUploadedFiles(fileLocation, event) { function deleteFileFromUploadedFiles(fileLocation, event) {
event.parentElement.parentElement.parentElement.remove(); event.parentElement.parentElement.parentElement.remove();
uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation); uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation);
if (fileLocation.startsWith("/temp/")) { if ($("#documentsPendingUploadList > li").length == 0) {
if ($("#documentsPendingUploadList > li").length == 0) { $("#documentsPendingUploadLabel").text("");
$("#documentsPendingUploadLabel").text(""); }
} if ($("#uploadedDocumentsList > li").length == 0) {
} else if (fileLocation.startsWith("/documents/")) { $("#uploadedDocumentsLabel").text("");
if ($("#uploadedDocumentsList > li").length == 0) {
$("#uploadedDocumentsLabel").text("");
}
} }
} }
function editFileName(fileLocation, event) { function editFileName(fileLocation, event) {
let currentFileName = $(event.parentElement.parentElement).find('a > .text-link').text();
Swal.fire({ Swal.fire({
title: 'Rename File', title: 'Rename File or Link',
html: ` html: `
<input type="text" id="newFileName" class="swal2-input" placeholder="New File Name" onkeydown="handleSwalEnter(event)"> <input type="text" id="newFileName" class="swal2-input" placeholder="New Name" onkeydown="handleSwalEnter(event)" value="${currentFileName}">
`, `,
confirmButtonText: 'Rename', confirmButtonText: 'Rename',
focusConfirm: false, focusConfirm: false,
preConfirm: () => { preConfirm: () => {
const newFileName = $("#newFileName").val(); const newFileName = $("#newFileName").val();
if (!newFileName) { if (!newFileName) {
Swal.showValidationMessage(`Please enter a valid file name`) Swal.showValidationMessage(`Please enter a valid name`)
} }
return { newFileName } return { newFileName }
}, },
}).then(function (result) { }).then(function (result) {
if (result.isConfirmed) { if (result.isConfirmed) {
var linkDisplayObject = $(event.parentElement.parentElement).find('a')[0]; var linkDisplayObject = $(event.parentElement.parentElement).find('a > .text-link');
linkDisplayObject.text = result.value.newFileName; linkDisplayObject.text(result.value.newFileName);
var editFileIndex = uploadedFiles.findIndex(x => x.location == fileLocation); var editFileIndex = uploadedFiles.findIndex(x => x.location == fileLocation);
uploadedFiles[editFileIndex].name = result.value.newFileName; uploadedFiles[editFileIndex].name = result.value.newFileName;
} }
@ -1479,7 +1507,8 @@ function bindModalInputChanges(modalName) {
$(e.currentTarget).attr('data-changed', true); $(e.currentTarget).attr('data-changed', true);
}); });
} }
function handleModalPaste(e, recordType) { function handleModalPaste(e) {
let recordType = getUploaderId().uploaderId;
var clipboardFiles = e.clipboardData.files; var clipboardFiles = e.clipboardData.files;
var acceptableFileFormats = $(`#${recordType}`).attr("accept"); var acceptableFileFormats = $(`#${recordType}`).attr("accept");
var acceptableFileFormatsArray = acceptableFileFormats.split(','); var acceptableFileFormatsArray = acceptableFileFormats.split(',');
@ -1595,4 +1624,40 @@ function populateLocationField(fieldName) {
errorToast('Location Services not Enabled'); errorToast('Location Services not Enabled');
} }
} }
}
function toggleUploadFileBrowser() {
let uploaderId = getUploaderId().uploaderId;
$(`#${uploaderId}`).trigger('click');
}
function handlePotentialFileDrop(event) {
event.preventDefault();
$('.lubelogger-uploader').addClass('solid');
}
function handleNoFileDrop(event) {
event.preventDefault();
$('.lubelogger-uploader').removeClass('solid');
}
function handleEndFileDrop(event) {
event.preventDefault();
event.stopPropagation();
$('.lubelogger-uploader').removeClass('solid');
let recordType = getUploaderId().uploaderId;
let clipboardFiles = event.dataTransfer.files;
let acceptableFileFormats = $(`#${recordType}`).attr("accept");
let acceptableFileFormatsArray = acceptableFileFormats.split(',');
let acceptableFiles = new DataTransfer();
if (clipboardFiles.length > 0) {
for (var x = 0; x < clipboardFiles.length; x++) {
if (acceptableFileFormats != "*") {
var fileExtension = `.${clipboardFiles[x].name.split('.').pop()}`;
if (acceptableFileFormatsArray.includes(fileExtension)) {
acceptableFiles.items.add(clipboardFiles[x]);
}
} else {
acceptableFiles.items.add(clipboardFiles[x]);
}
}
$(`#${recordType}`)[0].files = acceptableFiles.files;
$(`#${recordType}`).trigger('change');
}
} }