From 4b5dcb1c7e736714770f96119b28eefb34d17466 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Sat, 2 Mar 2024 05:47:22 -0700 Subject: [PATCH] revamped column check toggle behavior --- Views/Vehicle/_CollisionRecords.cshtml | 12 ++++---- Views/Vehicle/_Gas.cshtml | 18 +++++------ Views/Vehicle/_OdometerRecords.cshtml | 8 ++--- Views/Vehicle/_ServiceRecords.cshtml | 12 ++++---- Views/Vehicle/_SupplyRecords.cshtml | 16 +++++----- Views/Vehicle/_TaxRecords.cshtml | 10 +++--- Views/Vehicle/_UpgradeRecords.cshtml | 12 ++++---- wwwroot/js/shared.js | 42 +++++++++++++++----------- 8 files changed, 69 insertions(+), 61 deletions(-) diff --git a/Views/Vehicle/_CollisionRecords.cshtml b/Views/Vehicle/_CollisionRecords.cshtml index 59c8910..d37ac20 100644 --- a/Views/Vehicle/_CollisionRecords.cshtml +++ b/Views/Vehicle/_CollisionRecords.cshtml @@ -48,31 +48,31 @@
  • @@ -81,7 +81,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_Gas.cshtml b/Views/Vehicle/_Gas.cshtml index cffc1d5..67b2358 100644 --- a/Views/Vehicle/_Gas.cshtml +++ b/Views/Vehicle/_Gas.cshtml @@ -95,49 +95,49 @@
  • @@ -146,7 +146,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_OdometerRecords.cshtml b/Views/Vehicle/_OdometerRecords.cshtml index 07bf713..50582f4 100644 --- a/Views/Vehicle/_OdometerRecords.cshtml +++ b/Views/Vehicle/_OdometerRecords.cshtml @@ -47,19 +47,19 @@
  • @@ -68,7 +68,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_ServiceRecords.cshtml b/Views/Vehicle/_ServiceRecords.cshtml index d689712..a55728b 100644 --- a/Views/Vehicle/_ServiceRecords.cshtml +++ b/Views/Vehicle/_ServiceRecords.cshtml @@ -48,31 +48,31 @@
  • @@ -81,7 +81,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_SupplyRecords.cshtml b/Views/Vehicle/_SupplyRecords.cshtml index 329cdd9..28aacdf 100644 --- a/Views/Vehicle/_SupplyRecords.cshtml +++ b/Views/Vehicle/_SupplyRecords.cshtml @@ -48,43 +48,43 @@
  • @@ -93,7 +93,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_TaxRecords.cshtml b/Views/Vehicle/_TaxRecords.cshtml index a9c5ef9..ffcbd77 100644 --- a/Views/Vehicle/_TaxRecords.cshtml +++ b/Views/Vehicle/_TaxRecords.cshtml @@ -48,25 +48,25 @@
  • @@ -75,7 +75,7 @@ var elementId = Guid.NewGuid(); diff --git a/Views/Vehicle/_UpgradeRecords.cshtml b/Views/Vehicle/_UpgradeRecords.cshtml index 26a50b3..178e174 100644 --- a/Views/Vehicle/_UpgradeRecords.cshtml +++ b/Views/Vehicle/_UpgradeRecords.cshtml @@ -48,31 +48,31 @@
  • @@ -81,7 +81,7 @@ var elementId = Guid.NewGuid(); diff --git a/wwwroot/js/shared.js b/wwwroot/js/shared.js index d344881..d69094d 100644 --- a/wwwroot/js/shared.js +++ b/wwwroot/js/shared.js @@ -847,7 +847,7 @@ function replenishSupplies() { var quantitybeforeRepl = globalParseFloat($('#supplyRecordQuantity').val()); if (isNaN(replquantity) || (replcost.trim() != '' && isNaN(parsedReplCost))) { Swal.showValidationMessage(`Please enter a valid quantity and cost`); - } else if (replcost.trim() == '' && (isNaN(quantitybeforeRepl) || quantitybeforeRepl == 0)){ + } else if (replcost.trim() == '' && (isNaN(quantitybeforeRepl) || quantitybeforeRepl == 0)) { Swal.showValidationMessage(`Unable to use unit cost calculation, please provide cost`); } return { replquantity, replcost, parsedReplCost } @@ -879,24 +879,14 @@ function replenishSupplies() { } }); } -function showTableColumns(e, isExtraField) { +function showTableColumns(e) { //logic for extra field since we dont hardcode the data-column type - if (isExtraField) { - var showColumn = $(e).is(':checked'); - var columnName = $(e).parent().find('.form-check-label').text(); - if (showColumn) { - $(`[data-column='${columnName}']`).show(); - } else { - $(`[data-column='${columnName}']`).hide(); - } + var showColumn = $(e).is(':checked'); + var columnName = $(e).attr('data-column-toggle'); + if (showColumn) { + $(`[data-column='${columnName}']`).show(); } else { - var showColumn = $(e).is(':checked'); - var columnName = $(e).attr('data-column-toggle'); - if (showColumn) { - $(`[data-column='${columnName}']`).show(); - } else { - $(`[data-column='${columnName}']`).hide(); - } + $(`[data-column='${columnName}']`).hide(); } } function searchTableRows(tabName) { @@ -925,4 +915,22 @@ function searchTableRows(tabName) { updateAggregateLabels(); } }); +} +function loadUserColumnPreferences(columns) { + if (columns.length == 0) { + //user has no preference saved, reset to default + return; + } + //uncheck all columns + $(".col-visible-toggle").prop("checked", false); + //hide all columns + $('[data-column]').hide(); + //toggle visibility of each column + columns.map(x => { + var defaultColumn = $(`[data-column-toggle='${x}'].col-visible-toggle`); + if (defaultColumn.length > 0) { + defaultColumn.prop("checked", true); + $(`[data-column='${x}']`).show(); + } + }); } \ No newline at end of file