Improve listing page

This commit is contained in:
Augusto Gunsch 2022-07-27 12:59:59 +02:00
parent 863829d291
commit bd7f230fe1
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
5 changed files with 78 additions and 9 deletions

View File

@ -1,14 +1,54 @@
body {
font-family: cursive;
}
#header { #header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
border-bottom: 2px solid gray;
margin: 0 1em 2em;
} }
#buttons { #buttons {
display: flex; display: flex;
margin: 0 1em;
} }
#buttons button { #buttons button {
height: 2em; font-family: cursive;
margin: 1em; padding: .5em 1em;
font-size: 1rem;
margin: 0 2em;
align-self: center; align-self: center;
background-color: white;
border: 2px solid black;
box-shadow: 2px 2px black;
}
#buttons button:hover {
background-color: #EEE;
cursor: pointer;
}
#products {
display: flex;
flex-wrap: wrap;
}
.product {
width: 150px;
height: 150px;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
border: 2px solid black;
margin: 1em;
position: relative;
}
.delete-checkbox {
border: 1px solid black;
position: absolute;
top: 0px;
} }

View File

@ -13,12 +13,8 @@
<button id="delete-product-btn">MASS DELETE</button> <button id="delete-product-btn">MASS DELETE</button>
</div> </div>
</div> </div>
<?php <div id="products">
require 'model/product.php'; </div>
$products = Product::selectAll();
// TODO
echo json_encode($products);
?>
</body> </body>
<script src="index.js"></script>
</html> </html>

28
index.js Normal file
View File

@ -0,0 +1,28 @@
const productsList = document.getElementById('products');
const loadItems = () => {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
const products = JSON.parse(this.responseText);
const boxes = products.map(product =>
`<div class="product">
<input type="checkbox" class="delete-checkbox" value="${product.id}">
<p>
${product.sku}<br>
${product.name}<br>
${product.price} $<br>
${product.attribute}
</p>
</div>
`)
productsList.innerHTML = boxes.join('\n');
}
xhttp.open('GET', 'view/products.php', true);
xhttp.send();
}
loadItems();

View File

@ -86,6 +86,7 @@ abstract class Product implements JsonSerializable {
public function jsonSerialize() : mixed { public function jsonSerialize() : mixed {
return [ return [
'id' => $this->getProductId(),
'sku' => $this->getSKU(), 'sku' => $this->getSKU(),
'name' => $this->getName(), 'name' => $this->getName(),
'price' => $this->getPrice(), 'price' => $this->getPrice(),

4
view/products.php Normal file
View File

@ -0,0 +1,4 @@
<?php
require '../model/product.php';
echo json_encode(Product::selectAll());