From a28062ae8a5760d4793a9e6396b48f737ba014de Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 9 Oct 2020 16:10:43 -0600 Subject: [PATCH] Add API to get machine form fields without looking up machine --- api/actions/machine.php | 2 +- api/apisettings.php | 4 +++ lib/Machine.lib.php | 56 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/api/actions/machine.php b/api/actions/machine.php index 687acad..4cd0677 100644 --- a/api/actions/machine.php +++ b/api/actions/machine.php @@ -23,7 +23,7 @@ if (!empty($VARS["id"])) { $user = getRequestUser(); -if ($VARS["action"] != "lookup") { +if ($VARS["action"] != "lookup" && $VARS["action"] != "getmachineformfields") { if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { http_response_code(403); diff --git a/api/apisettings.php b/api/apisettings.php index e5f0450..8c3c79e 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -60,6 +60,10 @@ $APIS = [ "publicnotes (optional)" => "string" ] ], + "getmachineformfields" => [ + "load" => "machine.php", + "vars" => [] + ], "getclient" => [ "load" => "client.php", "vars" => [ diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 3eb51f0..c86889d 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -148,7 +148,59 @@ class Machine implements JsonSerializable { ] ]; } - return []; + return [ + "status" => "OK", + "id" => "", + "icon" => "", + "type" => [ + "id" => "", + "label" => "" + ], + "clientinfo" => [], + "info" => [], + "events" => [], + "components" => [], + "formdata" => [ + "options" => [ + "clientid" => ["" => ""] + Clients::getAllAsIDNameArray(), + "type" => Machine::getTypeList() + ], + "inputtypes" => [ + "model" => "text", + "condition" => "number", + "price" => "number", + "os" => "text", + "serial" => "text", + "manufacturer" => "text", + "clientid" => "select", + "privatenotes" => "textarea", + "publicnotes" => "textarea", + "type" => "select" + ], + "labels" => [ + "model" => $Strings->get("Model", false), + "condition" => $Strings->get("Condition", false), + "price" => $Strings->get("Price", false), + "os" => $Strings->get("OS/Software", false), + "serial" => $Strings->get("Serial", false), + "manufacturer" => $Strings->get("Manufacturer", false), + "clientid" => $Strings->get("Client", false), + "privatenotes" => $Strings->get("Private Notes", false), + "publicnotes" => $Strings->get("Public Notes", false), + "type" => $Strings->get("Type", false) + ], + "icons" => [ + "model" => "fas fa-hashtag", + "condition" => "fas fa-star-half-alt", + "price" => "fas fa-money-bill-wave", + "os" => "fas fa-hdd", + "serial" => "fas fa-barcode", + "manufacturer" => "fas fa-industry", + "privatenotes" => "fas fa-comment-dots", + "publicnotes" => "far fa-comment-dots" + ] + ] + ]; } public function toHTMLListGroup(bool $public = true): string { @@ -233,7 +285,7 @@ class Machine implements JsonSerializable { return ""; } if ($type == "ID") { - return "" . $publicsettings["ID number label"] . ": " . htmlspecialchars($this->getID()) . "
"; + return "" . $publicsettings["ID number label"] . ": " . htmlspecialchars($this->getID()) . "
"; } if (empty($this->{"get$type"}())) { return "";