Merge pull request #466 from hargata/Hargata/planner.improvement

Moved template modal outside of add modal.
This commit is contained in:
Hargata Softworks
2024-04-07 11:20:42 -06:00
committed by GitHub
9 changed files with 248 additions and 35 deletions

View File

@@ -1913,6 +1913,33 @@ namespace CarCareTracker.Controllers
} }
return PartialView("_SupplyRecords", result); return PartialView("_SupplyRecords", result);
} }
[HttpGet]
public IActionResult GetSupplyRecordsForPlanRecordTemplate(int planRecordTemplateId)
{
var viewModel = new SupplyUsageViewModel();
var planRecordTemplate = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId);
if (planRecordTemplate != default && planRecordTemplate.VehicleId != default)
{
var supplies = _supplyRecordDataAccess.GetSupplyRecordsByVehicleId(planRecordTemplate.VehicleId);
if (_config.GetServerEnableShopSupplies())
{
supplies.AddRange(_supplyRecordDataAccess.GetSupplyRecordsByVehicleId(0)); // add shop supplies
}
supplies.RemoveAll(x => x.Quantity <= 0);
bool _useDescending = _config.GetUserConfig(User).UseDescending;
if (_useDescending)
{
supplies = supplies.OrderByDescending(x => x.Date).ToList();
}
else
{
supplies = supplies.OrderBy(x => x.Date).ToList();
}
viewModel.Supplies = supplies;
viewModel.Usage = planRecordTemplate.Supplies;
}
return PartialView("_SupplyUsage", viewModel);
}
[TypeFilter(typeof(CollaboratorFilter))] [TypeFilter(typeof(CollaboratorFilter))]
[HttpGet] [HttpGet]
public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId) public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId)
@@ -1932,7 +1959,11 @@ namespace CarCareTracker.Controllers
{ {
result = result.OrderBy(x => x.Date).ToList(); result = result.OrderBy(x => x.Date).ToList();
} }
return PartialView("_SupplyUsage", result); var viewModel = new SupplyUsageViewModel
{
Supplies = result
};
return PartialView("_SupplyUsage", viewModel);
} }
[HttpPost] [HttpPost]
public IActionResult SaveSupplyRecordToVehicleId(SupplyRecordInput supplyRecord) public IActionResult SaveSupplyRecordToVehicleId(SupplyRecordInput supplyRecord)
@@ -2024,15 +2055,11 @@ namespace CarCareTracker.Controllers
{ {
//check if template name already taken. //check if template name already taken.
var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplatesByVehicleId(planRecord.VehicleId).Where(x => x.Description == planRecord.Description).Any(); var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplatesByVehicleId(planRecord.VehicleId).Where(x => x.Description == planRecord.Description).Any();
if (existingRecord) if (planRecord.Id == default && existingRecord)
{ {
return Json(new OperationResponse { Success = false, Message = "A template with that description already exists for this vehicle" }); return Json(new OperationResponse { Success = false, Message = "A template with that description already exists for this vehicle" });
} }
planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList(); planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList();
if (planRecord.Supplies.Any() && planRecord.CopySuppliesAttachment)
{
planRecord.Files.AddRange(GetSuppliesAttachments(planRecord.Supplies));
}
var result = _planRecordTemplateDataAccess.SavePlanRecordTemplateToVehicle(planRecord); var result = _planRecordTemplateDataAccess.SavePlanRecordTemplateToVehicle(planRecord);
return Json(new OperationResponse { Success = result, Message = result ? "Template Added" : StaticHelper.GenericErrorMessage }); return Json(new OperationResponse { Success = result, Message = result ? "Template Added" : StaticHelper.GenericErrorMessage });
} }
@@ -2082,6 +2109,10 @@ namespace CarCareTracker.Controllers
if (existingRecord.Supplies.Any()) if (existingRecord.Supplies.Any())
{ {
existingRecord.RequisitionHistory = RequisitionSupplyRecordsByUsage(existingRecord.Supplies, DateTime.Parse(existingRecord.DateCreated), existingRecord.Description); existingRecord.RequisitionHistory = RequisitionSupplyRecordsByUsage(existingRecord.Supplies, DateTime.Parse(existingRecord.DateCreated), existingRecord.Description);
if (existingRecord.CopySuppliesAttachment)
{
existingRecord.Files.AddRange(GetSuppliesAttachments(existingRecord.Supplies));
}
} }
var result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord.ToPlanRecord()); var result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord.ToPlanRecord());
return Json(new OperationResponse { Success = result, Message = result ? "Plan Record Added" : StaticHelper.GenericErrorMessage }); return Json(new OperationResponse { Success = result, Message = result ? "Plan Record Added" : StaticHelper.GenericErrorMessage });
@@ -2179,6 +2210,12 @@ namespace CarCareTracker.Controllers
return Json(result); return Json(result);
} }
[HttpGet] [HttpGet]
public IActionResult GetPlanRecordTemplateForEditById(int planRecordTemplateId)
{
var result = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId);
return PartialView("_PlanRecordTemplateEditModal", result);
}
[HttpGet]
public IActionResult GetPlanRecordForEditById(int planRecordId) public IActionResult GetPlanRecordForEditById(int planRecordId)
{ {
var result = _planRecordDataAccess.GetPlanRecordById(planRecordId); var result = _planRecordDataAccess.GetPlanRecordById(planRecordId);

View File

@@ -0,0 +1,8 @@
namespace CarCareTracker.Models
{
public class SupplyUsageViewModel
{
public List<SupplyRecord> Supplies { get; set; } = new List<SupplyRecord>();
public List<SupplyUsage> Usage { get; set; } = new List<SupplyUsage>();
}
}

View File

@@ -101,10 +101,6 @@
</button> </button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" onclick="savePlanRecordTemplate()">@translator.Translate(userLanguage, "Save as Template")</a></li> <li><a class="dropdown-item" href="#" onclick="savePlanRecordTemplate()">@translator.Translate(userLanguage, "Save as Template")</a></li>
@if (!Model.CreatedFromReminder)
{
<li><a class="dropdown-item" href="#" onclick="showPlanRecordTemplatesModal()">@translator.Translate(userLanguage, "View Templates")</a></li>
}
</ul> </ul>
</div> </div>
} }
@@ -130,7 +126,8 @@
id: @Model.Id, id: @Model.Id,
dateCreated: decodeHTMLEntities('@(Model.DateCreated)'), dateCreated: decodeHTMLEntities('@(Model.DateCreated)'),
reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'), reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'),
createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower() createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower(),
isTemplate: false
} }
} }
</script> </script>

View File

@@ -0,0 +1,117 @@
@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@model PlanRecordInput
@{
var isNew = Model.Id == 0;
var userConfig = config.GetUserConfig(User);
var userLanguage = userConfig.UserLanguage;
}
<div class="modal-header">
<h5 class="modal-title">@translator.Translate(userLanguage, "Edit Plan Record Template")<small style="display:none; @(isNew ? "" : "cursor:pointer;")" class="cached-banner ms-2 text-warning" onclick='@(isNew ? "" : $"showEditPlanRecordTemplateModal({Model.Id}, true)" )'>@translator.Translate(userLanguage, "Unsaved Changes")</small></h5>
<button type="button" class="btn-close" onclick="hideAddPlanRecordModal()" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-12">
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
<label for="planRecordDescription">@translator.Translate(userLanguage, "Description")</label>
<input type="text" id="planRecordDescription" class="form-control" placeholder="@translator.Translate(userLanguage, "Describe the Plan")" value="@Model.Description">
<label for="planRecordCost">@translator.Translate(userLanguage, "Cost")</label>
<input type="text" inputmode="decimal" id="planRecordCost" class="form-control" placeholder="@translator.Translate(userLanguage, "Cost of the Plan")" value="@Model.Cost">
@await Html.PartialAsync("_SupplyStore", "PlanRecordTemplate")
<label for="planRecordType">@translator.Translate(userLanguage, "Type")</label>
<select class="form-select" id="planRecordType">
<!option value="ServiceRecord" @(Model.ImportMode == ImportMode.ServiceRecord || isNew ? "selected" : "")>@translator.Translate(userLanguage, "Service")</!option>
<!option value="RepairRecord" @(Model.ImportMode == ImportMode.RepairRecord ? "selected" : "")>@translator.Translate(userLanguage, "Repair")</!option>
<!option value="UpgradeRecord" @(Model.ImportMode == ImportMode.UpgradeRecord ? "selected" : "")>@translator.Translate(userLanguage, "Upgrade")</!option>
</select>
<label for="planRecordPriority">@translator.Translate(userLanguage, "Priority")</label>
<select class="form-select" id="planRecordPriority">
<!option value="Critical" @(Model.Priority == PlanPriority.Critical ? "selected" : "")>@translator.Translate(userLanguage, "Critical")</!option>
<!option value="Normal" @(Model.Priority == PlanPriority.Normal || isNew ? "selected" : "")>@translator.Translate(userLanguage, "Normal")</!option>
<!option value="Low" @(Model.Priority == PlanPriority.Low ? "selected" : "")>@translator.Translate(userLanguage, "Low")</!option>
</select>
<label for="planRecordProgress">@translator.Translate(userLanguage, "Current Stage")</label>
<select class="form-select" id="planRecordProgress">
<!option value = "Backlog" @(Model.Progress == PlanProgress.Backlog || isNew ? "selected" : "")>@translator.Translate(userLanguage, "Planned")</!option>
<!option value="InProgress" @(Model.Progress == PlanProgress.InProgress ? "selected" : "")>@translator.Translate(userLanguage, "Doing")</!option>
<!option value = "Testing" @(Model.Progress == PlanProgress.Testing ? "selected" : "")>@translator.Translate(userLanguage, "Testing")</!option>
</select>
@foreach (ExtraField field in Model.ExtraFields)
{
var elementId = Guid.NewGuid();
<div class="extra-field">
<label for="@elementId">@field.Name</label>
<input type="text" id="@elementId" class="form-control @(field.IsRequired ? "extra-field-required" : "")" placeholder="@field.Name" value="@field.Value">
</div>
}
</div>
<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>
<textarea id="planRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
@if (Model.Files.Any())
{
<div>
@await Html.PartialAsync("_UploadedFiles", Model.Files)
<label for="planRecordFiles">@translator.Translate(userLanguage, "Upload more documents")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="planRecordFiles">
<br /><small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
</div>
}
else
{
<label for="planRecordFiles">@translator.Translate(userLanguage, "Upload documents(optional)")</label>
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept="@config.GetAllowedFileUploadExtensions()" class="form-control-file" id="planRecordFiles">
<br />
<small class="text-body-secondary">@translator.Translate(userLanguage, "Max File Size: 28.6MB")</small>
}
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
@if (!isNew)
{
@if (Model.RequisitionHistory.Any())
{
<button type="button" class="btn btn-warning" onclick="toggleSupplyUsageHistory()"><i class="bi bi-shop"></i></button>
}
<button type="button" class="btn btn-danger" onclick="deletePlannerRecordTemplate(@Model.Id)" style="margin-right:auto;">@translator.Translate(userLanguage, "Delete")</button>
}
<button type="button" class="btn btn-secondary" onclick="hideAddPlanRecordModal()">@translator.Translate(userLanguage, "Cancel")</button>
<button type="button" class="btn btn-primary" onclick="savePlanRecordTemplate(true)">@translator.Translate(userLanguage, "Edit Plan Record Template")</button>
</div>
@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory)
<script>
var uploadedFiles = [];
var selectedSupplies = [];
var copySuppliesAttachments = @Model.CopySuppliesAttachment.ToString().ToLower();
getUploadedFilesFromModel();
getSelectedSuppliesFromModel();
function getUploadedFilesFromModel() {
@foreach (UploadedFiles filesUploaded in Model.Files)
{
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
}
}
function getSelectedSuppliesFromModel() {
@foreach(SupplyUsage supplyUsage in Model.Supplies)
{
@:selectedSupplies.push({supplyId: @supplyUsage.SupplyId, quantity: @supplyUsage.Quantity})
}
}
function getPlanRecordModelData() {
return {
id: @Model.Id,
dateCreated: decodeHTMLEntities('@(Model.DateCreated)'),
reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'),
createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower(),
isTemplate: true
}
}
</script>

