From 9ec33b06fea64b961322810209f97db715143792 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 1 Jun 2018 20:25:42 -0600 Subject: [PATCH] Automatically show picker grid conditionally based on number of items --- pages/pos.php | 5 ++++- settings.template.php | 3 +++ static/js/pos_gridview.js | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pages/pos.php b/pages/pos.php index ff71667..c769034 100644 --- a/pages/pos.php +++ b/pages/pos.php @@ -13,7 +13,7 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$database->has(' require_once __DIR__ . "/../lib/chooseregister.php"; } else { $register = $database->get('registers', ['registerid (id)', 'registername (name)'], ['registerid' => $_SESSION['register']]); - $griditems = $binstack->select('items', ['itemid (id)', 'name', 'price', 'code1', 'code2'], ['AND' => ['price[!]' => null, 'price[!]' => 0]]); + $showgridbydefault = $binstack->count('items', ['AND' => ['price[!]' => null, 'price[!]' => 0]]) <= GRID_BY_DEFAULT_MAX_ITEMS; ?> + \ No newline at end of file diff --git a/settings.template.php b/settings.template.php index 3868736..d17f4e0 100644 --- a/settings.template.php +++ b/settings.template.php @@ -29,6 +29,9 @@ define("BINSTACK_DB_CHARSET", "utf8"); // Name of the app. define("SITE_TITLE", "NickelBox"); +// If there are this many or fewer items, +// load the POS grid view automatically +define("GRID_BY_DEFAULT_MAX_ITEMS", 20); // URL of the AccountHub API endpoint define("PORTAL_API", "http://localhost/accounthub/api.php"); diff --git a/static/js/pos_gridview.js b/static/js/pos_gridview.js index ddab68c..c14d557 100644 --- a/static/js/pos_gridview.js +++ b/static/js/pos_gridview.js @@ -50,4 +50,10 @@ $("#gridviewbtn").click(function () { $("#gridview").removeClass("d-none"); loadGridView(); } -}); \ No newline at end of file +}); + +if (showgridbydefault) { + $("#gridview").addClass("d-flex"); + $("#gridview").removeClass("d-none"); + loadGridView(); +} \ No newline at end of file