From 40def2bf7030977c6a2758780660f4d2de69a1f6 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 9 Dec 2017 02:10:45 -0700 Subject: [PATCH] Add item search box on dashboard (close #6) --- lang/en_us.php | 3 +- pages/home.php | 25 +++++++++- pages/items.php | 66 ++++++++------------------ static/js/items.js | 113 ++++++++++++++++++++++++--------------------- 4 files changed, 105 insertions(+), 102 deletions(-) diff --git a/lang/en_us.php b/lang/en_us.php index 539e539..42a8256 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -89,5 +89,6 @@ define("STRINGS", [ "show all items" => "Show all items", "missing name" => "You need to enter a name.", "use the dropdowns" => "Whoops, you need to use the category and location autocomplete boxes.", - "make categories and locations" => "Please create at least one category and location before adding an item." + "make categories and locations" => "Please create at least one category and location before adding an item.", + "search" => "Search" ]); \ No newline at end of file diff --git a/pages/home.php b/pages/home.php index b891e97..a9cbe3b 100644 --- a/pages/home.php +++ b/pages/home.php @@ -4,7 +4,30 @@ require_once __DIR__ . '/../required.php'; redirectifnotloggedin(); ?>
-
+
+
+ +
+ "/> +
+ + + + + + +
+
+
+
+
+
+
+
diff --git a/pages/items.php b/pages/items.php index a99994c..28ff6f8 100644 --- a/pages/items.php +++ b/pages/items.php @@ -9,9 +9,10 @@ redirectifnotloggedin();
- -
 
-">var filter = "stock"; +
 
+ var filter = null;\n"; } ?> @@ -31,50 +32,6 @@ redirectifnotloggedin(); - select('items', [ - '[>]categories' => ['catid' => 'catid'], - '[>]locations' => ['locid' => 'locid'] - ], [ - 'itemid', - 'name', - 'catname', - 'locname', - 'loccode', - 'code1', - 'code2', - 'qty', - 'want', - 'userid' - ], ["LIMIT" => 100]); - $usercache = []; - foreach ($items as $item) { - if (is_null($item['userid'])) { - $user = ""; - } else { - if (!isset($usercache[$item['userid']])) { - $usercache[$item['userid']] = getUserByID($item['userid']); - } - $user = $usercache[$item['userid']]['name']; - } - ?> - - - - - - - - - - - - - - - @@ -90,4 +47,17 @@ redirectifnotloggedin(); - \ No newline at end of file + + + + + + diff --git a/static/js/items.js b/static/js/items.js index b09dc45..1375138 100644 --- a/static/js/items.js +++ b/static/js/items.js @@ -1,64 +1,73 @@ var itemtable = $('#itemtable').DataTable({ responsive: { - details: { - display: $.fn.dataTable.Responsive.display.modal({ - header: function (row) { - var data = row.data(); - return " " + data[2]; - } - }), - renderer: $.fn.dataTable.Responsive.renderer.tableAll({ - tableClass: 'table' - }), - type: "column" - } + details: { + display: $.fn.dataTable.Responsive.display.modal({ + header: function (row) { + var data = row.data(); + return " " + data[2]; + } + }), + renderer: $.fn.dataTable.Responsive.renderer.tableAll({ + tableClass: 'table' + }), + type: "column" + } }, columnDefs: [ - { - targets: 0, - className: 'control', - orderable: false - }, - { - targets: 1, - orderable: false - }, - { - targets: 8, - orderable: false - } + { + targets: 0, + className: 'control', + orderable: false + }, + { + targets: 1, + orderable: false + }, + { + targets: 8, + orderable: false + } ], order: [ - [2, 'asc'] + [2, 'asc'] ], serverSide: true, ajax: { - url: "lib/getitemtable.php", - data: function (d) { - if (filter == "stock") { - d.show_want = 1; - } - }, - dataFilter: function (data) { - var json = jQuery.parseJSON(data); - json.data = []; - json.items.forEach(function (row) { - json.data.push([ - "", - row.editbtn + " " + row.clonebtn, - row.name, - row.catname, - row.locname + " (" + row.loccode + ")", - row.code1, - row.code2, - row.qty, - row.want, - row.username - ]); - }); - return JSON.stringify(json); - } + url: "lib/getitemtable.php", + data: function (d) { + if (filter == "stock") { + d.show_want = 1; + } + }, + dataFilter: function (data) { + var json = jQuery.parseJSON(data); + json.data = []; + json.items.forEach(function (row) { + json.data.push([ + "", + row.editbtn + " " + row.clonebtn, + row.name, + row.catname, + row.locname + " (" + row.loccode + ")", + row.code1, + row.code2, + row.qty, + row.want, + row.username + ]); + }); + return JSON.stringify(json); + } } }); -$('#itemtable_filter').append(""); \ No newline at end of file +$('#itemtable_filter').append(""); + +$(document).ready(function () { + if (search_preload_content !== false) { + var searchInput = $("#itemtable_filter label input"); + $(searchInput).val(search_preload_content); + $(searchInput).trigger("input"); + $(searchInput).trigger("change"); + } +}); \ No newline at end of file