mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 22:30:41 +01:00
implemented remove item
This commit is contained in:
parent
1d1e6cf6a5
commit
b6b4358157
4 changed files with 44 additions and 8 deletions
|
@ -38,15 +38,15 @@
|
|||
|
||||
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_quantity_classes'>$item->Anzahl $item->Einheit</div>");
|
||||
print_r("<div class='$div_item_name_classes'>$item->Name</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='list-row-name $div_item_name_classes'>$item->Name</div>");
|
||||
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("<i class='fas fa-angle-down'></i>");
|
||||
print_r("</button>");
|
||||
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='dropdown-item'><i class='fas fa-trash-alt'></i> Löschen</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='del-listitem dropdown-item'><i class='fas fa-trash-alt'></i> Löschen</button>");
|
||||
print_r("</div>");
|
||||
print_r("</div>");
|
||||
print_r("</div>");
|
||||
|
|
31
js/list.js
31
js/list.js
|
@ -5,6 +5,8 @@ $(document).ready(function () {
|
|||
$("#nameField").focus();
|
||||
$("#anzahl").on("focus", function () { $(this).select(); });
|
||||
$("#nameField").on("focus", function () { $(this).select(); });
|
||||
$(".edit-listitem").click(editItem);
|
||||
$(".del-listitem").click(deleteSingleItem);
|
||||
});
|
||||
|
||||
function highlightNewEntry(){
|
||||
|
@ -27,16 +29,37 @@ function highlightNewEntry(){
|
|||
|
||||
function deleteCheckeditems() {
|
||||
$.post({
|
||||
url: "api/list/del",
|
||||
data: {
|
||||
function: "del"
|
||||
},
|
||||
url: "api/list/clear",
|
||||
success: function () {
|
||||
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() {
|
||||
var dataId = $(this).data("id");
|
||||
$.post({
|
||||
|
|
|
@ -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(){
|
||||
include $_SESSION["docroot"].'/config/config.php';
|
||||
include $_SESSION["docroot"].'/php/connect.php';
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
break;
|
||||
|
||||
case 'del':
|
||||
$shopping->removeSingleItem($_POST["id"]);
|
||||
break;
|
||||
|
||||
case 'clear':
|
||||
$shopping->removeChecked();
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue