|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$("#addpackagebtn").click(function () {
|
|
|
|
if ($("input[name=number]").val().trim() == "") {
|
|
|
|
playSound("error");
|
|
|
|
app.toast.show({
|
|
|
|
text: "Please fill in a street number.",
|
|
|
|
position: "bottom",
|
|
|
|
destroyOnClose: true,
|
|
|
|
closeTimeout: 1000 * 10
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($("input[name=street]").val().trim() == "") {
|
|
|
|
playSound("error");
|
|
|
|
app.toast.show({
|
|
|
|
text: "Please fill in a street name.",
|
|
|
|
position: "bottom",
|
|
|
|
destroyOnClose: true,
|
|
|
|
closeTimeout: 1000 * 10
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($("input[name=citystate]").val().trim() == "") {
|
|
|
|
playSound("error");
|
|
|
|
app.toast.show({
|
|
|
|
text: "Please fill in a city and state.",
|
|
|
|
position: "bottom",
|
|
|
|
destroyOnClose: true,
|
|
|
|
closeTimeout: 1000 * 10
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save city/state if changed
|
|
|
|
if (localStorage.getItem("citystate") != $("input[name=citystate]").val().trim()) {
|
|
|
|
localStorage.setItem("citystate", $("input[name=citystate]").val().trim());
|
|
|
|
}
|
|
|
|
|
|
|
|
var address = ($("input[name=number]").val() + " " + $("input[name=street]").val()).toUpperCase();
|
|
|
|
$("#no-history").addClass("display-none");
|
|
|
|
addPackageByAddress(address, $("input[name=citystate]").val().toUpperCase(), $("input[name=itemtype]:checked").val(), function (ids) {
|
|
|
|
var packageObj = getPackage(ids.packageID);
|
|
|
|
$("#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>');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Remove any pre-existing click handlers from the history list,
|
|
|
|
// otherwise the user will see a number of confirm prompts equal to the number
|
|
|
|
// of times they've opened the manage page
|
|
|
|
$(".view-main").off("click", "#historylist .history-list-item");
|
|
|
|
|
|
|
|
$(".view-main").on("click", "#historylist .history-list-item", function () {
|
|
|
|
console.log("Asking to delete ", $(this).data("package"));
|
|
|
|
confirmDeletePackage(getPackage($(this).data("package")), function (id) {
|
|
|
|
console.log("Removing history item", id);
|
|
|
|
$('#historylist .history-list-item[data-package="' + id + '"]').remove();
|
|
|
|
if ($('#historylist .history-list-item').length == 0) {
|
|
|
|
$("#no-history").removeClass("display-none");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Restore user's last entered city/state combo
|
|
|
|
if (localStorage.getItem("citystate") != null) {
|
|
|
|
$("input[name=citystate]").val(localStorage.getItem("citystate"));
|
|
|
|
}
|