/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ function loadInventory(reload) { if (typeof reload != "boolean") { reload = false; // Make it reload if there's already stuff there, // to keep the items from disappearing and coming back if ($("#item-bin .item-col").length > 0) { reload = true; } } if (reload == false) { $("#item-bin .item-col").remove(); $("#item-bin #bag-preloader").removeClass("display-none"); } callAPI("inventory", { username: localStorage.getItem("username"), password: localStorage.getItem("password") }, function (resp) { var items = []; for (var i = 0; i < resp.items.length; i++) { var item = resp.items[i]; var found = false; for (var j = 0; j < items.length; j++) { if (items[j].id == item.id && items[j].json == item.json) { items[j].qty += 1; items[j].uuids.push(item.uuid); found = true; break; } } if (!found) { item["qty"] = 1; item["uuids"] = [item.uuid]; items.push(item); } } $("#item-bin .item-col").remove(); if (reload == false) { $("#item-bin #bag-preloader").addClass("display-none"); } items.forEach(function (item) { $("#item-bin").append('
' + '
' + '
' + (item.qty > 1 ? 'x' + item.qty + '' : "") + '

' + item.name + '

' + item.description + (item.classname == "healmagic" ? '' : '') + '
' + '
'); }) }, function (msg) { app.dialog.alert(msg, "Error"); }); } $("body").on("click", ".useitem-button", function () { var itemdom = $(this).parent(".item"); var uuids = itemdom.data("uuids") + ""; console.log(uuids); console.log(uuids.split("|")[0]); var qty = itemdom.data("qty"); var uuid = uuids.split("|")[0]; callAPI("useitem", { username: localStorage.getItem("username"), password: localStorage.getItem("password"), uuid: uuid }, function (success) { app.toast.show({ text: ' ' + success.msg, position: "center", destroyOnClose: true, closeTimeout: 5000 }); loadInventory(true); }, function (error) { app.dialog.alert(error, "Error"); }); });