From 1ea3366c70ad87f2c0d3fa3ae3a56f27b691f696 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 23 Apr 2014 13:07:25 -0400 Subject: clean up the javascript everywhere --- app/assets/javascripts/tournaments_show.js.coffee | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/assets/javascripts/tournaments_show.js.coffee (limited to 'app/assets/javascripts/tournaments_show.js.coffee') diff --git a/app/assets/javascripts/tournaments_show.js.coffee b/app/assets/javascripts/tournaments_show.js.coffee new file mode 100644 index 0000000..1e91d3a --- /dev/null +++ b/app/assets/javascripts/tournaments_show.js.coffee @@ -0,0 +1,30 @@ +Update = (tournament) -> + here = tournament["players"].length + needed = (tournament["min_teams_per_match"] * tournament["min_players_per_team"]) + pct_complete = here / needed + + $("#prog-bar").width (pct_complete * 100) + "%" + $("#players-needed").text here + " " + ((if here is 1 then "player has" else "players have")) + " signed up. " + needed + " players needed. " + + # Update the user list + players = "" + for player in tournament["players"] + players = players + "
  • " + player["user_name"] + "
  • " + $("#tournament-users").html players + + # Enable/disable the "start" button depending on the number of players + $("input[value=\"Start Tournament\"]").prop "disabled", (if (pct_complete >= 1) then false else true) + + # Switch views if the tournament has been started + if tournament["status"] is 1 + window.location.reload true + + # Do it all again + setTimeout (-> + $.ajax(url: window.location.href.replace(/\..*/,'')+".json").done Update + return + ), 2000 + +# Now kick off the whole process +window.onload = -> + $.ajax(url: window.location.href.replace(/\..*/,'')+".json").done Update -- cgit v1.2.3-54-g00ecf