edit inline for single list entries

This commit is contained in:
Tim Krehan 2019-05-28 15:55:00 +02:00
parent 467960037f
commit f3f65c6748
4 changed files with 87 additions and 2 deletions

View file

@ -72,7 +72,32 @@ function editItem(){
row.find(".dropdown").html("");
row.find(".dropdown").addClass("d-flex", "flex-row");
row.find(".dropdown").html("<i class='fas fa-check p-1'></i><i class='fas fa-times p-1'></i>");
var checkButton = $("<button type='button' class='save-list-row-changes btn p-2'><i class='fas fa-check'></i></button>");
var removeButton = $("<button type='button' class='del-list-row-changes btn p-2'><i class='fas fa-times'></i></button>");
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")
},

View file

@ -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';

View file

@ -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;

View file

@ -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;
}