From: Michael Orlitzky Date: Thu, 2 Nov 2023 01:48:50 +0000 (-0400) Subject: index.html.in: sketch the MARC zone-setting logic X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=61536310e5cf6df9dc65818bbe86b93cf22686b1;p=charm-bypass.git index.html.in: sketch the MARC zone-setting logic --- diff --git a/index.html.in b/index.html.in index c2e4b02..2dd939f 100644 --- a/index.html.in +++ b/index.html.in @@ -10,8 +10,8 @@ @@ -526,6 +526,67 @@ } } + + /*******************************************************/ + /* Compute the MARC "zone" from its origin/destination */ + /*******************************************************/ + + /* Sorted on the first component, then the second */ + const zone_map = { + BAL_BWE: 2, + BAL_SEB: 3, + BAL_WAS: 4, + BCA_CPK_: 3, + BWI_WBL: 1 + }; + + /* The default. Obviously wrong for when we don't + * have the necessary data. */ + let zone = 0; + + function compute_marc_zone(src, dest) { + /* Forward direction key for zone_map */ + const fwd = src + "_" + dest; + + /* Reverse direction key for zone_map. The zone_map only + * has them listed in one direction, so we check both + * directions here. */ + const rev = dest + "_" + src; + + if (zone_map[fwd]) { + zone = zone_map[fwd]; + } + else if (zone_map[rev]) { + zone = zone_map[rev]; + } + + /* Convert the number to a string */ + switch (zone) { + case 1: + return "One Zone"; + case 2: + return "Two Zone"; + case 3: + return "Three Zone"; + case 4: + return "Four Zone"; + default: + return "??? Zone"; + } + } + + function set_marc_zone() { + const params = new URLSearchParams(document.location.search); + if (params.get("origin") && params.get("destination")) { + const src = params.get("origin"); + const dest = params.get("destination"); + const zone = compute_marc_zone(src, dest); + + /* TODO: actually set the zone */ + alert(zone); + } + } + /******************************************/ /* Display the ticket (and hide the menu) */ /******************************************/ @@ -575,6 +636,9 @@ /* Set the ticket expiration date/time upon page load */ window.addEventListener("load", set_ticket_expiry); + /* Set the MARC Train zone, if applicable */ + window.addEventListener("load", set_marc_zone); + /* Swap colors when the screen is tapped */ document.body.addEventListener("click", swap_colors); }