diff --git a/js/list.js b/js/list.js
index 7408391..89b02e1 100644
--- a/js/list.js
+++ b/js/list.js
@@ -72,7 +72,32 @@ function editItem(){
row.find(".dropdown").html("");
row.find(".dropdown").addClass("d-flex", "flex-row");
- row.find(".dropdown").html("");
+ var checkButton = $("");
+ var removeButton = $("");
+ row.find(".dropdown").append(checkButton);
+ row.find(".dropdown").append(removeButton);
+
+ checkButton.click(changeListItem);
+ removeButton.click(function(){window.location = window.location;});
+}
+
+function changeListItem(){
+ var id = $(this).parent().parent().find("input[type=checkbox]").data("id");
+ var amount = $(this).parent().parent().find("input[type=number]").val();
+ var unit = $(this).parent().parent().find("select option:selected").val();
+ var name = $(this).parent().parent().find("input[type=text]").val();
+ $.post({
+ url: "api/list/change",
+ data: {
+ id: id,
+ anzahl: amount,
+ einheit: unit,
+ name: name
+ },
+ success: function(data){
+ window.location = window.location;
+ }
+ });
}
function checkItem() {
@@ -80,7 +105,7 @@ function checkItem() {
$.post({
url: "api/list/check",
data: {
- function: "check",
+ // function: "check",
id: dataId,
status: $(this).prop("checked")
},
diff --git a/php/classes.list.php b/php/classes.list.php
index 74c22f5..2834111 100644
--- a/php/classes.list.php
+++ b/php/classes.list.php
@@ -61,6 +61,49 @@
$mysqli->close();
}
+ function changeSingleItem($id, $anzahl, $einheit, $name){
+ include $_SESSION["docroot"].'/config/config.php';
+ include $_SESSION["docroot"].'/php/connect.php';
+ $paramCount = "s";
+ $query = "UPDATE `Einkauf` SET";
+ if($anzahl!=""){
+ $paramCount .= "s";
+ $query .= " `Anzahl` = ?";
+ }
+ if($einheit!=""){
+ if(strlen($paramCount)>1){
+ $query .= ",";
+ }
+ $paramCount .= "s";
+ $query .= " `Einheit` = ?";
+ }
+ if($name!=""){
+ if(strlen($paramCount)>1){
+ $query .= ",";
+ }
+ $paramCount .= "s";
+ $query .= " `Name` = ?";
+ }
+ if(strlen($paramCount)>1){
+ $query .= " WHERE `Einkauf`.`ID` = ?;";
+ $updateQuery = $mysqli->prepare($query);
+ if($anzahl!="" && $name!=""){
+ $updateQuery->bind_param($paramCount, $anzahl, $einheit, $name, $id);
+ }
+ elseif($anzahl!="" && $name==""){
+ $updateQuery->bind_param($paramCount, $anzahl, $einheit, $id);
+ }
+ elseif($anzahl=="" && $name!=""){
+ $updateQuery->bind_param($paramCount, $einheit, $name, $id);
+ }
+ elseif($anzahl=="" && $name==""){
+ $updateQuery->bind_param($paramCount, $einheit, $id);
+ }
+ $updateQuery->execute();
+ $mysqli->close();
+ }
+ }
+
function removeChecked(){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
diff --git a/php/edit-list.php b/php/edit-list.php
index eb5a4f6..e53a95e 100644
--- a/php/edit-list.php
+++ b/php/edit-list.php
@@ -13,6 +13,10 @@
$shopping->newItems($_POST["list"]);
break;
+ case 'change':
+ $shopping->changeSingleItem($_POST["id"], $_POST["anzahl"], $_POST["einheit"], $_POST["name"]);
+ break;
+
case 'del':
$shopping->removeSingleItem($_POST["id"]);
break;
diff --git a/style/helper.css b/style/helper.css
index 9963fd9..5b2d0a6 100644
--- a/style/helper.css
+++ b/style/helper.css
@@ -15,6 +15,19 @@
box-shadow: none;
}
+.save-list-row-changes {
+ color: var(--light);
+}
+.save-list-row-changes:hover {
+ color: var(--success);
+}
+.del-list-row-changes {
+ color: var(--light);
+}
+.del-list-row-changes:hover {
+ color: var(--danger);
+}
+
.nav-link-font {
font-size: 16px !important;
}
\ No newline at end of file