From 1e928ef85e0bb660306eb90b246b7974291af01d Mon Sep 17 00:00:00 2001 From: keplyx Date: Thu, 1 Aug 2019 10:34:45 +0200 Subject: [PATCH] Get saved stock on page load + password protect --- admin/index.php | 10 ++++++++++ assets/js/stock.js | 34 ++++++++++++++++++++++------------ includes/.htpassadmin | 1 + 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 includes/.htpassadmin diff --git a/admin/index.php b/admin/index.php index 6bc5f5e..482d9a2 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,5 +1,11 @@ @@ -63,6 +69,10 @@ ob_start(); + + diff --git a/assets/js/stock.js b/assets/js/stock.js index a003743..eb4a0a9 100644 --- a/assets/js/stock.js +++ b/assets/js/stock.js @@ -19,10 +19,20 @@ let defaultStock = [ ]; let currentDataset = []; +let currentTypes = []; + +function initValuesFromPHPDump() { + currentDataset = json_dump.articles; // json_dump is set using PHP + currentTypes = json_dump.types; + console.log(currentDataset); + console.log(currentTypes); + generateTable(currentDataset); +} + + $(document).ready(function () { - currentDataset = defaultStock; - generateTable(currentDataset); + initValuesFromPHPDump(); generateTypeCheckboxes(); }); @@ -57,12 +67,12 @@ function generateLine(item) { } function generateTypeCheckboxes() { - for (let i = 0; i < defaultTypes.length; i++) { - let id = 'typeCheck_' + defaultTypes[i]; + for (let i = 0; i < currentTypes.length; i++) { + let id = 'typeCheck_' + currentTypes[i]; $('#typeCheckboxesCell').append( '
' + '' + - '' + + '' + '
' ); } @@ -119,19 +129,19 @@ function removeItemFromList(item) { function getTypesChecked() { let types = []; - for (let i = 0; i < defaultTypes.length; i++) { - let id = 'typeCheck_' + defaultTypes[i]; + for (let i = 0; i < currentTypes.length; i++) { + let id = 'typeCheck_' + currentTypes[i]; if ($('#' + id).is(':checked')) { - types.push(defaultTypes[i]); + types.push(currentTypes[i]); } } return types; } function setTypesChecked(types) { - for (let i = 0; i < defaultTypes.length; i++) { - let id = 'typeCheck_' + defaultTypes[i]; - $('#' + id).prop('checked', types.indexOf(defaultTypes[i]) !== -1); + for (let i = 0; i < currentTypes.length; i++) { + let id = 'typeCheck_' + currentTypes[i]; + $('#' + id).prop('checked', types.indexOf(currentTypes[i]) !== -1); } return types; } @@ -179,7 +189,7 @@ function isItemInputFilled() { function saveDataset() { let finalDataset = { - types: defaultTypes, + types: currentTypes, articles: currentDataset }; console.log(finalDataset); diff --git a/includes/.htpassadmin b/includes/.htpassadmin new file mode 100644 index 0000000..9d6a8d6 --- /dev/null +++ b/includes/.htpassadmin @@ -0,0 +1 @@ +bli:LFqJx9olAYDvk