use and delete items
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
let img;
|
||||
let update;
|
||||
let invUpdate;
|
||||
|
||||
function delitem(id) {
|
||||
alert(id);
|
||||
function useInv(id, type) {
|
||||
$.ajax({
|
||||
url: window.api + `player/inv/${type}/${id}`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function (resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
},
|
||||
error: function (resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
function useItem(id) {
|
||||
alert(id);
|
||||
@@ -108,26 +120,26 @@ function invPlayer() {
|
||||
$("<span>").addClass("material-symbols-outlined").text("close"),
|
||||
);
|
||||
|
||||
$li.on("click", () => useItem(item.id));
|
||||
$li.on("click", () => useInv(item.id, "use"));
|
||||
$delBtn.on("click", (e) => {
|
||||
e.stopPropagation();
|
||||
delitem(item.id);
|
||||
useInv(item.id, "del");
|
||||
});
|
||||
|
||||
$li.append($delBtn);
|
||||
return $li;
|
||||
};
|
||||
|
||||
if (invUpdate === undefined || resp.invPeso !== invUpdate) {
|
||||
$("#inv ul").empty();
|
||||
resp.InvItems.forEach((item) => {
|
||||
$("#inv ul").append(buildItem(item));
|
||||
});
|
||||
invUpdate = resp.invPeso;
|
||||
}
|
||||
|
||||
$("#inv ul").empty();
|
||||
resp.InvItems.forEach((item) => {
|
||||
$("#inv ul").append(buildItem(item));
|
||||
});
|
||||
$("#invPA").text(resp.invPeso);
|
||||
},
|
||||
error: function () {
|
||||
$("#inv ul").empty();
|
||||
$("#invPA").text(0);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,5 +167,5 @@ $(document).ready(function () {
|
||||
load_ficha();
|
||||
roll_load();
|
||||
invPlayer();
|
||||
}, 500);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user