uniScore/public/js/front_client.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-11-24 17:57:48 +00:00
"use strict";
2017-03-14 15:02:54 +00:00
var iosocket = io.connect();
2018-11-24 17:57:48 +00:00
var tbdLabel = "To be determined",
noTeam = "Kein Team";
2017-03-20 17:12:20 +00:00
// setup all my handlers
2018-11-24 17:57:48 +00:00
iosocket.on("clientrefresh", function() {
location.reload();
});
2018-11-24 17:57:48 +00:00
iosocket.on("stateChange", function(state) {
console.log(state);
// basically the server tracks the state since it is the same for al clients
// So we know that we HAVE to update at this point
2018-11-24 17:57:48 +00:00
$("#team-container").bracket({
2017-03-20 17:12:20 +00:00
init: state,
decorator: {
2018-11-24 17:57:48 +00:00
edit: function() {},
2017-03-20 17:12:20 +00:00
render: render_fn
},
teamWidth: 130,
scoreWidth: 20,
2017-03-22 15:19:25 +00:00
matchMargin: 35,
roundMargin: 40
2017-03-20 17:12:20 +00:00
});
2017-03-13 12:53:22 +00:00
});
2017-03-20 17:12:20 +00:00
function render_fn(container, data, score, state) {
switch (state) {
case "empty-bye":
2018-11-24 17:57:48 +00:00
container.append(noTeam);
2017-03-20 17:12:20 +00:00
return;
case "empty-tbd":
2018-11-24 17:57:48 +00:00
container.append(tbdLabel);
return;
2017-03-20 17:12:20 +00:00
case "entry-no-score":
2018-11-24 17:57:48 +00:00
console.log("no score"); // no return
2017-03-20 17:12:20 +00:00
case "entry-default-win":
2018-11-24 17:57:48 +00:00
console.log("default win"); // no return
2017-03-20 17:12:20 +00:00
case "entry-complete":
container.append(data);
return;
}
}
2017-03-13 12:53:22 +00:00
2018-11-24 17:57:48 +00:00
$(document).ready(function() {
tbdLabel = $("#TBD").val();
noTeam = $("#NoT").val();
// get my state
var context = "main";
iosocket.emit("loadState", context);
});