diff --git a/admin/stock.php b/admin/stock.php
index e177e45..fe96e72 100644
--- a/admin/stock.php
+++ b/admin/stock.php
@@ -1,123 +1,6 @@
get_articles();
-$categories = $dao->get_categories();
-
-for ($i = 0; $i < sizeof($stock); $i++) {
- $article_categories = $dao->get_article_categories($stock[$i]["id"]);
- $stock[$i]["type"] = $article_categories;
-}
-
-ob_start();
-?>
-
-
-
-
-
-
-
Gestion des Stocks
-
-
Ajouter un article
-
-
-
Liste d'articles
-
-
- = $tableHeader ?>
-
-
-
-
-
-
-
-
Fichier de stock V2 non trouvé
-
-
-
-
-
-
-
->
-
-
-
-
-
-
-";
-include($relativePath . "includes/template.php");
-?>
+$pageTitle = "Gestion des articles";
+$script = "";
+include("template.php");
diff --git a/assets/css/categories.css b/assets/css/categories.css
index 7257e7e..551fe4f 100644
--- a/assets/css/categories.css
+++ b/assets/css/categories.css
@@ -5,7 +5,6 @@
}
#dataList li {
- text-align: center;
height: 50px;
line-height: 50px;
display: flex;
@@ -21,6 +20,12 @@
#dataList li div {
margin: auto;
display: flex;
+ width: 100%;
+}
+
+#dataList li div span {
+ margin-right: 5px;
+ height: 50px;
}
#listContainer {
@@ -31,3 +36,24 @@
.mdi {
font-size: 2rem;
}
+
+.list-name {
+ font-weight: bold;
+ width: 150px;
+}
+
+.list-description {
+ width: 200px;
+ overflow: hidden;
+}
+
+.list-price {
+ width: 70px;
+ text-align: center;
+}
+
+.list-code {
+ color: #8e8e8e;
+ width: 200px;
+ text-align: right;
+}
diff --git a/assets/js/ajaxManager.js b/assets/js/ajaxManager.js
index b7e697d..a51d0bb 100644
--- a/assets/js/ajaxManager.js
+++ b/assets/js/ajaxManager.js
@@ -1,9 +1,9 @@
class AjaxManager {
- static async getCategories() {
+ static async get(type) {
let data = {
- type: 'category',
+ type: type,
action: 'get',
};
let response = await $.ajax({
@@ -17,9 +17,9 @@ class AjaxManager {
return response['data'];
}
- static async deleteCategory(id) {
+ static async delete(id, type) {
let data = {
- type: 'category',
+ type: type,
action: 'remove',
data: id,
};
@@ -34,17 +34,17 @@ class AjaxManager {
return response['status'];
}
- static async saveCategory(category, isNew) {
- let data = {
- type: 'category',
+ static async save(data, isNew, type) {
+ let formattedData = {
+ type: type,
action: isNew ? 'create' : 'update',
- data: category,
+ data: data,
};
-
+ console.log(formattedData);
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
- data: JSON.stringify(data),
+ data: JSON.stringify(formattedData),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
diff --git a/assets/js/articles.js b/assets/js/articles.js
new file mode 100644
index 0000000..a71eeca
--- /dev/null
+++ b/assets/js/articles.js
@@ -0,0 +1,27 @@
+let listManager;
+
+$(document).ready(function () {
+ listManager = new ListManager($("#dataList"), 'article',
+ [
+ {
+ name: 'name',
+ description: 'Nom',
+ type: 'text'
+ },
+ {
+ name: 'description',
+ description: 'Description',
+ type: 'text'
+ },
+ {
+ name: 'price',
+ description: 'Prix',
+ type: 'number'
+ },
+ {
+ name: 'code',
+ description: 'Code',
+ type: 'text'
+ },
+ ]);
+});
diff --git a/assets/js/listManager.js b/assets/js/listManager.js
index 2dcaa5b..d5110d8 100644
--- a/assets/js/listManager.js
+++ b/assets/js/listManager.js
@@ -3,16 +3,17 @@ class ListManager {
currentData = [];
displayedData = [];
editableTypes = [];
+ type = '';
+
constructor(listContainer, type, editableTypes) {
this.listContainer = listContainer;
this.editableTypes = editableTypes;
- if (type === 'category') {
- AjaxManager.getCategories().then((data) => {
- this.currentData = data;
- this.generateList()
- });
- }
+ this.type = type;
+ AjaxManager.get(type).then((data) => {
+ this.currentData = data;
+ this.generateList()
+ });
}
generateList() {
@@ -43,7 +44,7 @@ class ListManager {
if (this.editableTypes[i]["type"] === "icon")
listItem += "
";
else
- listItem += item["name"] + '';
+ listItem += item[this.editableTypes[i]["name"]] + '';
}
listItem += "
";
return listItem;
@@ -53,6 +54,7 @@ class ListManager {
let formData = '