forked from PlayersCouncil/gemp-lotr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgameHistoryUi.js
74 lines (67 loc) · 3.19 KB
/
gameHistoryUi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var GameHistoryUI = Class.extend({
communication:null,
itemStart:0,
pageSize:20,
init:function (url) {
this.communication = new GempClientCommunication(url,
function (xhr, ajaxOptions, thrownError) {
});
this.loadHistory();
},
loadHistory:function () {
var that = this;
this.communication.getGameHistory(this.itemStart, this.pageSize,
function (xml) {
that.loadedGameHistory(xml);
});
},
loadedGameHistory:function (xml) {
log(xml);
var root = xml.documentElement;
if (root.tagName == 'gameHistory') {
var historyTable = $("<table class='gameHistory'></table>");
historyTable.append("<tr><th>Format</th><th>Tournament</th><th>Deck</th><th>Winner</th><th>Loser</th><th>Win reason</th><th>Lose reason</th><th>Finished on</th><th>Replay link</th></tr>");
var entries = root.getElementsByTagName("historyEntry");
for (var i = 0; i < entries.length; i++) {
var historyEntry = entries[i];
var format = historyEntry.getAttribute("formatName");
var tournament = historyEntry.getAttribute("tournament");
var deck = historyEntry.getAttribute("deckName");
var winner = historyEntry.getAttribute("winner");
var loser = historyEntry.getAttribute("loser");
var winReason = historyEntry.getAttribute("winReason");
var loseReason = historyEntry.getAttribute("loseReason");
var endTime = historyEntry.getAttribute("endTime"); //formatDate(new Date(parseInt(historyEntry.getAttribute("endTime"))));
var gameRecordingId = historyEntry.getAttribute("gameRecordingId");
var row = $("<tr></tr>");
if (format != null)
row.append($("<td></td>").html(format));
else
row.append($("<td></td>").html(" "));
if (tournament != null)
row.append($("<td></td>").html(tournament));
else
row.append($("<td></td>").html(" "));
if (deck != null)
row.append($("<td></td>").html(deck));
else
row.append($("<td></td>").html(" "));
row.append($("<td></td>").html(winner));
row.append($("<td></td>").html(loser));
row.append($("<td></td>").html(winReason));
row.append($("<td></td>").html(loseReason));
row.append($("<td></td>").html(endTime));
if (gameRecordingId != null) {
var link = "game.html?replayId=" + root.getAttribute("playerId") + "$" + gameRecordingId;
var linkElem = $("<a>replay game</a>");
linkElem.attr("href", link);
row.append($("<td></td>").html(linkElem));
} else {
row.append($("<td></td>").html("<i>not stored</i>"));
}
historyTable.append(row);
}
$("#gameHistory").append(historyTable);
}
}
});