implemented remove item

This commit is contained in:
Tim Krehan 2019-05-28 09:12:47 +02:00
parent 1d1e6cf6a5
commit b6b4358157
4 changed files with 44 additions and 8 deletions

View file

@ -38,15 +38,15 @@
print_r("<div class='list-row $div_item_row_classes $div_item_row_color_classes'>"); print_r("<div class='list-row $div_item_row_classes $div_item_row_color_classes'>");
print_r("<div class='$div_item_checkbox_classes'><input type='checkbox' class='$input_item_checkbox_classes' data-buttoncolor='$button_theme' data-color='$color_theme' data-id='$item->ID' $checked></div>"); print_r("<div class='$div_item_checkbox_classes'><input type='checkbox' class='$input_item_checkbox_classes' data-buttoncolor='$button_theme' data-color='$color_theme' data-id='$item->ID' $checked></div>");
print_r("<div class='$div_item_quantity_classes'>$item->Anzahl $item->Einheit</div>"); print_r("<div class='list-row-amount $div_item_quantity_classes' data-amount='$item->Anzahl' data-unit='$item->Einheit'>$item->Anzahl $item->Einheit</div>");
print_r("<div class='$div_item_name_classes'>$item->Name</div>"); print_r("<div class='list-row-name $div_item_name_classes'>$item->Name</div>");
print_r("<div class='$div_item_menu dropdown'>"); print_r("<div class='$div_item_menu dropdown'>");
print_r("<button type='button' class='$button_dropdown_classes $button_dropdown_color_classes' id='dropdown-menu-button-dataID-" . $item->ID . "' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>"); print_r("<button type='button' class='$button_dropdown_classes $button_dropdown_color_classes' id='dropdown-menu-button-dataID-" . $item->ID . "' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>");
print_r("<i class='fas fa-angle-down'></i>"); print_r("<i class='fas fa-angle-down'></i>");
print_r("</button>"); print_r("</button>");
print_r("<div class='dropdown-menu dropdown-menu-right' aria-labelledby='dropdown-menu-button-dataID-" . $item->ID . "'>"); print_r("<div class='dropdown-menu dropdown-menu-right' aria-labelledby='dropdown-menu-button-dataID-" . $item->ID . "'>");
print_r("<button type='button' class='dropdown-item'><i class='fas fa-edit'></i> Bearbeiten</button>"); print_r("<button type='button' class='edit-listitem dropdown-item'><i class='fas fa-edit'></i> Bearbeiten</button>");
print_r("<button type='button' class='dropdown-item'><i class='fas fa-trash-alt'></i> Löschen</button>"); print_r("<button type='button' class='del-listitem dropdown-item'><i class='fas fa-trash-alt'></i> Löschen</button>");
print_r("</div>"); print_r("</div>");
print_r("</div>"); print_r("</div>");
print_r("</div>"); print_r("</div>");

View file

@ -5,6 +5,8 @@ $(document).ready(function () {
$("#nameField").focus(); $("#nameField").focus();
$("#anzahl").on("focus", function () { $(this).select(); }); $("#anzahl").on("focus", function () { $(this).select(); });
$("#nameField").on("focus", function () { $(this).select(); }); $("#nameField").on("focus", function () { $(this).select(); });
$(".edit-listitem").click(editItem);
$(".del-listitem").click(deleteSingleItem);
}); });
function highlightNewEntry(){ function highlightNewEntry(){
@ -27,16 +29,37 @@ function highlightNewEntry(){
function deleteCheckeditems() { function deleteCheckeditems() {
$.post({ $.post({
url: "api/list/del", url: "api/list/clear",
data: {
function: "del"
},
success: function () { success: function () {
location.reload(); location.reload();
} }
}); });
} }
function deleteSingleItem() {
var id = $(this).parent().parent().parent().find("input[type=checkbox]").data("id");
$.post({
url: "api/list/del",
data: {
id: id
},
success: function (data) {
location.reload();
}
});
}
function editItem(){
var row = $(this).parent().parent().parent();
var amount = row.find(".list-row-amount").data("amount");
var unit = row.find(".list-row-amount").data("unit");
var name = row.find(".list-row-name").html();
row.find(".list-row-amount").html("");
row.find(".list-row-name").html("");
row.find(".list-row-amount").append("");
row.find(".list-row-name").append('<input type="text" class="form-control" autocomplete="off" value="'+name+'" required>');
}
function checkItem() { function checkItem() {
var dataId = $(this).data("id"); var dataId = $(this).data("id");
$.post({ $.post({

View file

@ -52,6 +52,15 @@
} }
} }
function removeSingleItem($id){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
$deleteQuery = $mysqli->prepare("DELETE FROM `Einkauf` WHERE `Einkauf`.`ID` = ?;");
$deleteQuery->bind_param("s", $id);
$deleteQuery->execute();
$mysqli->close();
}
function removeChecked(){ function removeChecked(){
include $_SESSION["docroot"].'/config/config.php'; include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php'; include $_SESSION["docroot"].'/php/connect.php';

View file

@ -14,6 +14,10 @@
break; break;
case 'del': case 'del':
$shopping->removeSingleItem($_POST["id"]);
break;
case 'clear':
$shopping->removeChecked(); $shopping->removeChecked();
break; break;