From 0468b19b6de2ab0d9cc3871dbcead82e19aec05e Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 11 Apr 2022 19:31:17 -0600 Subject: [PATCH] Add context menu to track search button (close #8) --- www/assets/js/track.js | 62 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/www/assets/js/track.js b/www/assets/js/track.js index 7fdbf9e..787bbb1 100644 --- a/www/assets/js/track.js +++ b/www/assets/js/track.js @@ -4,9 +4,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +var trackingcoderegex = /^[0-9a-zA-Z]{5,40}$/; + function openTrackingInfoPage(code) { - if (typeof code == "undefined" || code == null || code == "") { + if (typeof code == "undefined" || code == null || code.trim() == "") { app.input.validate("#trackingcode"); + app.toast.show({ + text: "Please enter a tracking code.", + position: "bottom", + closeTimeout: 2000 + }); return; } @@ -121,17 +128,16 @@ function updateTrackingMultiListStatus() { function openTrackingBarcodeScanner() { scanBarcode(function (result) { var code = ""; - var coderegex = /^[0-9a-zA-Z]{5,40}$/; if (result.startsWith("https://helena.express/track#")) { code = result.split("#")[1]; } else if (result.startsWith("http") && result.includes("#")) { - if (coderegex.test(result.split("#")[1])) { + if (trackingcoderegex.test(result.split("#")[1])) { code = result.split("#")[1]; } else { app.dialog.alert("This app can't understand what's in that barcode.", "Error"); return; } - } else if (coderegex.test(result)) { + } else if (trackingcoderegex.test(result)) { code = result; } else { app.dialog.alert("This app can't understand what's in that barcode.", "Error"); @@ -323,6 +329,54 @@ $("#app").on("contextmenu taphold", ".tracking-code-multi-link", function (evt) return false; }); +$("#app").on("contextmenu taphold", "#brokenscannercodeadd", function (evt) { + evt.preventDefault(); + + var code = $('input[name=\'trackingcode\']').val().trim().replace(/\s/, ""); + + var action = app.actions.create({ + buttons: [ + [ + { + text: 'Track', + bold: true, + onClick: function () { + if (code == "") { + app.dialog.alert("You need to type a tracking code first.", "Error"); + return; + } + openTrackingInfoPage(code); + } + }, + { + text: 'Add to Multi list', + onClick: function () { + if (code == "") { + app.dialog.alert("You need to type a tracking code first.", "Error"); + return; + } + if (!code.match(trackingcoderegex)) { + app.dialog.alert("That doesn't seem like a valid tracking code.", "Error"); + return; + } + addToTrackingMultiList(code); + addTrackingSuggestions(); + } + } + ], + [ + { + text: 'Cancel', + color: 'red' + } + ] + ] + }); + + action.open(); + return false; +}); + $("#app").on("tab:show", "#tracking-multi-list", function (evt) { updateTrackingMultiListStatus(); });