<commit_before>---
layout: default
permalink: /election/ballot/
title: Election Ballot
published: true
---

<script src="http://ccss.carleton.ca/js/jquery.min.js"></script>

<script>

var BASE_URL = "https://ccss-election.herokuapp.com";

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$(function () {
  var params = getUrlVars();

  if (!params['x']) {
    $("#ballot_display").css("display", "none");
    $("#pre_ballot_error").css("background-color", "red");
    $("#pre_ballot_error").css("display", "");
    $("#pre_ballot_content").text("We couldn't process your ballot. Please make sure you came here through the SCS authentication system!");
  }
  else {
    $.post(BASE_URL + '/validate?x=' + params['x'],
      function (data) {
        if (!data["ok"]) {
          $("#ballot_display").css("display", "none");
          $("#pre_ballot_content").text(data["error"]);
          $("#pre_ballot_error").css("display", "");
          $("#pre_ballot_error").css("background-color", "red");
        }
      }
    );
  }

  $("#ballot").submit(function (e) {
      e.preventDefault();

      checked = $(".votebox:checked");

      // Verify there are two things in the list of candidates they
      // want to vote for.
      //if (checked.length != 2) {
      //  alert("Please select the correct amount of candidates (2)");
      //  return;
      //}

      ids = checked.map(function (index, checkbox) {
          return checkbox.id;
      });

      // We checked for x above
      var x = params['x'];

      for (var i = 0; i < ids.length; i++) {
        // Send to the server
        $.post(BASE_URL + '/vote?x=' + x,
          // We verified above that exactly two things are in the list.
          {"vote": ids[i]},
          function (data) {
            if (data["ok"]) {
              $("#ballot_display").css("display", "none");
              $("#message_container").css("background-color", "greenyellow");
              $("#message_container").text(data["ok"]);
              $("#message_container").css("display", "");
            }
            else {
              $("#message_container").css("background-color", "red");
              $("#message_container").text(data["error"]);
              $("#message_container").css("display", "");
            }
          });
      }
    });
});

</script>
<head><link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"></head>
<div id="ballot_display">
<div style="padding:20px; font-size:20px">
Welcome to the 2018 CCSS General Election!<br>Below you will find the ballot. You may place one vote for each position.
</div>

<div id="message_container" style="display:none;font-weight: bold">
You shouldn't see this message.
</div>

<style>
.candidate-description {<commit_msg>Take the message container out the ballot box<commit_after>---
layout: default
permalink: /election/ballot/
title: Election Ballot
published: true
---

<script src="http://ccss.carleton.ca/js/jquery.min.js"></script>

<script>

var BASE_URL = "https://ccss-election.herokuapp.com";

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$(function () {
  var params = getUrlVars();

  if (!params['x']) {
    $("#ballot_display").css("display", "none");
    $("#pre_ballot_error").css("background-color", "red");
    $("#pre_ballot_error").css("display", "");
    $("#pre_ballot_content").text("We couldn't process your ballot. Please make sure you came here through the SCS authentication system!");
  }
  else {
    $.post(BASE_URL + '/validate?x=' + params['x'],
      function (data) {
        if (!data["ok"]) {
          $("#ballot_display").css("display", "none");
          $("#pre_ballot_content").text(data["error"]);
          $("#pre_ballot_error").css("display", "");
          $("#pre_ballot_error").css("background-color", "red");
        }
      }
    );
  }

  $("#ballot").submit(function (e) {
      e.preventDefault();

      checked = $(".votebox:checked");

      // Verify there are two things in the list of candidates they
      // want to vote for.
      //if (checked.length != 2) {
      //  alert("Please select the correct amount of candidates (2)");
      //  return;
      //}

      ids = checked.map(function (index, checkbox) {
          return checkbox.id;
      });

      // We checked for x above
      var x = params['x'];

      for (var i = 0; i < ids.length; i++) {
        // Send to the server
        $.post(BASE_URL + '/vote?x=' + x,
          // We verified above that exactly two things are in the list.
          {"vote": ids[i]},
          function (data) {
            if (data["ok"]) {
              $("#ballot_display").css("display", "none");
              $("#message_container").css("background-color", "greenyellow");
              $("#message_container").text(data["ok"]);
              $("#message_container").css("display", "");
            }
            else {
              $("#message_container").css("background-color", "red");
              $("#message_container").text(data["error"]);
              $("#message_container").css("display", "");
            }
          });
      }
    });
});

</script>
<head><link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"></head>

<div id="message_container" style="display:none;font-weight: bold">
You shouldn't see this message.
</div>
<div id="ballot_display">
<div style="padding:20px; font-size:20px">
Welcome to the 2018 CCSS General Election!<br>Below you will find the ballot. You may place one vote for each position.
</div>

<style>
.candidate-description {
{'fraction_non_alphanumeric': 0.18878205128205128, 'fraction_numerical': 0.005128205128205128, 'mean_word_length': 2.624274099883856, 'pattern_counts': {'":': 2, '<': 35, '<?xml version=': 0, '>': 31, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2065480', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1897, 'n_words': 451}