View File

@@ -20,7 +20,7 @@
<tr class="d-flex"> <tr class="d-flex">
<th scope="col" class="col-8">@translator.Translate(userLanguage,"Description")</th> <th scope="col" class="col-8">@translator.Translate(userLanguage,"Description")</th>
<th scope="col" class="col-2">@translator.Translate(userLanguage, "Use")</th> <th scope="col" class="col-2">@translator.Translate(userLanguage, "Use")</th>
<th scope="col" class="col-2">@translator.Translate(userLanguage, "Delete")</th> <th scope="col" class="col-2">@translator.Translate(userLanguage, "Edit")</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -67,7 +67,7 @@
} }
</td> </td>
<td class="col-2"><button type="button" class="btn btn-primary" onclick="usePlannerRecordTemplate(@planRecordTemplate.Id)"><i class="bi bi-plus-square"></i></button></td> <td class="col-2"><button type="button" class="btn btn-primary" onclick="usePlannerRecordTemplate(@planRecordTemplate.Id)"><i class="bi bi-plus-square"></i></button></td>
<td class="col-2"><button type="button" class="btn btn-danger" onclick="deletePlannerRecordTemplate(@planRecordTemplate.Id)"><i class="bi bi-trash"></i></button></td> <td class="col-2"><button type="button" class="btn btn-warning" onclick="showEditPlanRecordTemplateModal(@planRecordTemplate.Id)"><i class="bi bi-pencil-square"></i></button></td>
</tr> </tr>
} }
</tbody> </tbody>

