X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=index.html.in;h=f6094fafa999961ba1abeb17c9f80968f1387903;hb=eecc66f142ac6e3517624db982f3583e4857d6f7;hp=c2e4b026e6b802f24547c330cfb7fcb8c8591f06;hpb=001c586e57cbc38fa28c17acb55880b7e151ab3e;p=charm-bypass.git diff --git a/index.html.in b/index.html.in index c2e4b02..f6094fa 100644 --- a/index.html.in +++ b/index.html.in @@ -10,8 +10,8 @@ @@ -526,6 +526,72 @@ } } + + /*******************************************************/ + /* Compute the MARC "zone" from its origin/destination */ + /*******************************************************/ + + /* Sorted on the first component, then the second */ + const zone_map = { + BAL_BWE: 2, + BAL_BWI: 1, + BAL_SEB: 3, + BAL_WAS: 4, + BAL_WBL: 1, + BCA_CPK_: 3, + BCA_WAS_: 4, + BWI_BWE: 1, + BWI_WAS: 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 +641,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); }