From d0c3988566af2d2f8b60147cdf2e7a7a1ba1b165 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 27 Nov 2019 02:53:01 -0700 Subject: [PATCH] Add tool for scanning items delivered (close #14) --- www/assets/images/barcode-dashed.svg | 60 +++++++ www/assets/js/toolbox_scanner.js | 209 ++++++++++++++++++++++++ www/assets/js/toolbox_scannerentries.js | 23 +++ www/assets/js/toolbox_track.js | 2 +- www/pages/toolbox.html | 16 +- www/pages/toolbox/scanner.html | 50 ++++++ www/pages/toolbox/scanner/entries.html | 60 +++++++ www/pages/toolbox/scanner/scanner.html | 94 +++++++++++ www/pages/toolbox/trackinginfo.html | 6 +- www/routes.js | 209 +++++++++++++++--------- www/settings.js | 198 ++++++++++++++++++++++ 11 files changed, 836 insertions(+), 91 deletions(-) create mode 100644 www/assets/images/barcode-dashed.svg create mode 100644 www/assets/js/toolbox_scanner.js create mode 100644 www/assets/js/toolbox_scannerentries.js create mode 100644 www/pages/toolbox/scanner.html create mode 100644 www/pages/toolbox/scanner/entries.html create mode 100644 www/pages/toolbox/scanner/scanner.html diff --git a/www/assets/images/barcode-dashed.svg b/www/assets/images/barcode-dashed.svg new file mode 100644 index 0000000..5697bf1 --- /dev/null +++ b/www/assets/images/barcode-dashed.svg @@ -0,0 +1,60 @@ + + diff --git a/www/assets/js/toolbox_scanner.js b/www/assets/js/toolbox_scanner.js new file mode 100644 index 0000000..b3171f0 --- /dev/null +++ b/www/assets/js/toolbox_scanner.js @@ -0,0 +1,209 @@ +/* + * 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/. + */ + +var scannerCodes = []; + +function resetScanner() { + scannerCodes = []; + app.popup.close("#scanEventTypePopup"); + app.popup.close("#scanEventPopup"); + router.refreshPage(); +} + +function brokenScannerEsc() { + app.dialog.confirm( + "Clear list?", + "Confirm", + function () { + resetScanner(); + }, + function () { + // cancel + } + ); +} + +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"); + } + }, function (error) { + app.dialog.alert(error, "Error"); + }); +} + +function brokenScannerAddTextEntry() { + var code = $("#brokenscannerinput").val(); + if (code != "" && code.length > 5 && code.match(/^[0-9A-Z]+$/i)) { + addCodeToScannerList(code); + $("#brokenscannerinput").val(""); + } else { + app.dialog.alert("That's not a valid tracking code.", "Error"); + } +} + +function addCodeToScannerList(code) { + code = code.toUpperCase(); + var codeEntryTemplate = Template7.compile('
  • ' + + '
    ' + + '
    ' + + '
    {{code}}
    ' + + '
    ' + + '
    ' + + '
  • '); + $("#codelist").append(codeEntryTemplate({ + code: code + })); +} + +function chooseScanEvent() { + if ($("#codelist li.codelist-entry").length <= 0) { + app.dialog.alert("Nothing was entered!"); + return; + } + + $("#codelist li.codelist-entry").each(function () { + scannerCodes.push($(this).data("code")); + }); + + + openEventPopup(); +} + +function openEventPopup() { + var eventItemTemplate = Template7.compile('
  • ' + + ' ' + + '
  • '); + + $("#scanEventPopup ul.eventlist").html(""); + for (i in SETTINGS.scannerevents) { + var event = SETTINGS.scannerevents[i]; + $("#scanEventPopup ul.eventlist").append(eventItemTemplate({ + button: event.button, + title: event.title + })); + } + + app.popup.open("#scanEventPopup"); +} + +function openEventTypePopup(eventname) { + var eventItemTemplate = Template7.compile('
  • ' + + ' ' + + '
  • '); + + var eventafter = false; + for (i in SETTINGS.scannerevents) { + var event = SETTINGS.scannerevents[i]; + if (event.title == eventname) { + eventafter = event.after; + break; + } + } + + $("#scanEventTypePopup ul.eventlist").html(""); + for (i in eventafter) { + var event = eventafter[i]; + $("#scanEventTypePopup ul.eventlist").append(eventItemTemplate({ + button: event.button, + title: event.title, + parenttitle: eventname, + form3849: event.after == "3849" ? "1" : "0" + })); + } + + app.popup.open("#scanEventTypePopup"); +} + +function saveScanCode(code) { + if (localStorage.getItem("scanevents") == null) { + localStorage.setItem("scanevents", "[]"); + } + var events = JSON.parse(localStorage.getItem("scanevents")); + events.push(code); + localStorage.setItem("scanevents", JSON.stringify(events)); +} + +$(".view-main").off("click", "#codelist li.codelist-entry"); + +$(".view-main").on("click", "#codelist li.codelist-entry", function () { + var entry = $(this); + var code = entry.data("code"); + app.dialog.confirm( + "Remove " + code + " from list?", + "Confirm", + function () { + // delete + entry.remove(); + }, + function () { + // cancel + } + ); +}); + +$("#app").off("click", "ul li.eventtypebutton"); +$("#app").on("click", "ul li.eventtypebutton", function () { + var eventname = $(this).data("parenttitle"); + var eventtypename = $(this).data("title"); + + var scanEvent = []; + scanEvent.push(eventname); + scanEvent.push(eventtypename); + + if ($(this).data("form3849") == "1") { + // TODO: make this not a hack + app.dialog.prompt("Type in 3849 form", "3849 Form", function (formcode) { + for (i in scannerCodes) { + saveScanCode({ + code: scannerCodes[i], + event: scanEvent, + form3849: formcode, + date: timestampToDateTimeString((new Date).getTime() / 1000) + }); + } + app.toast.show({ + text: 'Information recorded successfully!', + position: "bottom", + destroyOnClose: true, + closeTimeout: 1000 * 3 + }); + resetScanner(); + }, function () { + + }, ""); + } else { + for (i in scannerCodes) { + saveScanCode({ + code: scannerCodes[i], + event: scanEvent, + form3849: "", + date: timestampToDateTimeString((new Date).getTime() / 1000) + }); + } + app.toast.show({ + text: 'Information recorded successfully!', + position: "bottom", + destroyOnClose: true, + closeTimeout: 1000 * 3 + }); + resetScanner(); + } +}); \ No newline at end of file diff --git a/www/assets/js/toolbox_scannerentries.js b/www/assets/js/toolbox_scannerentries.js new file mode 100644 index 0000000..1140edd --- /dev/null +++ b/www/assets/js/toolbox_scannerentries.js @@ -0,0 +1,23 @@ +/* + * 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 confirmDeleteScanEntries() { + app.dialog.confirm( + "Really delete all entries from scan list?", + "Clear Entries", + function () { + // clear + localStorage.setItem("scanevents", "[]"); + router.navigate("/toolbox/scanner/entries", { + reloadCurrent: true + }); + }, + function () { + // cancel + } + ); +} \ No newline at end of file diff --git a/www/assets/js/toolbox_track.js b/www/assets/js/toolbox_track.js index 3f9ee82..f0e1eb9 100644 --- a/www/assets/js/toolbox_track.js +++ b/www/assets/js/toolbox_track.js @@ -136,7 +136,7 @@ function scanTrackingBarcode() { } }, function (error) { app.dialog.alert(error, "Error"); - }) + }); } $("#trackbtn").click(function () { diff --git a/www/pages/toolbox.html b/www/pages/toolbox.html index 32aa05e..626b905 100644 --- a/www/pages/toolbox.html +++ b/www/pages/toolbox.html @@ -19,6 +19,14 @@
    -
    diff --git a/www/pages/toolbox/scanner.html b/www/pages/toolbox/scanner.html new file mode 100644 index 0000000..e1d404e --- /dev/null +++ b/www/pages/toolbox/scanner.html @@ -0,0 +1,50 @@ + + +
    + + + +
    + + +
    + info +
    + Scan barcodes while your postal scanner is crashed or restarting. + When the scanner is working again, you can scan all the saved + barcodes from your phone screen using the scanner's Manual Input or + Scan Barcode feature. +
    +
    +
    \ No newline at end of file diff --git a/www/pages/toolbox/scanner/entries.html b/www/pages/toolbox/scanner/entries.html new file mode 100644 index 0000000..edc745b --- /dev/null +++ b/www/pages/toolbox/scanner/entries.html @@ -0,0 +1,60 @@ + + +
    + + + +
    + {{#if entries}} +
    +
      + {{#each entries}} +
    • +
      +
      +
      + +
      +
      {{event}}
      +
      {{date}}
      + {{#if form3849}} +

      Form 3849:

      +
      + +
      + {{/if}} +
      +
      +
    • + {{/each}} +
    +
    + {{else}} +
    + +

    + No scan entries. +

    +
    + {{/if}} +
    + + +
    \ No newline at end of file diff --git a/www/pages/toolbox/scanner/scanner.html b/www/pages/toolbox/scanner/scanner.html new file mode 100644 index 0000000..0c7b9cb --- /dev/null +++ b/www/pages/toolbox/scanner/scanner.html @@ -0,0 +1,94 @@ + + +
    + + + + + + + + + + + + + +
    +
    +
      +
    +
    +
    +
    + + + +
    \ No newline at end of file diff --git a/www/pages/toolbox/trackinginfo.html b/www/pages/toolbox/trackinginfo.html index 439cc6d..dc85bdb 100644 --- a/www/pages/toolbox/trackinginfo.html +++ b/www/pages/toolbox/trackinginfo.html @@ -52,9 +52,7 @@
  • - - +
  • History
  • @@ -81,7 +79,7 @@