View File

@@ -28,6 +28,8 @@
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" onclick="showBulkImportModal('PlanRecord')">@translator.Translate(userLanguage,"Import via CSV")</a></li> <li><a class="dropdown-item" href="#" onclick="showBulkImportModal('PlanRecord')">@translator.Translate(userLanguage,"Import via CSV")</a></li>
<li><a class="dropdown-item" href="#" onclick="exportVehicleData('PlanRecord')">@translator.Translate(userLanguage,"Export to CSV")</a></li> <li><a class="dropdown-item" href="#" onclick="exportVehicleData('PlanRecord')">@translator.Translate(userLanguage,"Export to CSV")</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" onclick="showPlanRecordTemplatesModal()">@translator.Translate(userLanguage, "View Templates")</a></li>
</ul> </ul>
</div> </div>
} }
@@ -102,7 +104,7 @@
</div> </div>
</div> </div>
<div class="modal fade" data-bs-focus="false" id="planRecordTemplateModal" tabindex="-1" role="dialog" aria-hidden="true" data-bs-backdrop="static" data-bs-keyboard="false"> <div class="modal fade" data-bs-focus="false" id="planRecordTemplateModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content" id="planRecordTemplateModalContent"> <div class="modal-content" id="planRecordTemplateModalContent">
</div> </div>

View File

