diff --git a/www/assets/js/add.js b/www/assets/js/add.js
index 9c9a271..261fc11 100644
--- a/www/assets/js/add.js
+++ b/www/assets/js/add.js
@@ -4,36 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-$(".scanbarcodebtn").click(function () {
- scanBarcode(function (code) {
- playSound("scan");
- if (code != "") {
- addPackageByBarcode(code, $("input[name=itemtype]:checked").val(),
- function (ids) {
- var packageObj = getPackage(ids.packageID);
- // Reset item type to default
- $("input[name=itemtype][data-default=1]").prop("checked", true);
- $("#historylist").prepend('
'
- + ' '
- + ' '
- + '
'
- + ' '
- + '
'
- + ' ' + packageObj.address
- + '
'
- + '
'
- + '');
- $("#tap-to-remove-history-prompt").removeClass("display-none");
- $("#no-history").addClass("display-none");
- });
- } else {
- app.dialog.alert("Invalid barcode.", "Error");
- }
- }, function (error) {
- app.dialog.alert(error, "Error");
- });
-});
-
$(".addpackagebtn").click(function () {
if ($("input[name=number]").val().trim() == "") {
playSound("error");
@@ -173,6 +143,41 @@ function setTabSwipable() {
}
}
+function addPackageBarcode(code) {
+ playSound("scan");
+ if (code != "") {
+ addPackageByBarcode(code, $("input[name=itemtype]:checked").val(),
+ function (ids) {
+ var packageObj = getPackage(ids.packageID);
+ // Reset item type to default
+ $("input[name=itemtype][data-default=1]").prop("checked", true);
+ $("#historylist").prepend(''
+ + ' '
+ + ' '
+ + '
'
+ + ' '
+ + '
'
+ + ' ' + packageObj.address
+ + '
'
+ + '
'
+ + '');
+ $("#tap-to-remove-history-prompt").removeClass("display-none");
+ $("#no-history").addClass("display-none");
+ });
+ } else {
+ app.dialog.alert("Invalid barcode.", "Error");
+ }
+}
+
+$(".scanbarcodebtn").click(function () {
+ scanBarcode(function (code) {
+ addPackageBarcode(code);
+ }, function (error) {
+ app.dialog.alert(error, "Error");
+ });
+});
+
+
$(window).on('resize', setTabSwipable);
setTabSwipable();
\ No newline at end of file
diff --git a/www/assets/js/hardscan.js b/www/assets/js/hardscan.js
new file mode 100644
index 0000000..1c92d46
--- /dev/null
+++ b/www/assets/js/hardscan.js
@@ -0,0 +1,56 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+function setupHardwareScanner() {
+ try {
+ onScan.detachFrom(document);
+ } catch (ex) {
+ // do nothing
+ }
+
+ if (getStorage("hardwarescanner") == "true") {
+ onScan.attachTo(document, {
+ suffixKeyCodes: [13], // enter-key expected at the end of a scan
+ reactToKeyDown: true,
+ reactToPaste: true, // Compatibility to built-in scanners in paste-mode (as opposed to keyboard-mode)
+ ignoreIfFocusOn: 'input',
+ stopPropagation: true,
+ preventDefault: true,
+ keyCodeMapper: function (evt) {
+ // Handle special char codes
+ switch (evt.which) {
+ case 119: // F8, separates 42012345 from actual tracking barcode
+ return "";
+ }
+
+ var char = String.fromCharCode(evt.which);
+ // Handle special characters
+ switch (char) {
+ case "\u0010": // In some fields in UPS MI codes but pointless
+ return "";
+ }
+ // Return everything that gets through the special cases above
+ return char;
+ },
+ onScan: function (code, qty) { // Alternative to document.addEventListener('scan')
+ console.log("Scanned: ", code);
+ switch (router.currentRoute.name) {
+ case "add":
+ addPackageBarcode(code);
+ break;
+ case "track":
+ openTrackingHistory(code);
+ break;
+ case "scanner":
+ addCodeToScannerList(code);
+ break;
+ }
+ }
+ });
+ }
+}
+
+setupHardwareScanner();
\ No newline at end of file
diff --git a/www/assets/js/settings.js b/www/assets/js/settings.js
index 2aeab97..04362e3 100644
--- a/www/assets/js/settings.js
+++ b/www/assets/js/settings.js
@@ -94,6 +94,12 @@ $('.item-content[data-setting=wakelock] .toggle input').on("change", function ()
}
});
+$('.item-content[data-setting=hardwarescanner] .toggle input').on("change", function () {
+ var checked = $(this).prop('checked');
+ setStorage("hardwarescanner", checked);
+ setupHardwareScanner();
+});
+
$('.item-content[data-setting=alertvolume] .range-slider').on('range:changed', function (e, range) {
var val = app.range.get(".item-content[data-setting=alertvolume] .range-slider").getValue();
setStorage("alertvolume", val);
diff --git a/www/assets/js/toolbox_scanner.js b/www/assets/js/toolbox_scanner.js
index 8d358a3..60fedc7 100644
--- a/www/assets/js/toolbox_scanner.js
+++ b/www/assets/js/toolbox_scanner.js
@@ -29,11 +29,7 @@ function brokenScannerEsc() {
function brokenScannerScan() {
scanBarcode(function (code) {
playSound("scan");
- if (code != "" && code.length > 5 && code.match(/^[0-9A-Z]+$/i)) {
- addCodeToScannerList(code);
- } else {
- app.dialog.alert("That's not a valid tracking code.", "Error");
- }
+ addCodeToScannerList(code);
}, function (error) {
app.dialog.alert(error, "Error");
});
@@ -52,6 +48,13 @@ function brokenScannerAddTextEntry() {
function addCodeToScannerList(code) {
code = code.toUpperCase();
+ if (code != "" && code.length > 5 && code.match(/^[0-9A-Z]+$/i)) {
+ // continue
+ } else {
+ app.dialog.alert("That's not a valid tracking code.", "Error");
+ return;
+ }
+
var signatureregexes = [
/^E[A-Z][0-9]{9}US$/, // Priority Mail Express
/^[RV][A-Z][0-9]{9}[A-Z]{2}$/, // Registered mail
diff --git a/www/index.html b/www/index.html
index 7bb39f2..4fd313f 100644
--- a/www/index.html
+++ b/www/index.html
@@ -45,6 +45,7 @@
+
@@ -68,6 +69,8 @@
+
+