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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

199 lines
8.2 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="h4" id="player-name"></div>
<div id="player-level"></div>
<div class="h5" id="badge-header">Badges</div>
<div id="loading-badges">
<i class="fa fa-spinner fa-pulse"></i> Loading...
</div>
<div class="container" id="badge-container">
<div class="row" id="badges">
</div>
</div>
<div style="display: none;" id="privmsg-box">
<div class="h5" id="privmsg-header">Messages</div>
<div id="loading-privmsgs">
<i class="fa fa-spinner fa-pulse"></i> Loading...
</div>
<div class="container" id="privmsg-container">
<div class="list-group" id="privmsgs">
</div>
</div>
</div>
<div style="display: none;" id="sendmsg-box">
<div class="h5" id="sendmsg-header">Private Message</div>
<div class="container" id="sendmsg-container">
<form id="sendprivmsgform">
<div class="input-group">
<input type="text" class="form-control" id="privmsgbox" placeholder="Send message" />
<div class="input-group-btn">
<button type="submit" class="btn btn-success" id="sendprivmsg"><i class="fa fa-paper-plane"></i></button>
</div>
</div>
</form>
</div>
</div>
<script>
function popBadge(name, desc) {
navigator.notification.alert(desc, null, name, "Close");
}
function loadProfile(user) {
$('#player-name').text(user);
loadBadges(user);
loadPlayerStats(user);
if (user == username) {
loadPrivmsgs();
} else {
$('#sendmsg-box').css('display', 'block');
}
}
$("#sendprivmsgform").submit(function (event) {
var message = $('#privmsgbox').val();
var toplayer = $('#player-name').text();
if (message !== '') {
$.post(mkApiUrl('privmsgs'), {
msg: message,
to: toplayer,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK') {
$('#privmsgbox').val("");
$("#privmsgbox").attr("placeholder", "Message sent!");
setTimeout(function () {
$("#privmsgbox").attr("placeholder", "Send message");
}, 2000);
}
}, "json");
}
event.preventDefault();
return false;
});
function loadPlayerStats(user) {
$.getJSON(mkApiUrl('getstats'), {
user: user,
lang: USER_LANGUAGE
}, function (data) {
if (data.status === 'OK' && data.stats != null) {
if (data.stats.level != null) {
$('#player-level').text('Level ' + Math.floor(data.stats.level));
} else {
$('#player-level').text('Player does not exist.');
}
teamcolor = getTeamColorFromId(data.stats.teamid);
$('#player-name').css('border-color', '#' + teamcolor);
$('#player-name').css('color', '#' + teamcolor);
$('#player-level').css('border-color', '#' + teamcolor);
$('#badge-header').css('border-color', '#' + teamcolor);
$('#badges').css('border-color', '#' + teamcolor);
$('.badge-img').css('border-color', '#' + teamcolor);
$('#privmsg-header').css('border-color', '#' + teamcolor);
$('#privmsg-container').css('border-color', '#' + teamcolor);
$('#loading-privmsgs').css('border-color', '#' + teamcolor);
$('#sendmsg-header').css('border-color', '#' + teamcolor);
$('#sendmsg-container').css('border-color', '#' + teamcolor);
} else {
$('#player-level').text('Cannot load player stats.');
}
}).fail(function () {
$('#player-level').html('Loading failed. <a onclick="loadProfile(\'' + user + '\')">Reload</a>');
});
}
function loadBadges(user) {
$('#loading-badges').html('<i class="fa fa-spinner fa-pulse"></i> Loading...');
$('#loading-badges').css('display', 'block');
$.getJSON(
mkApiUrl('getbadges') + '?user=' + user + "&lang=" + USER_LANGUAGE,
function (data) {
if (data.status === 'OK') {
$('#badges').html("");
data.badges.forEach(function (item) {
var badgehtml = '<div class="col col-xs-3 col-md-2 col-lg-1" '
+ 'onclick="popBadge(\'' + item.badgename + '\', \'' + item.badgedesc + '\')">'
+ '<img class="badge-img img-circle img-responsive" alt="" src="assets/badges/' + item.badgesid + '.png" onerror="this.src=\'assets/badges/badge.png\'"/>'
+ '</div>'
$('#badges').append(badgehtml);
});
$('#loading-badges').css('display', 'none');
} else {
$('#loading-badges').html('Loading failed. <a onclick="loadAchievements(\'' + user + '\')">Reload</a>');
}
}
).fail(
function (err) {
$('#loading-badges').html('Loading failed, <a onclick="loadProfile(\'' + user + '\')">reload</a>"');
}
);
}
function loadPrivmsgs() {
$('#loading-privmsgs').html('<i class="fa fa-spinner fa-pulse"></i> Loading...');
$('#loading-privmsgs').css('display', 'block');
$('#privmsg-box').css('display', 'block');
$('#privmsgs').css('display', 'block');
$.getJSON(
mkApiUrl('privmsgs') + "?lang=" + USER_LANGUAGE,
function (data) {
if (data.status === 'OK') {
$('#privmsgs').html("");
data.msgs.forEach(function (item) {
var privmsghtml = '<div class="list-group-item" '
+ (item.msg_read == 0 ? 'onclick="markMsgRead(\'' + item.id + '\')"' : '') + '>'
+ '<button class="btn btn-danger pull-right" onclick="deleteMsg(\'' + item.id + '\')"><i class="fa fa-trash"></i></button>'
+ (item.msg_read == 0 ? '<b>' : '') + item.message + (item.msg_read == 0 ? '</b>' : '')
+ '<br />' + (item.msg_read == 0 ? '<b>' : '') + "From: " + item.nickname + (item.msg_read == 0 ? '</b>' : '')
+ '</div>';
$('#privmsgs').append(privmsghtml);
});
$('#loading-privmsgs').css('display', 'none');
} else {
$('#loading-privmsgs').html('Loading failed. <a onclick="loadPrivmsgs()">Reload</a>');
}
}
).fail(
function (err) {
$('#loading-privmsgs').html('Loading failed, <a onclick="loadPrivmsgs()">reload</a>"');
}
);
}
function markMsgRead(id) {
$.getJSON(
mkApiUrl('privmsgs') + "?markread=" + id,
function () {
loadPrivmsgs();
privMsgSync();
}
);
}
function deleteMsg(id) {
$.getJSON(
mkApiUrl('privmsgs') + "?delete=" + id,
function () {
loadPrivmsgs();
privMsgSync();
}
);
}
</script>