From 70e02dfeffb0554ca3ef399ad4b3ccb4af79a53d Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 3 Apr 2021 16:01:11 -0600 Subject: [PATCH] Update rates page --- www/assets/js/rates.js | 99 +++++++++++++++++++++++++++--------------- www/pages/rates.html | 6 +-- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/www/assets/js/rates.js b/www/assets/js/rates.js index 925fdf8..e7d4b8e 100644 --- a/www/assets/js/rates.js +++ b/www/assets/js/rates.js @@ -4,44 +4,73 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +var itemTypeCharacteristics = { + "Parcel": {weight: true, size: true, lbs: true}, + // USPS + "Card": {weight: false, size: false, lbs: false}, + "Letter": {weight: true, size: false, lbs: false}, + "Flat": {weight: true, size: false, lbs: true}, + "FlatRateEnvelope": {weight: false, size: false, lbs: false}, + "FlatRateLegalEnvelope": {weight: false, size: false, lbs: false}, + "FlatRatePaddedEnvelope": {weight: false, size: false, lbs: false}, + "SmallFlatRateBox": {weight: false, size: false, lbs: false}, + "MediumFlatRateBox": {weight: false, size: false, lbs: false}, + "LargeFlatRateBox": {weight: false, size: false, lbs: false}, + "LargeFlatRateBoxAPOFPO": {weight: false, size: false, lbs: false}, + "RegionalRateBoxA": {weight: true, size: false, lbs: true}, + "RegionalRateBoxB": {weight: true, size: false, lbs: true}, + // UPS + "UPSLetter": {weight: true, size: false, lbs: true}, + "UPSExpressBox": {weight: true, size: false, lbs: true}, + "Pak": {weight: true, size: false, lbs: true}, + "Tube": {weight: true, size: false, lbs: true}, + "SmallExpressBox": {weight: true, size: false, lbs: true}, + "MediumExpressBox": {weight: true, size: false, lbs: true}, + "LargeExpressBox": {weight: true, size: false, lbs: true}, + // FedEx + "FedExEnvelope": {weight: true, size: false, lbs: true}, + "FedExBox": {weight: true, size: false, lbs: true}, + "FedExPak": {weight: true, size: false, lbs: true}, + "FedExTube": {weight: true, size: false, lbs: true}, + "FedExSmallBox": {weight: true, size: false, lbs: true}, + "FedExMediumBox": {weight: true, size: false, lbs: true}, + "FedExLargeBox": {weight: true, size: false, lbs: true}, + "FedExExtraLargeBox": {weight: true, size: false, lbs: true} +}; + function updateRateForm() { $("#itemweight").css("display", "none"); $("#itemsize").css("display", "none"); - $("#itemweightlbs").css("display", ""); - switch ($("#itemType").val()) { - case "Card": - $("#itemweight").css("display", "none"); - $("#weightLbs").val("0"); - $("#weightOz").val("0"); - break; - case "Letter": - $("#itemweight").css("display", ""); - $("#itemweightlbs").css("display", "none"); - $("#weightLbs").val("0"); - break; - case "Flat": - $("#itemweight").css("display", ""); - break; - case "Parcel": - $("#itemweight").css("display", ""); - $("#itemsize").css("display", ""); - break; - case "RegionalRateBoxA": - case "RegionalRateBoxB": - $("#itemweight").css("display", ""); - break; - case "Pak": - case "Tube": - case "SmallExpressBox": - case "MediumExpressBox": - case "LargeExpressBox": - $("#itemweight").css("display", ""); - break; - default: - if ($("#itemType").val().startsWith("UPS") || $("#itemType").val().startsWith("FedEx")) { - $("#itemweight").css("display", ""); - } - break; + $("#itemweightlbs").css("display", "none"); + + if ($("#itemType").val() == "") { + // no selection, leave all boxes hidden + return; + } + if (typeof itemTypeCharacteristics[$("#itemType").val()] == 'undefined') { + // not in list of item type info + $("#itemweight").css("display", ""); + $("#itemsize").css("display", ""); + $("#itemweightlbs").css("display", ""); + return; + } + + var chars = itemTypeCharacteristics[$("#itemType").val()]; + if (chars.weight) { + // show weight box for ounces + $("#itemweight").css("display", ""); + } else { + $("#weightLbs").val("0"); + $("#weightOz").val("0"); + } + if (chars.lbs) { + // show weight box for pounds + $("#itemweightlbs").css("display", ""); + } else { + $("#weightLbs").val("0"); + } + if (chars.size) { + $("#itemsize").css("display", ""); } } diff --git a/www/pages/rates.html b/www/pages/rates.html index 7f2dfd8..b7378bf 100644 --- a/www/pages/rates.html +++ b/www/pages/rates.html @@ -69,7 +69,7 @@