shopping-list/js/list.js

76 lines
2.5 KiB
JavaScript
Raw Normal View History

$(document).ready(function () {
2019-05-22 21:17:53 +02:00
highlightNewEntry();
$("input[type=checkbox]").change(checkItem);
$("#remove").click(deleteCheckeditems);
$("#nameField").focus();
$("#anzahl").on("focus", function () { $(this).select(); });
$("#nameField").on("focus", function () { $(this).select(); });
});
2019-05-22 21:17:53 +02:00
function highlightNewEntry(){
var cookies = document.cookie;
2019-05-23 08:47:48 +02:00
var cookieRegExp = new RegExp(/;?\s+newItem=(\d+)/g);
var match = cookieRegExp.exec(cookies);
2019-05-26 17:11:47 +02:00
console.log(match);
2019-05-23 08:47:48 +02:00
if(match!=null){
var newID = match[1];
var checkBox = $(`[data-id='${newID}']`);
2019-05-23 08:47:48 +02:00
var newRow = checkBox.parent().parent();
newRow.removeClass($(checkBox).data("color"));
newRow.addClass("alert-primary");
setTimeout(function () {
newRow.removeClass("alert-primary");
newRow.addClass($(checkBox).data("color"));
}, 1000);
document.cookie = "newItem=-1"
}
2019-05-22 21:17:53 +02:00
}
2019-05-19 18:37:00 +02:00
function deleteCheckeditems() {
$.post({
url: "api/list/del",
data: {
function: "del"
},
success: function () {
location.reload();
}
2018-10-24 15:00:27 +02:00
});
2019-05-19 18:37:00 +02:00
}
function checkItem() {
var dataId = $(this).data("id");
$.post({
url: "api/list/check",
data: {
function: "check",
id: dataId,
status: $(this).prop("checked")
},
success: function () {
2019-05-26 17:07:08 +02:00
var dataIdSelector = (`[data-id='${dataId}']`);
2019-05-26 17:07:47 +02:00
var color = $(dataIdSelector).data("color");
$(dataIdSelector).parent().parent().removeClass("bg-danger");
2019-05-19 18:37:00 +02:00
2019-05-26 17:07:47 +02:00
if($(dataIdSelector).prop("checked")){
$(dataIdSelector).parent().parent().removeClass(color);
$(dataIdSelector).parent().parent().addClass("bg-success");
}
else{
$(dataIdSelector).parent().parent().removeClass("bg-success");
$(dataIdSelector).parent().parent().addClass(color);
}
},
error: function () {
$(dataIdSelector).parent().parent().addClass("bg-danger");
$(dataIdSelector).parent().parent().data("toggle", "popover");
$(dataIdSelector).parent().parent().data("container", "body");
$(dataIdSelector).parent().parent().data("placement", "top");
$(dataIdSelector).parent().parent().data("html", true);
$(dataIdSelector).parent().parent().data("trigger", "focus");
$(dataIdSelector).parent().parent().data("content", "Dieses Element konnte nicht gespeichert werden.<br />Bitte die Seite Aktualisieren");
$(dataIdSelector).parent().parent().attr("title", "Fehler!");
$(dataIdSelector).parent().parent().popover('show');
2019-05-19 18:37:00 +02:00
}
2018-10-24 15:00:27 +02:00
});
}