You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.8 KiB
HTML
77 lines
2.8 KiB
HTML
<!--
|
|
TerranQuest - Augmented Reality fantasy game
|
|
|
|
Copyright 2016 Netsyms Technologies
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
-->
|
|
<div class="scrollable-box">
|
|
<div class="list-group" id="inventory-list">
|
|
<div class="list-group-item">
|
|
<i class="fa fa-spinner fa-pulse fa-fw"></i> Loading...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function useitem(uuid) {
|
|
$('#invitem-' + uuid).prop('onclick', null).off('click');
|
|
$.getJSON(mkApiUrl('useitem', 'gs'), {
|
|
itemuuid: uuid
|
|
}, function (data) {
|
|
if (data.status === 'OK') {
|
|
loadinventory();
|
|
syncStats();
|
|
} else {
|
|
navigator.notification.alert(data.message, null, "Error", 'OK');
|
|
}
|
|
}).fail(function () {
|
|
navigator.notification.alert("Cannot use item. Try again.", null, "Error", 'OK');
|
|
});
|
|
}
|
|
|
|
function getitemhtmlfromjson(item) {
|
|
var itemhtml = "<div class='list-group-item inventory-item' id='item-" + item.itemuuid + "'>"
|
|
+ "<h4 class='itemname'>" + item.itemname + "</h4>"
|
|
+ "<p class='itemdesc'>" + item.itemdesc + "</p>";
|
|
if (item.classname == "healmagic") {
|
|
itemhtml += "<span class='btn btn-success' id='invitem-" + item.itemuuid + "' onclick=\"useitem('" + item.itemuuid + "')\">"
|
|
+ "Use Item"
|
|
+ "</span>";
|
|
}
|
|
itemhtml += "<span class='itemid' style='display: none;'>" + item.itemid + "</span>"
|
|
+ "<span class='itemclassid' style='display: none;'>" + item.classid + "</span>"
|
|
+ "<span class='itemjson' style='display: none;'>" + item.itemjson + "</span>"
|
|
+ "</div>";
|
|
return itemhtml;
|
|
}
|
|
|
|
function loadinventory() {
|
|
$.getJSON(mkApiUrl('inventory'), {
|
|
user: username
|
|
}, function (data) {
|
|
var content = "";
|
|
if (data.status == 'OK') {
|
|
var items = data.items;
|
|
items.forEach(function (item) {
|
|
content += getitemhtmlfromjson(item);
|
|
});
|
|
} else {
|
|
content = "<div class='list-group-item'>An error occurred.</div>";
|
|
}
|
|
$('#inventory-list').html(content);
|
|
});
|
|
}
|
|
|
|
loadinventory();
|
|
</script> |