summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-23 13:07:25 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-23 13:07:25 -0400
commit1ea3366c70ad87f2c0d3fa3ae3a56f27b691f696 (patch)
tree5446ee7a134b0aab31d4a232008f96acd88a291a
parent395a12042bbe9c4eeca60e41c75004c3bdad4e87 (diff)
clean up the javascript everywhere
-rw-r--r--app/assets/javascripts/ajax.js19
-rw-r--r--app/assets/javascripts/application.js3
-rw-r--r--app/assets/javascripts/matches_show.js.coffee2
-rw-r--r--app/assets/javascripts/tournaments_show.js.coffee30
-rw-r--r--app/assets/stylesheets/custom.css.scss12
-rw-r--r--app/assets/stylesheets/search.css.scss11
-rw-r--r--app/views/layouts/application.html.erb7
-rw-r--r--app/views/matches/show.html.erb28
-rw-r--r--app/views/search/go.html.erb23
-rw-r--r--app/views/tournaments/show.html.erb31
10 files changed, 69 insertions, 97 deletions
diff --git a/app/assets/javascripts/ajax.js b/app/assets/javascripts/ajax.js
deleted file mode 100644
index 040c100..0000000
--- a/app/assets/javascripts/ajax.js
+++ /dev/null
@@ -1,19 +0,0 @@
-function populate() {
- //populate optionArray
- //make a form element
- var e = document.getElementById("tournament_id");
- var gameType = e.options[e.selectedIndex].text;
- if (gameType != "Select a Game Type") {
- alert(gameType + " was Selected!");
- //populate optionArray via AJAX
- //select * from tournament_settings where gametype = GameType
- for(var option in optionArray){
- //identify the number of
- ;
- }
- };
-
-//$.ajax(url: "/selected").done (html) -> $("#ajax-form").append html
-
-}
-
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index cb6edeb..e9430a3 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -13,7 +13,8 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
-//= require_tree .
//= require 'drag.js'
//= require 'dragsort.js'
//= require 'coordinates.js'
+//
+//= require_tree ./common
diff --git a/app/assets/javascripts/matches_show.js.coffee b/app/assets/javascripts/matches_show.js.coffee
new file mode 100644
index 0000000..2609a69
--- /dev/null
+++ b/app/assets/javascripts/matches_show.js.coffee
@@ -0,0 +1,2 @@
+window.onload = ->
+ BetterDragSort.makeListSortable(document.getElementById("boxes"));
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 + "<li><span class=\"black\">" + player["user_name"] + "</span></li>"
+ $("#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
diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss
index d7f1698..2fecd13 100644
--- a/app/assets/stylesheets/custom.css.scss
+++ b/app/assets/stylesheets/custom.css.scss
@@ -74,4 +74,14 @@ p.errors {
font-size: 12px;
list-style: square;
}
-} \ No newline at end of file
+}
+
+// Limitation: Only one box can be expanded at a time
+.collapsible {
+ .collapsed { display: block; }
+ .expanded { display: none; }
+ &:target {
+ .collapsed { display: none; }
+ .expanded { display: block; }
+ }
+}
diff --git a/app/assets/stylesheets/search.css.scss b/app/assets/stylesheets/search.css.scss
index 69cd1ad..22fd394 100644
--- a/app/assets/stylesheets/search.css.scss
+++ b/app/assets/stylesheets/search.css.scss
@@ -1,14 +1,3 @@
// Place all the styles related to the search controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
-
-#search-down {
- text-align: center;
- cursor: pointer;
- text-decoration: underline;
-}
-
-
-#advanced-search {
- display: none;
-} \ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index eca33b8..116554b 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -4,15 +4,12 @@
<title>Leaguer</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
+ <%= javascript_include_tag "#{params[:controller]}", "data-turbolinks-track" => true %>%>
+ <%= javascript_include_tag "#{params[:controller]}_#{params[:action]}", "data-turbolinks-track" => true %>%>
<%= csrf_meta_tags %>
<%= yield :head %>
</head>
<body>
-<script>
- window.onload = function() {
- BetterDragSort.makeListSortable(document.getElementById("boxes"));
- };
-</script>
<header>
<nav>
<%# This is the logo %>
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index a1d82a3..a3ebec2 100644
--- a/app/views/matches/show.html.erb
+++ b/app/views/matches/show.html.erb
@@ -1,3 +1,17 @@
+<script type="text/javascript">
+function score_peers() {
+ //get each player in order and assign score here!
+ var $lisp = $('ol#boxes');
+ var comma = ","
+ for(var i=0; i < $lisp.length; i++) {
+ if ( i == lisp.length-1) {
+ comma = "";
+ }
+ $('review_action').value += $('ol#boxes:eq(' + i + ')').text() + comma;
+ }
+}
+</script>
+
<p>
<strong>Status:</strong>
<%= @match.status %>
@@ -112,17 +126,3 @@
<% end # case %>
<% end # form %>
</div>
-
-<script type="text/javascript">
-function score_peers() {
- //get each player in order and assign score here!
- var $lisp = $('ol#boxes');
- var comma = ","
- for(var i=0; i < $lisp.length; i++) {
- if ( i == lisp.length-1) {
- comma = "";
- }
- $('review_action').value += $('ol#boxes:eq(' + i + ')').text() + comma;
- }
-}
-</script>
diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb
index 6e48b07..d2bf8f3 100644
--- a/app/views/search/go.html.erb
+++ b/app/views/search/go.html.erb
@@ -1,6 +1,11 @@
-<h5 id="search-down">&#x25B2; Advanced Search &#x25B2;</h5>
-<div id="advanced-search">
- <p> This is where the search will go </p>
+<div id="advanced_search" class="collapsible">
+ <div class="collapsed">
+ <h5><a href="#advanced_search">Advanced Search [show]</a></h5>
+ </div>
+ <div class="expanded">
+ <h5><a href="#collapse">Advanced Search [hide]</a></h5>
+ <p>This is where the advancedsearch will go.</p>
+ </div>
</div>
<%# Show search results if a query was not nill %>
@@ -26,15 +31,3 @@
<% end %>
<% end %>
-
-<script type="text/javascript" language="javascript">
-
- $(document).ready(function() {
-
- $("#search-down").click(function(){
- $("#search-down").text("▼ Advanced Search ▼").html();
- $("#advanced-search").slideDown( 'slow');
- });
-
- });
-</script> \ No newline at end of file
diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb
index a4983f7..3f8552e 100644
--- a/app/views/tournaments/show.html.erb
+++ b/app/views/tournaments/show.html.erb
@@ -106,34 +106,3 @@
<%end %>
</div>
-
-<script>
-function donehandle( tournament ) {
- if ( console && console.log ) {
- var here = tournament["players"].length;
- var needed = (tournament["min_teams_per_match"] * tournament["min_players_per_team"]);
- var pct_complete = here / needed;
- $("#prog-bar").width( (pct_complete * 100) +"%");
- $("#players-needed").text(here + " " + (here==1?"player has":"players have") + " signed up. " + needed + " players needed. ");
- players = "";
-
- //creates the present user list
- for (var i = 0; i < tournament["players"].length; i++) {
- players = players+"<li><span class=\"black\">"+tournament["players"][i]["user_name"]+"</span></li>"
- }
-
- //updates the user list
- $("#tournament-users").html(players);
-
- //if there are enough players to start, enable the button, else disable it.
- $("input[value=\"Start Tournament\"]").prop('disabled', (pct_complete >= 1)? false : true);
-
- if (tournament["status"] == 1)
- window.location.reload(true);
- }
- setTimeout(function(){$.ajax({url: "<%= url_for @tournament %>.json"}).done(donehandle)}, 2000);
-}
-
-$.ajax({url: "<%= url_for @tournament %>.json"})
- .done(donehandle);
-</script>