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/10/12 11:55:10 UTC

svn commit: r1708070 - in /steve/trunk/pysteve/www: cgi-bin/rest_admin.py htdocs/js/steve_rest.js htdocs/js/steve_stv.js

Author: humbedooh
Date: Mon Oct 12 09:55:10 2015
New Revision: 1708070

URL: http://svn.apache.org/viewvc?rev=1708070&view=rev
Log:
Add the option to supply nomination and seconding statements for candidates in STV mode.

Modified:
    steve/trunk/pysteve/www/cgi-bin/rest_admin.py
    steve/trunk/pysteve/www/htdocs/js/steve_rest.js
    steve/trunk/pysteve/www/htdocs/js/steve_stv.js

Modified: steve/trunk/pysteve/www/cgi-bin/rest_admin.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/rest_admin.py?rev=1708070&r1=1708069&r2=1708070&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/rest_admin.py Mon Oct 12 09:55:10 2015
@@ -230,8 +230,9 @@ else:
                         else:
                             try:
                                 issuedata = election.getIssue(electionID, issue)
-                                fields = ['title','description','type','statements','candidates','seconds','nominatedby']
+                                fields = ['title','description','type','statements','candidates','seconds','nominatedby', 'seconds_txt']
                                 statements = []
+                                seconds = []
                                 for field in fields:
                                     val = form.getvalue(field)
                                     if val:
@@ -243,7 +244,11 @@ else:
                                             val = []
                                             z = 0
                                             for entry in xval:
-                                                val.append({'name': entry.strip(), 'statement': statements[z] if len(statements) > z else ""})
+                                                val.append({
+                                                    'name': entry.strip(),
+                                                    'statement': statements[z] if len(statements) > z else "",
+                                                    'seconds_txt': seconds[z] if len(seconds) > z else ""
+                                                    })
                                                 z += 1
                                         if field == "statements":
                                             try:
@@ -253,8 +258,17 @@ else:
                                             val = []
                                             for entry in xval:
                                                 statements.append(entry)
+                                        if field == "seconds_txt":
+                                            try:
+                                                xval = json.loads(val)
+                                            except:
+                                                xval = val.split("\n")
+                                            val = []
+                                            for entry in xval:
+                                                seconds.append(entry)
                                         if field == "seconds":
                                             val = [x.strip() for x in val.split("\n")]
+                                        
                                             
                                         # HACK: If field  parsing is outsourced, let's do that instead (primarily for COP)
                                         voteType = election.getVoteType(issuedata)

Modified: steve/trunk/pysteve/www/htdocs/js/steve_rest.js
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/htdocs/js/steve_rest.js?rev=1708070&r1=1708069&r2=1708070&view=diff
==============================================================================
--- steve/trunk/pysteve/www/htdocs/js/steve_rest.js (original)
+++ steve/trunk/pysteve/www/htdocs/js/steve_rest.js Mon Oct 12 09:55:10 2015
@@ -340,12 +340,15 @@ function saveSTV() {
 	
 	candidates = []
 	statements = []
+	seconds = []
 	for (var i = 0; i < 256; i++) {
 		if (document.getElementById('name_' + i)) {
 			var name = document.getElementById('name_' + i).value;
 			var statement = document.getElementById('statement_' + i).value;
+			var seconds_txt = document.getElementById('seconds_txt_' + i).value;
 			candidates.push(name)
 			statements.push(statement ? statement : "")
+			seconds.push(seconds_txt ? seconds_txt : "")
 		}
 	}
 	
@@ -353,7 +356,8 @@ function saveSTV() {
 		title: title,
 		description: description,
 		candidates: JSON.stringify(candidates),
-		statements: JSON.stringify(statements)
+		statements: JSON.stringify(statements),
+		seconds_txt: JSON.stringify(seconds)
 	},
 	undefined,
 	saveCallback,
@@ -387,11 +391,13 @@ function renderEditCandidates() {
 		var candidate = edit_i.candidates[c]
 		var name = candidate.name
 		var statement = candidate.statement
+		var seconds = candidate.seconds_txt
 		var h = document.createElement('h4')
 		h.innerHTML = name + " &nbsp; - &nbsp <a href='javascript:void(removeEditCandidate(\"" + name + "\"));'>Delete</a>"
 		obj.appendChild(h)
 		obj.appendChild(keyvaluepair("name_" + c, "Name:", "text", name, false, "edit_i.candidates[" + c + "].name = this.value"))
-		obj.appendChild(keyvaluepair("statement_" + c, "Statement/seconds:", "textarea", statement ? statement : "", false, "edit_i.candidates[" + c + "].statement = this.value"))
+		obj.appendChild(keyvaluepair("statement_" + c, "Statement:", "textarea", statement ? statement : "", false, "edit_i.candidates[" + c + "].statement = this.value"))
+		obj.appendChild(keyvaluepair("seconds_txt_" + c, "Nomination/Seconds:", "textarea", seconds ? seconds : "", false, "edit_i.candidates[" + c + "].seconds_txt = this.value"))
 		obj.appendChild(document.createElement('hr'))
 	}
 }

Modified: steve/trunk/pysteve/www/htdocs/js/steve_stv.js
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/htdocs/js/steve_stv.js?rev=1708070&r1=1708069&r2=1708070&view=diff
==============================================================================
--- steve/trunk/pysteve/www/htdocs/js/steve_stv.js (original)
+++ steve/trunk/pysteve/www/htdocs/js/steve_stv.js Mon Oct 12 09:55:10 2015
@@ -18,6 +18,7 @@
 
 var candidates = []
 var statements = []
+var seconds = []
 var ballotNames = []
 var ballotChars = []
 var chars;
@@ -174,7 +175,7 @@ function drawCandidates() {
             
             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>'
+            popuph.innerHTML = '<h2>Statement from ' + name + '</h2><a href="#close" class="btn-close" aria-hidden="true">&#00D7;</a>'
             
             var popupb = document.createElement("div")
             popupb.setAttribute("class", "modal-body")
@@ -189,15 +190,44 @@ function drawCandidates() {
             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>"
+        }
+        
+        // Does the candidate have a nomination and/or seconds? if so, put it on there
+        if (seconds[char]) {
+            var seconds = document.createElement('div')
+            seconds.setAttribute("class", "statement_marker")
+            seconds.setAttribute("title", "Click to read " + name + "'s nomination and/or seconds")
+            seconds.innerHTML = "<a href='#statement_"+char+"'>2nds</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">&#00D7;</a>'
+            
+            var popupb = document.createElement("div")
+            popupb.setAttribute("class", "modal-body")
+            popupb.innerHTML = '<pre>' + (seconds[char] ? seconds[char] : "This candidate does not have a nomination statement") +'</pre>'
+            
+            var popupf = document.createElement("div")
+            popupf.setAttribute("class", "modal-footer")
+            popupf.innerHTML = '<a href="#close" class="btn">Close window</a>'
+            
+            popupd.appendChild(popuph)
+            popupd.appendChild(popupb)
+            popupd.appendChild(popupf)
+            
+            document.getElementsByTagName('body')[0].appendChild(popup)
+        }
         box.appendChild(outer)
         
     }
@@ -526,6 +556,7 @@ function displayIssueSTV(code, response,
             var candidate = response.issue.candidates[c];
             candidates.push(candidate.name);
             statements[chars[c]] = candidate.statement;
+            seconds[chars[c]] = candidate.seconds_txt; // don't use .seconds, that's for arrays!
         }
         document.getElementById('cnum').innerHTML = candidates.length
         document.getElementById('snum').innerHTML = seats