Browse Source

Add street autocomplete (close #4), update project properties

master v1.0.0
Skylar Ittner 2 years ago
parent
commit
d3bff90b3e
  1. 9
      nbproject/license-mpl.txt
  2. 5
      nbproject/project.properties
  3. 71
      www/assets/js/autofill.js
  4. 6
      www/assets/js/list.js
  5. 32
      www/assets/js/manage.js
  6. 2
      www/assets/js/packages.js
  7. 1
      www/index.html
  8. 2
      www/pages/manage.html

9
nbproject/license-mpl.txt

@ -0,0 +1,9 @@
<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix}This Source Code Form is subject to the terms of the Mozilla Public
${licensePrefix}License, v. 2.0. If a copy of the MPL was not distributed with this
${licensePrefix}file, You can obtain one at http://mozilla.org/MPL/2.0/.
<#if licenseLast??>
${licenseLast}
</#if>

5
nbproject/project.properties

@ -2,10 +2,11 @@ auxiliary.org-netbeans-modules-cordova.cordova_5f_build_5f_script_5f_version=52
auxiliary.org-netbeans-modules-cordova.phonegap=true
auxiliary.org-netbeans-modules-javascript-nodejs.run_2e_enabled=false
browser.run=true
file.reference.PackageHelper-www=www
file.reference.PackageNotice-test=test
file.reference.PackageNotice-www=www
files.encoding=UTF-8
site.root.folder=${file.reference.PackageNotice-www}
project.licensePath=./nbproject/license-mpl.txt
site.root.folder=${file.reference.PackageHelper-www}
start.file=index.html
test.folder=${file.reference.PackageNotice-test}
web.context.root=/PackageNotice

71
www/assets/js/autofill.js

@ -0,0 +1,71 @@
/*
* 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 autofillDB = {};
if (localStorage.getItem("autofill_db") != null) {
autofillDB = JSON.parse(localStorage.getItem("autofill_db"));
}
function addressToNumberAndStreet(address) {
var number = "";
var street = "";
var addressRegex = RegExp("^[0-9]+ .+$");
if (addressRegex.test(address)) {
number = address.split(" ", 2)[0];
street = address.substring(address.indexOf(' ') + 1);
}
return [number, street];
}
function addAutofillEntry(address) {
var [number, street] = addressToNumberAndStreet(address);
if (number == "" || street == "") {
return;
}
if (typeof autofillDB[number] == 'undefined') {
autofillDB[number] = [
[street, 1]
];
} else {
var found = false;
for (var i = 0; i < autofillDB[number].length; i++) {
if (autofillDB[number][i][0] == street) {
autofillDB[number][i][1]++;
found = true;
break;
}
}
if (!found) {
autofillDB[number].push([street, 1]);
}
}
localStorage.setItem("autofill_db", JSON.stringify(autofillDB));
}
function searchAutofill(number) {
if (typeof autofillDB[number] == 'undefined') {
return [];
}
var sorted = autofillDB[number].sort(function (a, b) {
return b[1] - a[1];
});
var streets = [];
for (var i = 0; i < sorted.length; i++) {
streets.push(sorted[i][0]);
}
return streets;
}

6
www/assets/js/list.js

@ -1,7 +1,7 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* 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/.
*/
$(".view-main").on("click", "#addresslist .package-list-item .deliver-btn", function () {

32
www/assets/js/manage.js

@ -77,4 +77,34 @@ $(".view-main").on("click", "#historylist .history-list-item", function () {
// Restore user's last entered city/state combo
if (localStorage.getItem("citystate") != null) {
$("input[name=citystate]").val(localStorage.getItem("citystate"));
}
}
var streetAutocomplete = app.autocomplete.create({
inputEl: '#streetInput',
openIn: 'dropdown',
preloader: false, //enable preloader
/* If we set valueProperty to "id" then input value on select will be set according to this property */
valueProperty: 'name', //object's "value" property name
textProperty: 'name', //object's "text" property name
limit: 10, //limit to 10 results
typeahead: true,
dropdownPlaceholderText: '',
source: function (query, render) {
var autocomplete = this;
var streets = searchAutofill($("input[name=number]").val());
if (query.length === 0) {
render(streets);
return;
}
var results = [];
for (var i = 0; i < streets.length; i++) {
if (streets[i].toLowerCase().indexOf(query.toLowerCase()) >= 0) {
results.push(streets[i]);
}
}
render(results);
}
});

2
www/assets/js/packages.js

@ -148,6 +148,8 @@ function addPackage(address, latitude, longitude, type, callback) {
packageID: packageID
});
}
addAutofillEntry(address);
}
function markDelivered(id, delivered) {

1
www/index.html

@ -34,6 +34,7 @@
<script src="assets/js/platform.js"></script>
<script src="assets/js/audio.js"></script>
<script src="assets/js/autofill.js"></script>
<script src="assets/js/packages.js"></script>
<script src="assets/js/location.js"></script>
<script src="assets/js/list.js"></script>

2
www/pages/manage.html

@ -49,7 +49,7 @@
<div class="item-inner">
<div class="item-title item-label">Street</div>
<div class="item-input-wrap">
<input type="text" name="street" placeholder="Road Drive">
<input type="text" name="street" id="streetInput" placeholder="Road Drive">
<span class="input-clear-button"></span>
</div>
</div>

Loading…
Cancel
Save