Get saved stock on page load + password protect

This commit is contained in:
keplyx 2019-08-01 10:34:45 +02:00
parent c4e6bd641b
commit 1e928ef85e
3 changed files with 33 additions and 12 deletions

View file

@ -1,5 +1,11 @@
<?php
$relativePath = "../";
$file='../data/stock.json';
$fp = fopen($file, 'r');
$result = fread($fp,filesize($file));
fclose($fp);
ob_start();
?>
<tr>
@ -63,6 +69,10 @@ ob_start();
</button>
</div>
<script type="text/javascript">
let json_dump = <?php echo $result; ?>;
</script>
</>

View file

@ -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(
'<div class="form-check">' +
'<input type="checkbox" class="form-check-input" id="' + id + '">' +
'<label class="form-check-label" for="' + id + '">' + defaultTypes[i] + '</label>' +
'<label class="form-check-label" for="' + id + '">' + currentTypes[i] + '</label>' +
'</div>'
);
}
@ -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);

1
includes/.htpassadmin Normal file
View file

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