Browse Source

Get saved stock on page load + password protect

keplyx 2 years ago
parent
commit
1e928ef85e
3 changed files with 33 additions and 12 deletions
  1. 10
    0
      admin/index.php
  2. 22
    12
      assets/js/stock.js
  3. 1
    0
      includes/.htpassadmin

+ 10
- 0
admin/index.php View File

@@ -1,5 +1,11 @@
1 1
 <?php
2 2
 $relativePath = "../";
3
+
4
+$file='../data/stock.json';
5
+$fp = fopen($file, 'r');
6
+$result = fread($fp,filesize($file));
7
+fclose($fp);
8
+
3 9
 ob_start();
4 10
 ?>
5 11
 <tr>
@@ -63,6 +69,10 @@ ob_start();
63 69
         </button>
64 70
     </div>
65 71
 
72
+    <script type="text/javascript">
73
+        let json_dump = <?php echo $result; ?>;
74
+    </script>
75
+
66 76
 
67 77
 </>
68 78
 

+ 22
- 12
assets/js/stock.js View File

@@ -19,10 +19,20 @@ let defaultStock = [
19 19
 ];
20 20
 
21 21
 let currentDataset = [];
22
+let currentTypes = [];
22 23
 
23
-$(document).ready(function () {
24
-    currentDataset = defaultStock;
24
+function initValuesFromPHPDump() {
25
+    currentDataset = json_dump.articles; // json_dump is set using PHP
26
+    currentTypes = json_dump.types;
27
+    console.log(currentDataset);
28
+    console.log(currentTypes);
25 29
     generateTable(currentDataset);
30
+}
31
+
32
+
33
+
34
+$(document).ready(function () {
35
+    initValuesFromPHPDump();
26 36
     generateTypeCheckboxes();
27 37
 });
28 38
 
@@ -57,12 +67,12 @@ function generateLine(item) {
57 67
 }
58 68
 
59 69
 function generateTypeCheckboxes() {
60
-    for (let i = 0; i < defaultTypes.length; i++) {
61
-        let id = 'typeCheck_' + defaultTypes[i];
70
+    for (let i = 0; i < currentTypes.length; i++) {
71
+        let id = 'typeCheck_' + currentTypes[i];
62 72
         $('#typeCheckboxesCell').append(
63 73
             '<div class="form-check">' +
64 74
             '<input type="checkbox" class="form-check-input" id="' + id + '">' +
65
-            '<label class="form-check-label" for="' + id + '">' + defaultTypes[i] + '</label>' +
75
+            '<label class="form-check-label" for="' + id + '">' + currentTypes[i] + '</label>' +
66 76
             '</div>'
67 77
         );
68 78
     }
@@ -119,19 +129,19 @@ function removeItemFromList(item) {
119 129
 
120 130
 function getTypesChecked() {
121 131
     let types = [];
122
-    for (let i = 0; i < defaultTypes.length; i++) {
123
-        let id = 'typeCheck_' + defaultTypes[i];
132
+    for (let i = 0; i < currentTypes.length; i++) {
133
+        let id = 'typeCheck_' + currentTypes[i];
124 134
         if ($('#' + id).is(':checked')) {
125
-            types.push(defaultTypes[i]);
135
+            types.push(currentTypes[i]);
126 136
         }
127 137
     }
128 138
     return types;
129 139
 }
130 140
 
131 141
 function setTypesChecked(types) {
132
-    for (let i = 0; i < defaultTypes.length; i++) {
133
-        let id = 'typeCheck_' + defaultTypes[i];
134
-        $('#' + id).prop('checked', types.indexOf(defaultTypes[i]) !== -1);
142
+    for (let i = 0; i < currentTypes.length; i++) {
143
+        let id = 'typeCheck_' + currentTypes[i];
144
+        $('#' + id).prop('checked', types.indexOf(currentTypes[i]) !== -1);
135 145
     }
136 146
     return types;
137 147
 }
@@ -179,7 +189,7 @@ function isItemInputFilled() {
179 189
 
180 190
 function saveDataset() {
181 191
     let finalDataset = {
182
-        types: defaultTypes,
192
+        types: currentTypes,
183 193
         articles: currentDataset
184 194
     };
185 195
     console.log(finalDataset);

+ 1
- 0
includes/.htpassadmin View File

@@ -0,0 +1 @@
1
+bli:LFqJx9olAYDvk

Loading…
Cancel
Save