List available games on front page

This commit is contained in:
Stephen McQuay 2015-08-27 21:43:09 -07:00
parent 28353170c6
commit 6bad86730e
2 changed files with 11 additions and 50 deletions

View File

@ -19,7 +19,10 @@
</div> </div>
</div> </div>
<div class="container" id="game-list"></div> <div class="container">
<ul id="games">
</ul>
</div>
<script src="/ui/jquery.js"></script> <script src="/ui/jquery.js"></script>
<script src="/ui/bs/js/bootstrap.min.js"></script> <script src="/ui/bs/js/bootstrap.min.js"></script>

View File

@ -3,58 +3,16 @@ $(function(){
if($("#error > div").text() != "") { if($("#error > div").text() != "") {
$("#error").show(); $("#error").show();
} }
loadServers();
loadGames(); loadGames();
}); });
function loadServers() {
$.get("/ui/servers", function(data) {
$("#server-list").append(data);
$(".start").click(function(e) {
$("#error").hide();
data = {
'server': $(this).attr("value"),
}
$.post(
"/api/v1/game/add/",
JSON.stringify(data),
function(data) {
if (data.ok) {
loadGames();
} else {
$("#error").text(data.error);
$("#error").show();
}
}
);
});
});
}
function loadGames() { function loadGames() {
$.get("/ui/games", function(data) { $.get("/api/v0/game/list/", function(data) {
$("#game-list").empty(); $("#games").empty();
$("#game-list").append(data); for (var key in data) {
$(".stop").click(function(e) { var name = data[key]["id"];
$("#error").hide(); var s = "<li><a href='/ui/game/" + name + "/'>join</a> " + name + "</li>";
data = { $("#games").append(s);
'name': $(this).attr("server"), }
'game_id': $(this).attr("value"),
}
$.post(
"/api/v1/game/stop/",
JSON.stringify(data),
function(data) {
if (data.ok) {
loadGames();
} else {
$("#error").text(data.error);
$("#error").show();
}
}
);
});
}); });
} }