@@ -33,6 +33,7 @@
$('#upgradeRecordCost').val(selectedSupplyResult.totalSum); $('#upgradeRecordCost').val(selectedSupplyResult.totalSum);
break; break;
case "PlanRecord": case "PlanRecord":
case "PlanRecordTemplate":
$('#planRecordCost').val(selectedSupplyResult.totalSum); $('#planRecordCost').val(selectedSupplyResult.totalSum);
break; break;
} }
@@ -53,6 +54,7 @@
$('#upgradeRecordModal').modal('hide'); $('#upgradeRecordModal').modal('hide');
break; break;
case "PlanRecord": case "PlanRecord":
case "PlanRecordTemplate":
$('#planRecordModal').modal('hide'); $('#planRecordModal').modal('hide');
break; break;
} }
@@ -70,6 +72,7 @@
$('#upgradeRecordModal').modal('show'); $('#upgradeRecordModal').modal('show');
break; break;
case "PlanRecord": case "PlanRecord":
case "PlanRecordTemplate":
$('#planRecordModal').modal('show'); $('#planRecordModal').modal('show');
break; break;
} }
@@ -83,14 +86,27 @@
} }
} }
function getSupplies() { function getSupplies() {
var vehicleId = GetVehicleId().vehicleId; var caller = GetCaller().tab;
$.get(`/Vehicle/GetSupplyRecordsForRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) { if (caller == 'PlanRecordTemplate') {
if (data) { var planRecordTemplateId = getPlanRecordModelData().id;
hideParentModal(); $.get(`/Vehicle/GetSupplyRecordsForPlanRecordTemplate?planRecordTemplateId=${planRecordTemplateId}`, function (data) {
$("#inputSuppliesModalContent").html(data); if (data) {
$('#inputSuppliesModal').modal('show'); hideParentModal();
} $("#inputSuppliesModalContent").html(data);
}) $('#inputSuppliesModal').modal('show');
recalculateTotal();
}
});
} else {
var vehicleId = GetVehicleId().vehicleId;
$.get(`/Vehicle/GetSupplyRecordsForRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) {
if (data) {
hideParentModal();
$("#inputSuppliesModalContent").html(data);
$('#inputSuppliesModal').modal('show');
}
});
}
} }
function hideSuppliesModal() { function hideSuppliesModal() {
$('#inputSuppliesModal').modal('hide'); $('#inputSuppliesModal').modal('hide');

View File

@@ -4,15 +4,15 @@
@{ @{
var userConfig = config.GetUserConfig(User); var userConfig = config.GetUserConfig(User);
var userLanguage = userConfig.UserLanguage; var userLanguage = userConfig.UserLanguage;
var recordTags = Model.SelectMany(x => x.Tags).Distinct(); var recordTags = Model.Supplies.SelectMany(x => x.Tags).Distinct();
} }
@model List<SupplyRecord> @model SupplyUsageViewModel
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title">@translator.Translate(userLanguage,"Select Supplies")</h5> <h5 class="modal-title">@translator.Translate(userLanguage,"Select Supplies")</h5>
<button type="button" class="btn-close" onclick="hideSuppliesModal()" aria-label="Close"></button> <button type="button" class="btn-close" onclick="hideSuppliesModal()" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
@if (Model.Any()) @if (Model.Supplies.Any())
{ {
<div class="row"> <div class="row">
<div class="col-12" style="max-height:50vh; overflow-y:auto;" id="supplies-table"> <div class="col-12" style="max-height:50vh; overflow-y:auto;" id="supplies-table">
@@ -37,11 +37,12 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (SupplyRecord supplyRecord in Model) @foreach (SupplyRecord supplyRecord in Model.Supplies)
{ {
var supplyUsage = Model.Usage.Where(x => x.SupplyId == supplyRecord.Id).SingleOrDefault();
<tr class="d-flex" id="supplyRows" data-tags='@string.Join(" ", supplyRecord.Tags)'> <tr class="d-flex" id="supplyRows" data-tags='@string.Join(" ", supplyRecord.Tags)'>
<td class="col-1"><input class="form-check-input" type="checkbox" onchange="toggleQuantityFieldDisabled(this)" value="@supplyRecord.Id"></td> <td class="col-1"><input class="form-check-input" type="checkbox" onchange="toggleQuantityFieldDisabled(this)" value="@supplyRecord.Id" @(supplyUsage == default ? "" : "checked")></td>
<td class="col-2"><input type="text" inputmode="decimal" disabled onchange="recalculateTotal()" class="form-control"></td> <td class="col-2"><input type="text" inputmode="decimal" @(supplyUsage == default ? "disabled" : "") value="@(supplyUsage == default ? "" : supplyUsage.Quantity)" onchange="recalculateTotal()" class="form-control"></td>
<td class="col-2 supplyquantity">@supplyRecord.Quantity</td> <td class="col-2 supplyquantity">@supplyRecord.Quantity</td>
<td class="col-2 text-truncate">@StaticHelper.TruncateStrings(supplyRecord.PartNumber)</td> <td class="col-2 text-truncate">@StaticHelper.TruncateStrings(supplyRecord.PartNumber)</td>
<td class="col-3 text-truncate">@StaticHelper.TruncateStrings(supplyRecord.Description)</td> <td class="col-3 text-truncate">@StaticHelper.TruncateStrings(supplyRecord.Description)</td>

View File

@@ -14,7 +14,8 @@ function showEditPlanRecordModal(planRecordId, nocache) {
if (existingContent.trim() != '') { if (existingContent.trim() != '') {
//check if id is same. //check if id is same.
var existingId = getPlanRecordModelData().id; var existingId = getPlanRecordModelData().id;
if (existingId == planRecordId && $('[data-changed=true]').length > 0) { var isNotTemplate = !getPlanRecordModelData().isTemplate;
if (existingId == planRecordId && isNotTemplate && $('[data-changed=true]').length > 0) {
$('#planRecordModal').modal('show'); $('#planRecordModal').modal('show');
$('.cached-banner').show(); $('.cached-banner').show();
return; return;
@@ -36,6 +37,36 @@ function showEditPlanRecordModal(planRecordId, nocache) {
} }
}); });
} }
function showEditPlanRecordTemplateModal(planRecordTemplateId, nocache) {
hidePlanRecordTemplatesModal();
if (!nocache) {
var existingContent = $("#planRecordModalContent").html();
if (existingContent.trim() != '') {
//check if id is same.
var existingId = getPlanRecordModelData().id;
var isTemplate = getPlanRecordModelData().isTemplate;
if (existingId == planRecordTemplateId && isTemplate && $('[data-changed=true]').length > 0) {
$('#planRecordModal').modal('show');
$('.cached-banner').show();
return;
}
}
}
$.get(`/Vehicle/GetPlanRecordTemplateForEditById?planRecordTemplateId=${planRecordTemplateId}`, function (data) {
if (data) {
$("#planRecordModalContent").html(data);
//initiate datepicker
initDatePicker($('#planRecordDate'));
$('#planRecordModal').modal('show');
bindModalInputChanges('planRecordModal');
$('#planRecordModal').off('shown.bs.modal').on('shown.bs.modal', function () {
if (getGlobalConfig().useMarkDown) {
toggleMarkDownOverlay("planRecordNotes");
}
});
}
});
}
function hideAddPlanRecordModal() { function hideAddPlanRecordModal() {
$('#planRecordModal').modal('hide'); $('#planRecordModal').modal('hide');
if (getPlanRecordModelData().createdFromReminder) { if (getPlanRecordModelData().createdFromReminder) {
@@ -98,22 +129,19 @@ function showPlanRecordTemplatesModal() {
$.get(`/Vehicle/GetPlanRecordTemplatesForVehicleId?vehicleId=${vehicleId}`, function (data) { $.get(`/Vehicle/GetPlanRecordTemplatesForVehicleId?vehicleId=${vehicleId}`, function (data) {
if (data) { if (data) {
$("#planRecordTemplateModalContent").html(data); $("#planRecordTemplateModalContent").html(data);
hideAddPlanRecordModal();
$('#planRecordTemplateModal').modal('show'); $('#planRecordTemplateModal').modal('show');
} }
}); });
} }
function hidePlanRecordTemplatesModal() { function hidePlanRecordTemplatesModal() {
$('#planRecordTemplateModal').modal('hide'); $('#planRecordTemplateModal').modal('hide');
$('#planRecordModal').modal('show');
} }
function usePlannerRecordTemplate(planRecordTemplateId) { function usePlannerRecordTemplate(planRecordTemplateId) {
$.post(`/Vehicle/ConvertPlanRecordTemplateToPlanRecord?planRecordTemplateId=${planRecordTemplateId}`, function (data) { $.post(`/Vehicle/ConvertPlanRecordTemplateToPlanRecord?planRecordTemplateId=${planRecordTemplateId}`, function (data) {
if (data.success) { if (data.success) {
var vehicleId = GetVehicleId().vehicleId; var vehicleId = GetVehicleId().vehicleId;
successToast(data.message); successToast(data.message);
$('#planRecordTemplateModal').modal('hide'); hidePlanRecordTemplatesModal();
hideAddPlanRecordModal();
saveScrollPosition(); saveScrollPosition();
getVehiclePlanRecords(vehicleId); getVehiclePlanRecords(vehicleId);
} else { } else {
@@ -136,6 +164,7 @@ function deletePlannerRecordTemplate(planRecordTemplateId) {
$("#workAroundInput").hide(); $("#workAroundInput").hide();
if (data) { if (data) {
successToast("Template Deleted"); successToast("Template Deleted");
hideAddPlanRecordModal();
hidePlanRecordTemplatesModal(); hidePlanRecordTemplatesModal();
} else { } else {
errorToast(genericErrorMessage()); errorToast(genericErrorMessage());
@@ -146,7 +175,7 @@ function deletePlannerRecordTemplate(planRecordTemplateId) {
} }
}); });
} }
function savePlanRecordTemplate() { function savePlanRecordTemplate(isEdit) {
//get values //get values
var formValues = getAndValidatePlanRecordValues(); var formValues = getAndValidatePlanRecordValues();
//validate //validate
@@ -157,7 +186,13 @@ function savePlanRecordTemplate() {
//save to db. //save to db.
$.post('/Vehicle/SavePlanRecordTemplateToVehicleId', { planRecord: formValues }, function (data) { $.post('/Vehicle/SavePlanRecordTemplateToVehicleId', { planRecord: formValues }, function (data) {
if (data.success) { if (data.success) {
successToast(data.message); if (isEdit) {
hideAddPlanRecordModal();
showPlanRecordTemplatesModal();
successToast('Plan Template Updated');
} else {
successToast('Plan Template Added');
}
} else { } else {
errorToast(data.message); errorToast(data.message);
} }