Add support for barcode scanner hardware
This commit is contained in:
parent
00122b2d94
commit
6c992578ba
@ -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('<li class="history-list-item item-content" data-package="' + ids.packageID + '">'
|
||||
+ ' <div class="item-media">'
|
||||
+ ' <i class="icon ' + getIconForType(packageObj.type) + '"></i>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="item-inner">'
|
||||
+ ' <div class="item-title">'
|
||||
+ ' ' + packageObj.address
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ '</li>');
|
||||
$("#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('<li class="history-list-item item-content" data-package="' + ids.packageID + '">'
|
||||
+ ' <div class="item-media">'
|
||||
+ ' <i class="icon ' + getIconForType(packageObj.type) + '"></i>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="item-inner">'
|
||||
+ ' <div class="item-title">'
|
||||
+ ' ' + packageObj.address
|
||||
+ ' </div>'
|
||||
+ ' </div>'
|
||||
+ '</li>');
|
||||
$("#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();
|
56
www/assets/js/hardscan.js
Normal file
56
www/assets/js/hardscan.js
Normal file
@ -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();
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -45,6 +45,7 @@
|
||||
<script src="node_modules/jsbarcode/dist/JsBarcode.all.min.js"></script>
|
||||
<script src="node_modules/bwip-js/dist/bwip-js-min.js"></script>
|
||||
<script src="node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.js"></script>
|
||||
<script src="node_modules/onscan.js/onscan.min.js"></script>
|
||||
|
||||
<script src="settings.js"></script>
|
||||
|
||||
@ -68,6 +69,8 @@
|
||||
<script src="routes.js"></script>
|
||||
<script src="assets/js/main.js"></script>
|
||||
|
||||
<script src="assets/js/hardscan.js"></script>
|
||||
|
||||
<script src="cache.js"></script>
|
||||
|
||||
<script>
|
||||
|
@ -521,6 +521,14 @@ var routes = [
|
||||
link: true
|
||||
}
|
||||
);
|
||||
settings.push({
|
||||
setting: "hardwarescanner",
|
||||
title: "Use Hardware Scanner",
|
||||
text: "Enable scanning barcodes with a real scanner (not just a camera)",
|
||||
toggle: true,
|
||||
checked: getStorage("hardwarescanner") == "true",
|
||||
onclick: ""
|
||||
});
|
||||
if (platform_type == "cordova" && cordova.platformId != "browser") {
|
||||
settings.push({
|
||||
setting: "wakelock",
|
||||
|
Loading…
x
Reference in New Issue
Block a user