Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'spencer' of github.com:h4rr/sc2tournament into h4rr

  • Loading branch information...
commit b1e7e858ad535ee7d7d1a028d6de8ac53fb2fd51 2 parents 683a045 + 6f98d95
Harrison Weingard authored
Showing with 66 additions and 83 deletions.
  1. +66 −83 templates/test_tree.html
View
149 templates/test_tree.html
@@ -1,11 +1,11 @@
<html>
<head>
- <!--<script type="text/javascript" src="{{ STATIC_URL }}js/raphael-min.js"></script>
- <script type="text/javascript" src="{{ STATIC_URL }}js/dracula_graffle.js"></script> -->
- <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.4.2.min.js"></script><!--
+ <script type="text/javascript" src="{{ STATIC_URL }}js/raphael-min.js"></script>
+ <script type="text/javascript" src="{{ STATIC_URL }}js/dracula_graffle.js"></script>
+ <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/dracula_graph.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/dracula_algorithms.js"></script>
- <script type="text/javascript" src="{{ STATIC_URL }}js/binary_tree.js"></script>-->
+ <script type="text/javascript" src="{{ STATIC_URL }}js/binary_tree.js"></script>
<style type="text/css">
div#canvas {
border: 1px solid black;
@@ -116,10 +116,10 @@
</style>
<script type="text/javascript">
/* Get variables from template and use this to render tournament */
- /* $(document).ready(function() {
+ $(document).ready(function() {
renderTournament({{ tournament_id }});
//setInterval(function (){ renderTournament({{ tournament_id }}); }, 0000);
- });*/
+ });
</script>
</head>
<body>
@@ -128,17 +128,25 @@
{# Check to see if we should show them the admin stuff #}
{% ifequal t.organized_by.id request.user.id %}
-
<script type="text/javascript">
// Some ajaxy stuff for submitting the form
- $(document).ready(function() {
- $('.pending').click(function () {
+$(document).ready(function() {
+ function ajaxToggle(team) {
+ console.log("Called with " + team);
+ var accept = "{% url sc2tournament.views.tournament_accept %}";
+ var reject = "{% url sc2tournament.views.tournament_reject %}";
// Get the parent - i.e., the form element, this function is called from <a>
- var link = $(this).parent();
+ var link = $(team).parent();
// Get the form data to submit
var data = link.serialize();
// Get the URL that the form submits it to
var postUrl = link.attr('action');
+ // Conditional stuff to consolidate accepted/rejected into one function
+ var accepted = postUrl == accept;
+ if(accepted) console.log("Called with an accept url");
+ var newUrl = accepted ? reject : accept;
+ var appendClass = accepted ? "#accepted_teams" : "#pending_teams";
+ console.log("Posting to " + postUrl);
$.ajax({
// AJAX request to the URL the form was going to submit to
url: postUrl,
@@ -150,75 +158,61 @@
cache: false,
//success
success: function (html) {
+ console.log(html);
// TODO: we can check the result here
- if ( 1 == 1 ) {
+ if ( html.indexOf('<html>') != -1 ) {
// Move up to the <li> tag
link = link.parent();
// Fade it out, move it to accepted teams, fade in.
link.fadeOut(250, function() {
- link.remove().appendTo("#accepted_teams ul");
- link.fadeIn(250);
- });
- }
- }
- });
- });
- $('.accepted').click(function () {
- // Get the parent
- var link = $(this).parent();
- var data = link.serialize();
- var postUrl = link.attr('action');
- $.ajax({
- url: postUrl,
- type: "POST",
- //pass the data
- data: data,
- //Do not cache the page
- cache: false,
- //success
- success: function (html) {
- if ( 1 == 1 ) {
- link = link.parent();
- link.fadeOut(250, function() {
- link.remove().appendTo("#pending_teams ul");
- link.fadeIn(250);
+ link.remove().appendTo(appendClass + " ul");
+ link.fadeIn(250, function() {
+ $(this).find('form').attr('action', newUrl);
+ console.log("Setting post to " + newUrl);
+ // Damn you jQuery, I don't want to set another click listener for the same element
+ $(this).find("a").click(function() {
+ ajaxToggle(this)
+ });
+ });
});
- }
- }
+ } else { // Deal with an ajax error
+ $("#error").text("There was an error! " +html+ " (click to close) ");
+ $("#error").fadeIn();
+ $("#error").click(function () {
+ $(this).fadeOut();
+ });
+ }
+
+ }
});
- });
-
- $('form').submit(function() {
- alert($(this).serialize());
- var data = $(this).serialize();
- //start the ajax
- $.ajax({
- //this is the php file that processes the data and send mail
- url: "process.php",
- //GET method is used
- type: "POST",
- //pass the data
- data: data,
- //Do not cache the page
- cache: false,
- //success
- success: function (html) {
- //if process.php returned 1/true (send mail success)
- if (html) {
- //hide the form
- $(this).fadeOut('slow');
-
- //show the success message
- $(this).fadeIn('slow');
- }
- }
- });
- return false;
- });
- });
+ }
+ $('.pending').click(function() { ajaxToggle(this) });
+ $('.accepted').click(function() { ajaxToggle(this) });
+});
</script>
+<style type="text/css">
+ #pending_teams {
+ float:left;
+ width: 300px;
+ color: red;
+ }
+ #accepted_teams {
+ float:left;
+ width: 300px;
+ color: green;
+ }
+ #admin ul li ul {
+ display:none;
+ }
+ #error {
+ display:none;
+ color:red;
+ }
+</style>
<div id="admin">
<p>Click on the team name to accept or reject this team into your tournament...</p>
+ <div id="error">
+ </div>
<div id="pending_teams">
<ul>
<lh>Teams Pending</lh>
@@ -228,7 +222,7 @@
{% csrf_token %}
<input type="hidden" name="team_id" value="{{ team.id }}" />
<input type="hidden" name="tournament_id" value="{{ t.id }}" />
- <a class="pending">{{ team }}</a>
+ <a class="pending team">{{ team }}</a> <span onclick="$(this).find('ul').fadeToggle()">(+)</a>
<ul>
{% for member in team.members.all %}
<li>{{ member }}</li>
@@ -239,8 +233,6 @@
{% endfor %}
</ul>
</div>
-
-
<div id="accepted_teams">
<ul>
<lh>Teams accepted</lh>
@@ -250,7 +242,7 @@
{% csrf_token %}
<input type="hidden" name="team_id" value="{{ team.id }}" />
<input type="hidden" name="tournament_id" value="{{ t.id }}" />
- <a class="accepted">{{ team }}</a>
+ <a class="accepted team">{{ team }}</a> <span onclick="$(this).find('ul').toggle()">(+)</a>
<ul>
{% for member in team.members.all %}
<li>{{ member }}</li>
@@ -261,9 +253,6 @@
{% endfor %}
</ul>
</div>
-
-
-
<form method="post" action="{% url sc2tournament.views.tournament_start %}">.
{% csrf_token %}
<input type="hidden" name="value" value="yes" />
@@ -271,18 +260,12 @@
<input type="submit" value="Start the Tournament!" />
</form>
</div>
-
{% endifequal %}
-
-
{# Only show the tournament chart if the tournament hasn't started yet #}
{% ifnotequal t.status "org" %}
<div id="canvas"></div>
{% endifnotequal %}
-
-
-
-<div style="clear:both">Clear div</div>
+<div style="clear:both"></div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.