From 358585680aa4436159c0ca5bb88a75448ae6ec9a Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 6 Sep 2020 20:16:53 -0600 Subject: [PATCH] Add client search and viewing --- www/assets/js/clients.js | 125 ++++++++++++++++++++++++++++++++ www/assets/js/home.js | 5 ++ www/index.html | 5 +- www/pages/client.html | 149 +++++++++++++++++++++++++++++++++++++++ www/pages/clients.html | 35 +++++++++ www/pages/home.html | 13 +++- www/pages/machine.html | 2 +- www/routes.js | 10 +++ 8 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 www/assets/js/clients.js create mode 100644 www/pages/client.html create mode 100644 www/pages/clients.html diff --git a/www/assets/js/clients.js b/www/assets/js/clients.js new file mode 100644 index 0000000..26bdccd --- /dev/null +++ b/www/assets/js/clients.js @@ -0,0 +1,125 @@ +/* + * Copyright 2020 Netsyms Technologies. + * 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 clientSearchAsync(routeTo, routeFrom, resolve, reject) { + app.dialog.preloader("Searching..."); + + apirequest( + "searchclients", + { + q: routeTo.params.q + }, + function (resp) { + app.dialog.close(); + if (resp.status == "ERROR") { + app.dialog.alert(resp.msg, "Error"); + reject(); + } else { + var context = { + clients: resp.clients, + q: routeTo.params.q + }; + + resolve({ + templateUrl: "pages/clients.html", + }, { + context: context + }); + } + }, + function (xhr) { + app.dialog.close(); + var error = $.parseJSON(xhr.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + } else { + app.dialog.alert("A server or network error occurred.", "Error"); + } + reject(); + }); +} + +function clientGetAsync(routeTo, routeFrom, resolve, reject) { + app.dialog.preloader("Expanding client..."); + + apirequest( + "getclient", + { + clientid: routeTo.params.clientid + }, + function (resp) { + app.dialog.close(); + if (resp.status == "ERROR") { + app.dialog.alert(resp.msg, "Error"); + reject(); + } else { + + var machinelist = []; + for (var i = 0; i < resp.machines.length; i++) { + var machine = resp.machines[i]; + machine["props"] = []; + for (var k in machine.formdata.labels) { + if (machine.hasOwnProperty(k)) { + switch (k) { + case "type": + case "clientid": + // skip these + break; + default: + var value = machine.info[k]; + if (value == false || value == 0) { + value = false; + } else { + value = value.toString().replace("\n", "
"); + } + machine.props.push({ + name: k, + value: value + }); + } + } + } + console.log(machine); + machinelist.push(machine); + } + + // Add
for newlines + for (var k in resp.client) { + if (resp.client.hasOwnProperty(k)) { + resp.client[k] = resp.client[k].toString().replace("\n", "
"); + } + } + + if (typeof resp.client.phone == 'string') { + resp.client.phonestripped = resp.client.phone.replace(/\D/g, ''); + } + + var context = { + client: resp.client, + machines: machinelist + }; + + resolve({ + templateUrl: "pages/client.html", + }, { + context: context + }); + } + }, + function (xhr) { + app.dialog.close(); + var error = $.parseJSON(xhr.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + } else { + app.dialog.alert("A server or network error occurred.", "Error"); + } + reject(); + }); + +} \ No newline at end of file diff --git a/www/assets/js/home.js b/www/assets/js/home.js index 592b545..009dc94 100644 --- a/www/assets/js/home.js +++ b/www/assets/js/home.js @@ -11,6 +11,11 @@ $("#machinesearchbar").submit(function (evt) { openMachineInfo($("#machinesearchbar input[type=search]").val()); }); +$("#clientsearchbar").submit(function (evt) { + evt.preventDefault(); + router.navigate("/clients/" + $("#clientsearchbar input[type=search]").val()); +}); + function scanBarcodeOpenMachine() { scanBarcode(function (code) { openMachineInfo(code); diff --git a/www/index.html b/www/index.html index bd7aaf5..9d50354 100644 --- a/www/index.html +++ b/www/index.html @@ -34,9 +34,10 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. - + - + + \ No newline at end of file diff --git a/www/pages/client.html b/www/pages/client.html new file mode 100644 index 0000000..1c8950d --- /dev/null +++ b/www/pages/client.html @@ -0,0 +1,149 @@ + + +
+ + + +
+
+ Info + Machines +
+
+ +
+
+ +
+ {{#with client}} +
+
    +
  • +
    +
    +
    +
    Name
    + {{name}} +
    +
    +
    +
  • + {{#if phone}} +
  • + +
    +
    +
    Phone
    + {{phone}} +
    +
    +
    +
  • + {{/if}} + {{#if billingaddress}} +
  • +
    +
    +
    +
    Billing Address
    + {{billingaddress}} +
    +
    +
    +
  • + {{/if}} + {{#if mailingaddress}} +
  • +
    +
    +
    +
    Mailing Address
    + {{mailingaddress}} +
    +
    +
    +
  • + {{/if}} + {{#if privatenotes}} +
  • +
    +
    +
    +
    Private Notes
    + {{privatenotes}} +
    +
    +
    +
  • + {{/if}} + {{#if publicnotes}} +
  • +
    +
    +
    +
    Public Notes
    + {{publicnotes}} +
    +
    +
    +
  • + {{/if}} +
+
+ {{/with}} +
+ +
+
+
    + {{#each machines}} +
  • + +
    + Open +
    +
      + {{#each props}} +
    • +
      +
      +
      +
      {{title}}
      + {{content}} +
      +
      +
      +
    • + {{/each}} +
    +
    +
    +
  • + {{/each}} +
+
+
+ +
+
+
\ No newline at end of file diff --git a/www/pages/clients.html b/www/pages/clients.html new file mode 100644 index 0000000..ef1d7d8 --- /dev/null +++ b/www/pages/clients.html @@ -0,0 +1,35 @@ + + +
+ + + +
+ +
+
\ No newline at end of file diff --git a/www/pages/home.html b/www/pages/home.html index 864a61e..33ec6c4 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -28,7 +28,18 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + +