You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/21 00:41:25 UTC

svn commit: r1668177 - in /steve/trunk/pytest/www: cgi-bin/ htdocs/ htdocs/css/ htdocs/images/ htdocs/js/

Author: humbedooh
Date: Fri Mar 20 23:41:24 2015
New Revision: 1668177

URL: http://svn.apache.org/r1668177
Log:
- fix letter validation for STV
- Add STV HTML ballot
- Add STV voting scripts
- Add the images from the old STV page in trunk
- Allow for STV voting

Added:
    steve/trunk/pytest/www/htdocs/ballot_stv.html
    steve/trunk/pytest/www/htdocs/images/ballot_bg.png   (with props)
    steve/trunk/pytest/www/htdocs/images/dragleft.png   (with props)
    steve/trunk/pytest/www/htdocs/images/dragright.png   (with props)
    steve/trunk/pytest/www/htdocs/images/target.png   (with props)
    steve/trunk/pytest/www/htdocs/js/steve_stv.js
Modified:
    steve/trunk/pytest/www/cgi-bin/rest_voter.py
    steve/trunk/pytest/www/htdocs/css/steve_interactive.css
    steve/trunk/pytest/www/htdocs/js/steve_rest.js

Modified: steve/trunk/pytest/www/cgi-bin/rest_voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_voter.py?rev=1668177&r1=1668176&r2=1668177&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_voter.py Fri Mar 20 23:41:24 2015
@@ -147,7 +147,7 @@ if pathinfo:
                         invalid = False
                         letters = ['y','n','a']
                         if issuedata['type'].find("stv") == 0:
-                            letters = [chr(i) for i in range(ord('a'),ord('a') + len(issuedata['candidates'])-1)]
+                            letters = [chr(i) for i in range(ord('a'),ord('a') + len(issuedata['candidates']))]
                         for char in letters:
                             if vote.count(char) > 1:
                                 double = True
@@ -159,7 +159,7 @@ if pathinfo:
                         if double:
                             response.respond(500, {'message': "Vote contains duplicate characters"})
                         elif invalid:
-                            response.respond(500, {'message': "Vote contains invalid characters"})
+                            response.respond(500, {'message': "Vote contains invalid characters. Accepted are: %s" % ", ".join(letters)})
                         else:
                             votes = {}
                             if os.path.isfile(issuepath + ".votes"):

Added: steve/trunk/pytest/www/htdocs/ballot_stv.html
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/ballot_stv.html?rev=1668177&view=auto
==============================================================================
--- steve/trunk/pytest/www/htdocs/ballot_stv.html (added)
+++ steve/trunk/pytest/www/htdocs/ballot_stv.html Fri Mar 20 23:41:24 2015
@@ -0,0 +1,45 @@
+ <!DOCTYPE HTML>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="css/steve_interactive.css">
+<link rel="stylesheet" href="css/jquery-ui.css">
+<script src="js/steve_rest.js" type="text/javascript"></script>
+<script src="js/steve_stv.js" type="text/javascript"></script>
+<title>Apache STeVe: STV Voting</title>
+
+</head>
+<body onload="window.setTimeout(loadIssue, 500, null, null, null, displayIssueSTV);">
+    <div id="popups"></div>
+    <p style="text-align: center;">
+        <img src="/images/steve_logo.png"/>
+    </p>
+    <a href="javascript:void(location.href='election.html' + document.location.search);">Back to election front page</a>
+<div class="formbox" id="votebox">
+    <h2 id="title"></h2>
+<p>
+    This is a ballot with <span id="cnum">N</span> nominated members and
+    <span id="snum">N</span> board seats available.
+    The red line denotes the cutaway, should all your choices be voted in.
+    All the nominees are placed in random order on the canidate list.
+    If the canidate has prepared a statement, you can view it by clicking on the
+    statement link to the right of the candidate's name.
+</p>
+<p>
+    <b>How to vote:</b><br/>
+    Drag a candidate from the candidate list to the ballot box to place them in
+    the vote. You can rearrange your votes as you see fit, by dragging
+    candidates up/down on the ballot box list. You may place as many canidates
+    in the ballot box as you see fit. If you want to
+    remove a single candidate from your ballot box, simply drag the
+    canidate back to the list of remaining candidates to the left.
+</p>
+<div id="preloaderWrapper">
+    <img src="/images/steve_spinner.gif"/>
+    <div id="preloader">
+        Loading issues, please wait...
+    </div>
+</div>
+</div>
+</body>
+</html>
\ No newline at end of file

Modified: steve/trunk/pytest/www/htdocs/css/steve_interactive.css
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/css/steve_interactive.css?rev=1668177&r1=1668176&r2=1668177&view=diff
==============================================================================
--- steve/trunk/pytest/www/htdocs/css/steve_interactive.css (original)
+++ steve/trunk/pytest/www/htdocs/css/steve_interactive.css Fri Mar 20 23:41:24 2015
@@ -19,7 +19,7 @@
 body {
   /*color: #333333;*/
   font-family: "Trebuchet MS", "Helvetica", "Arial",  "Verdana", "sans-serif";
-  font-size: 85.5%;
+  font-size: 90%;
 }
 .wrap {
   padding: 40px;
@@ -220,7 +220,7 @@ pre {
     float: left;
 }
 #ballotbox {
-    width: 480px;
+    width: 360px;
     min-height: 100px;
     padding-top: 30px;
     padding-bottom: 10px;
@@ -242,7 +242,7 @@ pre {
 .ballotbox {
     border: 1px dotted #666;
     padding: 4px;
-    max-width: 340px;
+    max-width: 300px;
     min-height: 25px;
     cursor: move;
     cursor: grab;
@@ -267,7 +267,7 @@ pre {
 .ballotbox_clist {
     border: 1px dotted #666;
     padding: 4px;
-    max-width: 330px;
+    max-width: 300px;
     min-height: 25px;
     cursor: move;
     cursor: grab;
@@ -300,7 +300,7 @@ pre {
 .ballotSelected {
     border: 1px dotted #666;
     padding: 4px;
-    max-width: 340px;
+    max-width: 300px;
     min-height: 25px;
     cursor: move;
     cursor: grab;

Added: steve/trunk/pytest/www/htdocs/images/ballot_bg.png
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/images/ballot_bg.png?rev=1668177&view=auto
==============================================================================
Binary file - no diff available.

Propchange: steve/trunk/pytest/www/htdocs/images/ballot_bg.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: steve/trunk/pytest/www/htdocs/images/dragleft.png
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/images/dragleft.png?rev=1668177&view=auto
==============================================================================
Binary file - no diff available.

Propchange: steve/trunk/pytest/www/htdocs/images/dragleft.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: steve/trunk/pytest/www/htdocs/images/dragright.png
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/images/dragright.png?rev=1668177&view=auto
==============================================================================
Binary file - no diff available.

Propchange: steve/trunk/pytest/www/htdocs/images/dragright.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: steve/trunk/pytest/www/htdocs/images/target.png
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/images/target.png?rev=1668177&view=auto
==============================================================================
Binary file - no diff available.

Propchange: steve/trunk/pytest/www/htdocs/images/target.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: steve/trunk/pytest/www/htdocs/js/steve_rest.js
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/js/steve_rest.js?rev=1668177&r1=1668176&r2=1668177&view=diff
==============================================================================
--- steve/trunk/pytest/www/htdocs/js/steve_rest.js (original)
+++ steve/trunk/pytest/www/htdocs/js/steve_rest.js Fri Mar 20 23:41:24 2015
@@ -200,7 +200,7 @@ function loadElection(election, uid, cal
 	} else if (obj && (step % 2 == 1)) {
 		obj.innerHTML = "Ready..!"
 	}
-	if (step % 2 == 1) {
+	if (step % 2 == 1 && obj) {
 		obj.style.transform = "translate(0,0)"
 	} else if (obj) {
 		obj.style.transform = "translate(0,-500%)"

Added: steve/trunk/pytest/www/htdocs/js/steve_stv.js
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/htdocs/js/steve_stv.js?rev=1668177&view=auto
==============================================================================
--- steve/trunk/pytest/www/htdocs/js/steve_stv.js (added)
+++ steve/trunk/pytest/www/htdocs/js/steve_stv.js Fri Mar 20 23:41:24 2015
@@ -0,0 +1,612 @@
+/* WARNING: This script contains Voodoo! */
+/*
+#####
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#####
+*/
+
+var candidates = []
+var statements = []
+var ballotNames = []
+var ballotChars = []
+var chars;
+var fading = false
+var seats = 0;
+
+// Make copies for reset
+var candidates_copy = []
+var chars_copy = []
+
+var failover = null;
+
+
+
+// Set transfer data during drag'n'drop
+function dragVote(ev) {
+    ev.dataTransfer.setData("Text", ev.target.getAttribute("data"));
+    failover = ev.target.getAttribute("data")
+    if (ballotNames.indexOf(failover) == -1) {
+        document.getElementById('candidates').style.backgroundImage = "url(/images/dragright.png)"
+        document.getElementById('candidates').style.backgroundRepeat = "no-repeat"
+    } else {
+        document.getElementById('candidates').style.backgroundImage = "url(/images/dragleft.png)"
+        document.getElementById('candidates').style.backgroundRepeat = "no-repeat"
+    }
+}
+
+var source, dest
+
+function cancel(ev) {
+    ev.preventDefault()
+}
+
+function resetList() {
+    candidates = []
+    chars = []
+    for (i in candidates_copy) candidates.push(candidates_copy[i])
+    for (i in chars_copy) chars.push(chars_copy[i])
+    ballotNames = []
+    ballotChars = []
+    shuffleCandidates();
+    
+    drawCandidates()
+    fading = false
+    document.getElementById('ballot').innerHTML = '<img src="/images/target.png" style="margin-left: 100px;" ondrop="event.preventDefault(); dropCandidate(event);"/>';
+    drawList();
+}
+
+// Did we drop a vote on top of another?
+function dropVote(ev, parent) {
+    
+    //ev.preventDefault();
+    if (parent || fading) return;
+    
+    // Get who we dragged and who we dropped it on
+    source = ev.dataTransfer.getData("Text");
+    dest = parent ? ev.target.parentNode.getAttribute("data") : ev.target.getAttribute("data")
+    if (dest == "UPPER") { dest = ballotNames[0]}
+    if (dest == "LOWER") { dest = ballotNames[ballotNames.length -1] }
+    if (candidates.indexOf(dest) != -1) {
+        alert("Back to school!")
+    }
+    
+    // If we didn't drag this onto ourselves, let's initiate the fade-out and swap
+    if (source != dest) {
+        fadeOut(1, "ballot");
+    }
+    
+}
+
+function dropComplete(z) {
+    if (fading) {
+        return;
+    }
+    // Get array indices
+    var sid = ballotNames.indexOf(source);
+    var did = ballotNames.indexOf(dest)
+    
+    // Splice!
+    if (sid >= 0 && did >= 0) {
+        ballotNames.splice(did, 0, ballotNames.splice(sid, 1)[0])
+        ballotChars.splice(did, 0, ballotChars.splice(sid, 1)[0])
+    } else {
+        alert(source + ":" + dest)
+    }
+    //ev.preventDefault();
+    // Redraw and carry on
+    
+    drawList()
+    fadeIn(0, z, Math.random())
+}
+
+
+// A little shuffle, so we don't all get the same order at first
+function shuffleCandidates() {
+    for (var i = 0; i < candidates.length; i++) {
+        
+        // Pick some numbers
+        var sid = parseInt(Math.random()*candidates.length-0.01);
+        var did = parseInt(Math.random()*candidates.length-0.01);
+        
+        // Splice!
+        if (sid >= 0 && did >= 0) {
+            candidates.splice(did, 0, candidates.splice(sid, 1)[0])
+            chars.splice(did, 0, chars.splice(sid, 1)[0])
+        }
+    }
+}
+
+
+function drawCandidates() {
+    var box = document.getElementById('candidates')
+    box.innerHTML = "<h3>Candidates:</h3>"
+    for (i in candidates) {
+        var name = candidates[i]
+        var char = chars[i]
+        // Add element and set drag'n'drop + data
+        var outer = document.createElement('div')
+        var inner = document.createElement('span')
+        inner.style.fontFamily = "monospace"
+        inner.innerHTML = char + ": " + name;
+        inner.setAttribute("ondrop", "dropCandidate(event, true)")
+        outer.setAttribute("class", "ballotbox_clist")
+        outer.setAttribute("id", name)
+        outer.setAttribute("data", name)
+        inner.setAttribute("data", name)
+        outer.setAttribute("draggable", "true")
+        outer.setAttribute("ondragstart", "dragVote(event)")
+        outer.appendChild(inner)
+        outer.setAttribute("title", "Drag to move "  + name + " to the ballot box")
+        outer.setAttribute("ondrop", "dropCandidate(event, false)")
+        outer.setAttribute("ondragover", "event.preventDefault();")
+        outer.setAttribute("ondragend", "event.preventDefault();")
+        outer.setAttribute("ondragenter", "event.preventDefault();")
+        
+        // Does the candidate have a statement? if so, put it on there
+        if (statements[char]) {
+            var statement = document.createElement('div')
+            statement.setAttribute("class", "statement_marker")
+            statement.setAttribute("title", "Click to read " + name + "'s statement")
+            statement.innerHTML = "<a href='#statement_"+char+"'>Statement</a>"
+
+            outer.appendChild(statement)
+            
+            var popup = document.createElement("div")
+            popup.setAttribute("class", "modal")
+            popup.setAttribute("id", "statement_" + char)
+            popup.setAttribute("aria-hidden", "true")
+            
+            var popupd = document.createElement("div")
+            popupd.setAttribute("class", "modal-dialog")
+            popup.appendChild(popupd)
+            
+            var popuph = document.createElement("div")
+            popuph.setAttribute("class", "modal-header")
+            popuph.innerHTML = '<h2>Statement from ' + name + '</h2><a href="#close" class="btn-close" aria-hidden="true">×</a>'
+            
+            var popupb = document.createElement("div")
+            popupb.setAttribute("class", "modal-body")
+            popupb.innerHTML = '<pre>' + (statements[char] ? statements[char] : "This candidate has not prepared a statement") +'</pre>'
+            
+            var popupf = document.createElement("div")
+            popupf.setAttribute("class", "modal-footer")
+            popupf.innerHTML = '<a href="#close" class="btn">Close statement</a>'
+            
+            popupd.appendChild(popuph)
+            popupd.appendChild(popupb)
+            popupd.appendChild(popupf)
+            
+            document.getElementsByTagName('body')[0].appendChild(popup)
+        }/* else {
+            var statement = document.createElement('div')
+            statement.setAttribute("class", "statement_marker")
+            statement.style = "background: linear-gradient(to bottom, #e2e2e2 0%,#dbdbdb 50%,#d1d1d1 51%,#fefefe 100%) !important;"
+            statement.style.color = "#666";
+            statement.innerHTML = "<i>No statement</i>"
+
+            outer.appendChild(statement)
+        }*/
+        box.appendChild(outer)
+        
+    }
+}
+
+// Did we drop a vote on top of another?
+function dropCandidate(ev) {
+    
+    ev.preventDefault();
+    source = ev.dataTransfer.getData("Text");
+    dest = ev.target.getAttribute("data")
+    var z = 0;
+    if (dest == "UPPER") { dest = ballotNames[0]; z = 0}
+    if (dest == "LOWER") { dest = ballotNames[ballotNames.length -1]; z = 1;}
+    if (dest && candidates.indexOf(dest) != -1) {
+        return;
+    }
+    if (ballotNames.indexOf(source) == -1 && candidates.indexOf(source) != -1) {
+        var x = ballotNames.indexOf(dest)
+        x += z
+        if (ballotNames.indexOf(dest) != -1) {
+            ballotNames.splice(x,0,source);
+            ballotChars.splice(x,0,chars[candidates.indexOf(source)]);
+        } else {
+            ballotNames.push(source)
+            ballotChars.push(chars[candidates.indexOf(source)])
+        }
+        chars.splice(candidates.indexOf(source), 1)
+        candidates.splice(candidates.indexOf(source), 1)
+        
+        fadeIn(0, "ballot", Math.random())
+        //ev.preventDefault()
+        drawCandidates();
+        drawList();
+        
+    }
+    
+}
+
+// Did we drop a vote on top of another?
+function dropBack(ev) {
+    ev.preventDefault();
+    source = ev.dataTransfer.getData("Text");
+    dest = ev.target.getAttribute("data")
+    
+    if (dest == "UPPER") { dest = ballotNames[0]}
+    if (dest == "LOWER") { dest = ballotNames[ballotNames.length -1] }
+    
+    if ((!dest || candidates.indexOf(dest) != -1) && ballotNames.indexOf(source) != -1) {
+    
+        candidates.push(source)
+        chars.push(ballotChars[ballotNames.indexOf(source)])
+        ballotChars.splice(ballotNames.indexOf(source), 1)
+        ballotNames.splice(ballotNames.indexOf(source), 1)
+        drawList();
+        drawCandidates();
+        fadeIn(0, "candidates", Math.random())
+        
+    } else {
+        dest = null
+        source = null
+    }
+}
+
+function showLines(ev) {
+    
+    source = ev.dataTransfer.getData("Text");
+    source = source ? source : failover;
+    ev.preventDefault();
+    if (ev.target) {
+        var above = false
+        dest = ev.target.getAttribute("data")
+        var odest = dest;
+        var override = false
+        if (dest == "UPPER") { dest = ballotNames[0]; override = true; above = true;}
+        if (dest == "LOWER") { dest = ballotNames[ballotNames.length-1]; override = true; above= false; }
+        for (i=0;i< document.getElementById('ballot').childNodes.length;i++) {
+            var el = document.getElementById('ballot').childNodes[i]
+            el.style.borderTop = ""
+            el.style.borderBottom = ""
+        }
+        document.getElementById('UPPER').style.borderTop = "none"
+        document.getElementById('LOWER').style.borderBottom = "none"
+        document.getElementById('UPPER').style.borderBottom = "none"
+        document.getElementById('LOWER').style.borderTop = "none"
+        if (ballotNames.indexOf(dest) != -1 && dest != source) {
+            a = ballotNames.indexOf(source);
+            b = ballotNames.indexOf(dest);
+            
+            override = false
+            if (a != -1 && !override) {
+                
+                if (a > b) {
+                    above = true;
+                } else {
+                    above = false;
+                }
+            } else {
+                b--;
+                if (b == -1) {
+                    above = false;
+                } if (b == ballotNames.length-1) {
+                    above = false;
+                }
+            }
+            
+            if (((a == -1 || above == true) && odest != "UPPER") || odest == "LOWER") {
+                document.getElementById(odest).style.borderTop = "16px solid #0AF";
+            } else {
+                document.getElementById(odest).style.borderBottom = "16px solid #0AF";
+            }
+        }
+    }
+    
+}
+
+function insertAfter(newNode, referenceNode) {
+    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+}
+
+function insertBefore(newNode, referenceNode) {
+    referenceNode.parentNode.insertBefore(newNode, referenceNode);
+}
+
+function drawList() {
+    
+    
+    // Remove drag helper
+    document.getElementById('candidates').style.background = "";
+    
+    // Fetch ballot master and clear it
+    var ballot = document.getElementById('ballot')
+    ballot.innerHTML = ""
+    var s = 0;
+    
+    // For each nominee, do...
+    for (i in ballotNames) {
+        s++;
+        var el = ballotNames[i];
+        var outer = document.createElement('li');
+        // Set style
+        outer.setAttribute("class", "ballotbox")
+        
+        var no = document.createElement('div');
+        no.setAttribute("class", "ballotNumber")
+        no.innerHTML = (s)
+        
+        
+        // Above/below cutaway line? If so, draw it
+        if (s == seats) {
+            outer.style.borderBottom = "1px solid #A00"
+        }
+        if (s == seats+1) {
+            outer.style.borderTop = "1px solid #A00"
+        }
+        
+        // 'grey out' people below cutaway line
+        if (s > seats) {
+            outer.style.opacity = "0.75"
+        }
+        
+        // Add element and set drag'n'drop + data
+        var inner = document.createElement('span')
+        inner.style.left = "35px"
+        inner.style.maxWidth = "300px"
+        inner.style.maxHeight = "60px"
+        inner.style.overflow = "hidden"
+        inner.innerHTML = ballotChars[i] + ": " + el;
+        inner.setAttribute("ondrop", "dropVote(event, true)")
+        outer.setAttribute("id", el)
+        outer.setAttribute("data", el)
+        inner.setAttribute("data", el)
+        outer.setAttribute("draggable", "true")
+        outer.setAttribute("ondragstart", "dragVote(event)")
+        outer.setAttribute("ondragenter", "showLines(event)")
+        outer.appendChild(no)
+        outer.appendChild(inner)
+        outer.setAttribute("title", "Drag to move "  + el + " up or down on the list")
+        outer.setAttribute("ondrop", "dropVote(event, false)")
+        
+        
+        if (el == source) {
+            outer.style.opacity = "0"
+        }
+        
+        // Add to box
+        ballot.appendChild(outer)
+    }
+    
+    // Drop upper and lower filler boxes, so people can drag to the top/bottom of the list as well
+    if (!document.getElementById('UPPER')) {
+        var d = document.createElement('div');
+        d.setAttribute("class", "fillerbox")
+        d.setAttribute("data", "UPPER");
+        d.setAttribute("id", "UPPER");
+        d.setAttribute("ondragenter", "showLines(event)")
+        d.setAttribute("ondrop", "dropVote(event, false)")
+        insertBefore(d, ballot);
+        
+        var d = document.createElement('div');
+        d.setAttribute("class", "fillerbox")
+        d.setAttribute("id", "LOWER")
+        d.setAttribute("data", "LOWER");
+        d.setAttribute("ondrop", "dropVote(event, false)")
+        d.setAttribute("ondragenter", "showLines(event)")
+        insertAfter(d, ballot);
+    }
+    
+    // Clear any bad lines
+    document.getElementById('UPPER').style.borderTop = "none"
+    document.getElementById('LOWER').style.borderBottom = "none"
+    document.getElementById('UPPER').style.borderBottom = "none"
+    document.getElementById('LOWER').style.borderTop = "none"
+    
+}
+
+
+// Fade in/out maneuvres
+function fadeOut(x) {
+    if (source) {
+        if (!x) {
+            x = 1
+        }
+        if (fading) {
+            return;
+        }
+        x -= 0.1
+        document.getElementById(source).setAttribute("class", "ballotSelected")
+        document.getElementById(source).style.opacity = String(x)
+        if (x > 0) {
+            window.setTimeout(function() { fadeOut(x)}, 20)
+        } else {
+            dropComplete("candidates");
+        }
+    }   
+}
+
+var gz = 0;
+function fadeIn(x, y, z) {
+    if (source) {
+        if (x == 0) {
+            gz = z;
+        }
+        if (z != gz) {
+            return;
+        }
+        x += 0.1
+        if (x >= 1) {
+            x = 1
+        }
+        document.getElementById(source).style.opacity = String(x)
+        
+        
+        document.getElementById(source).setAttribute("class", "ballotSelected")
+        if (x < 1) {
+            fading = true
+            window.setTimeout(function() { fadeIn(x, y, z)}, 25)
+            
+        } else {
+             window.setTimeout(function() {fading = false }, 250)
+            if (y == "ballot") {
+                document.getElementById(source).setAttribute("class", "ballotbox")
+                
+            } else {
+                document.getElementById(source).setAttribute("class", "ballotbox_clist")
+                
+            }
+            source = null
+            drawList();
+            
+            
+        }
+    }   
+}
+
+var step = -1
+
+function loadIssue(election, issue, uid, callback) {
+	
+	var messages = ["Herding cats...", "Shaving yaks...", "Shooing some cows away...", "Fetching election data...", "Loading issues..."]
+	if (!election || !uid) {
+		var l = document.location.search.substr(1).split("/");
+		election = l[0];
+		issue = l.length > 1 ? l[l.length-2] : "";
+		uid = l.length > 2 ? l[l.length-1] : "";
+	}
+	if (step == -1) {
+		getJSON("/steve/voter/view/" + election + "/" + issue + "?uid=" + uid, [election, issue, uid], callback)
+	}
+	
+	var obj = document.getElementById('preloader');
+	step++;
+	if (!election_data && obj) {
+		if (step % 2 == 1) obj.innerHTML = messages[parseInt(Math.random()*messages.length-0.01)]
+	} else if (obj && (step % 2 == 1)) {
+		obj.innerHTML = "Ready..!"
+	}
+	if (step % 2 == 1) {
+		obj.style.transform = "translate(0,0)"
+	} else if (obj) {
+		obj.style.transform = "translate(0,-500%)"
+	}
+	if (!election_data|| (step % 2 == 0) ) {
+		window.setTimeout(loadElection, 750, election, uid, callback);
+	}
+}
+
+function displayIssueSTV(code, response, state) {
+    election_data = response
+    if (code != 200) {
+        document.getElementById('preloaderWrapper').innerHTML = "<h1>Could not load issue:</h1><h2>" + response.message + "</h2>";
+    } else {
+        candidates = []
+        statements = []
+        var m = response.issue.type.match(/(\d+)/);
+        if (m) {
+            seats = parseInt(m[1])
+        }
+        for (c in response.issue.candidates) {
+            var candidate = response.issue.candidates[c];
+            candidates.push(candidate.name);
+            statements.push(candidate.statement);
+        }
+        document.getElementById('cnum').innerHTML = candidates.length
+        document.getElementById('snum').innerHTML = seats
+        chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']  // Corresponding STV letters, in same order as nominees
+        while (chars.length > candidates.length) chars.splice(-1,1)
+        
+        for (i in candidates) candidates_copy.push(candidates[i])
+        for (i in chars) chars_copy.push(chars[i])
+
+
+        var obj = document.getElementById('preloaderWrapper')
+        obj.innerHTML = ""
+        obj.setAttribute("style", "min-width: 100%; min-height: 400px;")
+        obj.setAttribute("id", "ballotWrapper")
+        
+        
+        var c = document.createElement('div')
+        c.setAttribute("id", "candidates")
+        c.setAttribute("ondragover", "event.preventDefault();")
+        c.setAttribute("ondragenter", "event.preventDefault();")
+        c.setAttribute("ondragend", "event.preventDefault();")
+        c.setAttribute("ondrop", "dropBack(event);")
+        obj.appendChild(c)
+        
+        var b = document.createElement('div')
+        b.setAttribute("id", "ballotbox")
+        b.setAttribute("ondragover", "event.preventDefault();")
+        b.setAttribute("ondragenter", "event.preventDefault();")
+        b.setAttribute("ondragend", "event.preventDefault();")
+        b.setAttribute("ondrop", "dropCandidate(event);")
+        b.innerHTML = "<font color='red'><h3>Drag candidates over here:</h3</font>"
+        
+        var l = document.createElement('ol')
+        l.setAttribute("id", "ballot")
+        b.appendChild(l)
+        obj.appendChild(b)
+        l.innerHTML = "<img src='/images/target.png'/>"
+        
+        
+        var stvdiv = document.createElement('div')
+        stvdiv.setAttribute("id", "stv")
+        b.appendChild(stvdiv)
+        
+        var vote = document.createElement('input')
+        vote.setAttribute("type", "button")
+        vote.setAttribute("class", "btn-green")
+        vote.setAttribute("value", "Cast votes")
+        vote.setAttribute("onclick", "castVotes();")
+        
+        var reset = document.createElement('input')
+        reset.setAttribute("type", "button")
+        reset.setAttribute("class", "btn-red")
+        reset.setAttribute("value", "Reset")
+        reset.setAttribute("onclick", "resetList();")
+        
+        stvdiv.appendChild(vote)
+        stvdiv.appendChild(reset)
+        
+        shuffleCandidates();
+        drawCandidates();
+        
+        document.getElementById('title').innerHTML = response.issue.title
+        document.title = response.issue.title + " - Apache STeVe"
+        
+    }
+    
+}
+
+function castVotes(args) {
+    var l = document.location.search.substr(1).split("/");
+    election = l[0];
+    issue = l.length > 1 ? l[l.length-2] : "";
+    uid = l.length > 2 ? l[l.length-1] : "";
+	postREST("/steve/voter/vote/" + election + "/" + issue, {
+        uid: uid,
+        vote: ballotChars.join("")
+        },
+        undefined,
+        castVotesCallback,
+        null)
+}
+
+function castVotesCallback(code, response, state) {
+    if (code != 200) {
+        alert(response.message)
+    } else {
+        document.getElementById('votebox').innerHTML = "<h2>Your vote has been registered!</h2><p style='text-align:center;'><big>Should you reconsider, you can always reload this page and vote again.<br/><br/><a href=\"javascript:void(location.href='election.html'+document.location.search);\">Back to election front page</a></big></p>"
+    }
+}
\ No newline at end of file