liquid_feedback_frontend
annotate static/js/voting.js @ 5:afd9f769c7ae
Version beta1
Final voting with Schulze-Method is now possible
Many bug fixes and code cleanup
Registration with invite codes
More sort and filter options
Seperated display of "supporters" and "potential supporters"
Optical changes
Flood limit / initiative contigent is now checked by frontend
Neccessary changes to access core beta11
Final voting with Schulze-Method is now possible
Many bug fixes and code cleanup
Registration with invite codes
More sort and filter options
Seperated display of "supporters" and "potential supporters"
Optical changes
Flood limit / initiative contigent is now checked by frontend
Neccessary changes to access core beta11
author | bsw/jbe |
---|---|
date | Fri Dec 25 12:00:00 2009 +0100 (2009-12-25) |
parents | |
children | 00d1004545f1 |
rev | line source |
---|---|
bsw/jbe@5 | 1 function setCategoryHeadings() { |
bsw/jbe@5 | 2 var approvalCount = 0; |
bsw/jbe@5 | 3 var disapprovalCount = 0; |
bsw/jbe@5 | 4 var sections = document.getElementById("voting").childNodes; |
bsw/jbe@5 | 5 for (var i=0; i<sections.length; i++) { |
bsw/jbe@5 | 6 var section = sections[i]; |
bsw/jbe@5 | 7 if (section.className == "approval") approvalCount++; |
bsw/jbe@5 | 8 if (section.className == "disapproval") disapprovalCount++; |
bsw/jbe@5 | 9 } |
bsw/jbe@5 | 10 var approvalIndex = 0; |
bsw/jbe@5 | 11 var disapprovalIndex = 0; |
bsw/jbe@5 | 12 for (var i=0; i<sections.length; i++) { |
bsw/jbe@5 | 13 var section = sections[i]; |
bsw/jbe@5 | 14 if ( |
bsw/jbe@5 | 15 section.className == "approval" || |
bsw/jbe@5 | 16 section.className == "abstention" || |
bsw/jbe@5 | 17 section.className == "disapproval" |
bsw/jbe@5 | 18 ) { |
bsw/jbe@5 | 19 var setHeading = function(heading) { |
bsw/jbe@5 | 20 var headingNodes = section.childNodes; |
bsw/jbe@5 | 21 for (var j=0; j<headingNodes.length; j++) { |
bsw/jbe@5 | 22 var headingNode = headingNodes[j]; |
bsw/jbe@5 | 23 if (headingNode.className == "cathead") { |
bsw/jbe@5 | 24 headingNode.textContent = heading; |
bsw/jbe@5 | 25 } |
bsw/jbe@5 | 26 } |
bsw/jbe@5 | 27 } |
bsw/jbe@5 | 28 var count = 0; |
bsw/jbe@5 | 29 var entries = section.childNodes; |
bsw/jbe@5 | 30 for (var j=0; j<entries.length; j++) { |
bsw/jbe@5 | 31 var entry = entries[j]; |
bsw/jbe@5 | 32 if (entry.className == "movable") count++; |
bsw/jbe@5 | 33 } |
bsw/jbe@5 | 34 if (section.className == "approval") { |
bsw/jbe@5 | 35 if (approvalCount > 1) { |
bsw/jbe@5 | 36 if (approvalIndex == 0) { |
bsw/jbe@5 | 37 if (count == 1) setHeading("Zustimmung (Erstwunsch)"); |
bsw/jbe@5 | 38 else setHeading("Zustimmung (Erstwünsche)"); |
bsw/jbe@5 | 39 } else if (approvalIndex == 1) { |
bsw/jbe@5 | 40 if (count == 1) setHeading("Zustimmung (Zweitwunsch)"); |
bsw/jbe@5 | 41 else setHeading("Zustimmung (Zweitwünsche)"); |
bsw/jbe@5 | 42 } else if (approvalIndex == 2) { |
bsw/jbe@5 | 43 if (count == 1) setHeading("Zustimmung (Drittwunsch)"); |
bsw/jbe@5 | 44 else setHeading("Zustimmung (Drittwünsche)"); |
bsw/jbe@5 | 45 } else { |
bsw/jbe@5 | 46 if (count == 1) setHeading("Zustimmung (" + (approvalIndex+1) + ".-Wunsch)"); |
bsw/jbe@5 | 47 else setHeading("Zustimmung (" + (approvalIndex+1) + ".-Wünsche)"); |
bsw/jbe@5 | 48 } |
bsw/jbe@5 | 49 } else { |
bsw/jbe@5 | 50 setHeading("Zustimmung"); |
bsw/jbe@5 | 51 } |
bsw/jbe@5 | 52 approvalIndex++; |
bsw/jbe@5 | 53 } else if (section.className == "abstention") { |
bsw/jbe@5 | 54 setHeading("Enthaltung"); |
bsw/jbe@5 | 55 } else if (section.className == "disapproval") { |
bsw/jbe@5 | 56 if (disapprovalCount > disapprovalIndex + 2) { |
bsw/jbe@5 | 57 setHeading("Ablehnung (jedoch Bevorzugung gegenüber unteren Ablehnungsblöcken)") |
bsw/jbe@5 | 58 } else if (disapprovalCount == 2 && disapprovalIndex == 0) { |
bsw/jbe@5 | 59 setHeading("Ablehnung (jedoch Bevorzugung gegenüber unterem Ablehnungsblock)") |
bsw/jbe@5 | 60 } else if (disapprovalIndex == disapprovalCount - 2) { |
bsw/jbe@5 | 61 setHeading("Ablehnung (jedoch Bevorzugung gegenüber letztem Ablehnungsblock)") |
bsw/jbe@5 | 62 } else { |
bsw/jbe@5 | 63 setHeading("Ablehnung"); |
bsw/jbe@5 | 64 } |
bsw/jbe@5 | 65 disapprovalIndex++; |
bsw/jbe@5 | 66 } |
bsw/jbe@5 | 67 } |
bsw/jbe@5 | 68 } |
bsw/jbe@5 | 69 } |
bsw/jbe@5 | 70 function elementDropped(element, dropX, dropY) { |
bsw/jbe@5 | 71 var oldParent = element.parentNode; |
bsw/jbe@5 | 72 var centerY = dropY + element.clientHeight / 2 |
bsw/jbe@5 | 73 var approvalCount = 0; |
bsw/jbe@5 | 74 var disapprovalCount = 0; |
bsw/jbe@5 | 75 var mainDiv = document.getElementById("voting"); |
bsw/jbe@5 | 76 var sections = mainDiv.childNodes; |
bsw/jbe@5 | 77 for (var i=0; i<sections.length; i++) { |
bsw/jbe@5 | 78 var section = sections[i]; |
bsw/jbe@5 | 79 if (section.className == "approval") approvalCount++; |
bsw/jbe@5 | 80 if (section.className == "disapproval") disapprovalCount++; |
bsw/jbe@5 | 81 } |
bsw/jbe@5 | 82 for (var i=0; i<sections.length; i++) { |
bsw/jbe@5 | 83 var section = sections[i]; |
bsw/jbe@5 | 84 if ( |
bsw/jbe@5 | 85 section.className == "approval" || |
bsw/jbe@5 | 86 section.className == "abstention" || |
bsw/jbe@5 | 87 section.className == "disapproval" |
bsw/jbe@5 | 88 ) { |
bsw/jbe@5 | 89 if ( |
bsw/jbe@5 | 90 centerY >= section.offsetTop && |
bsw/jbe@5 | 91 centerY < section.offsetTop + section.clientHeight |
bsw/jbe@5 | 92 ) { |
bsw/jbe@5 | 93 var entries = section.childNodes; |
bsw/jbe@5 | 94 for (var j=0; j<entries.length; j++) { |
bsw/jbe@5 | 95 var entry = entries[j]; |
bsw/jbe@5 | 96 if (entry.className == "movable") { |
bsw/jbe@5 | 97 if (centerY < entry.offsetTop + entry.clientHeight / 2) { |
bsw/jbe@5 | 98 if (element != entry) { |
bsw/jbe@5 | 99 oldParent.removeChild(element); |
bsw/jbe@5 | 100 section.insertBefore(element, entry); |
bsw/jbe@5 | 101 } |
bsw/jbe@5 | 102 break; |
bsw/jbe@5 | 103 } |
bsw/jbe@5 | 104 } |
bsw/jbe@5 | 105 } |
bsw/jbe@5 | 106 if (j == entries.length) { |
bsw/jbe@5 | 107 oldParent.removeChild(element); |
bsw/jbe@5 | 108 section.appendChild(element); |
bsw/jbe@5 | 109 } |
bsw/jbe@5 | 110 break; |
bsw/jbe@5 | 111 } |
bsw/jbe@5 | 112 } |
bsw/jbe@5 | 113 } |
bsw/jbe@5 | 114 if (i == sections.length) { |
bsw/jbe@5 | 115 var newSection = document.createElement("div"); |
bsw/jbe@5 | 116 var cathead = document.createElement("div"); |
bsw/jbe@5 | 117 cathead.setAttribute("class", "cathead"); |
bsw/jbe@5 | 118 newSection.appendChild(cathead); |
bsw/jbe@5 | 119 for (var i=0; i<sections.length; i++) { |
bsw/jbe@5 | 120 var section = sections[i]; |
bsw/jbe@5 | 121 if ( |
bsw/jbe@5 | 122 section.className == "approval" || |
bsw/jbe@5 | 123 section.className == "abstention" || |
bsw/jbe@5 | 124 section.className == "disapproval" |
bsw/jbe@5 | 125 ) { |
bsw/jbe@5 | 126 if (centerY < section.offsetTop + section.clientHeight / 2) { |
bsw/jbe@5 | 127 if (section.className == "disapproval") { |
bsw/jbe@5 | 128 newSection.setAttribute("class", "disapproval"); |
bsw/jbe@5 | 129 disapprovalCount++; |
bsw/jbe@5 | 130 } else { |
bsw/jbe@5 | 131 newSection.setAttribute("class", "approval"); |
bsw/jbe@5 | 132 approvalCount++; |
bsw/jbe@5 | 133 } |
bsw/jbe@5 | 134 mainDiv.insertBefore(newSection, section); |
bsw/jbe@5 | 135 break; |
bsw/jbe@5 | 136 } |
bsw/jbe@5 | 137 } |
bsw/jbe@5 | 138 } |
bsw/jbe@5 | 139 if (i == sections.length) { |
bsw/jbe@5 | 140 newSection.setAttribute("class", "disapproval"); |
bsw/jbe@5 | 141 disapprovalCount++; |
bsw/jbe@5 | 142 mainDiv.appendChild(newSection); |
bsw/jbe@5 | 143 } |
bsw/jbe@5 | 144 oldParent.removeChild(element); |
bsw/jbe@5 | 145 newSection.appendChild(element); |
bsw/jbe@5 | 146 } |
bsw/jbe@5 | 147 sections = mainDiv.childNodes; |
bsw/jbe@5 | 148 for (i=0; i<sections.length; i++) { |
bsw/jbe@5 | 149 var section = sections[i]; |
bsw/jbe@5 | 150 if ( |
bsw/jbe@5 | 151 (section.className == "approval" && approvalCount > 1) || |
bsw/jbe@5 | 152 (section.className == "disapproval" && disapprovalCount > 1) |
bsw/jbe@5 | 153 ) { |
bsw/jbe@5 | 154 var entries = section.childNodes; |
bsw/jbe@5 | 155 for (var j=0; j<entries.length; j++) { |
bsw/jbe@5 | 156 var entry = entries[j]; |
bsw/jbe@5 | 157 if (entry.className == "movable") break; |
bsw/jbe@5 | 158 } |
bsw/jbe@5 | 159 if (j == entries.length) { |
bsw/jbe@5 | 160 section.parentNode.removeChild(section); |
bsw/jbe@5 | 161 } |
bsw/jbe@5 | 162 } |
bsw/jbe@5 | 163 } |
bsw/jbe@5 | 164 setCategoryHeadings(); |
bsw/jbe@5 | 165 } |
bsw/jbe@5 | 166 window.addEventListener("load", function(event) { |
bsw/jbe@5 | 167 setCategoryHeadings(); |
bsw/jbe@5 | 168 var mainDiv = document.getElementById("voting"); |
bsw/jbe@5 | 169 var form = document.getElementById("voting_form"); |
bsw/jbe@5 | 170 var elements = document.getElementsByTagName("input"); |
bsw/jbe@5 | 171 for (var i=0; i<elements.length; i++) { |
bsw/jbe@5 | 172 var element = elements[i]; |
bsw/jbe@5 | 173 if (element.className == "voting_done") { |
bsw/jbe@5 | 174 element.addEventListener("click", function(event) { |
bsw/jbe@5 | 175 var scoringString = ""; |
bsw/jbe@5 | 176 var approvalCount = 0; |
bsw/jbe@5 | 177 var disapprovalCount = 0; |
bsw/jbe@5 | 178 var sections = mainDiv.childNodes; |
bsw/jbe@5 | 179 for (var j=0; j<sections.length; j++) { |
bsw/jbe@5 | 180 var section = sections[j]; |
bsw/jbe@5 | 181 if (section.className == "approval") approvalCount++; |
bsw/jbe@5 | 182 if (section.className == "disapproval") disapprovalCount++; |
bsw/jbe@5 | 183 } |
bsw/jbe@5 | 184 var approvalIndex = 0; |
bsw/jbe@5 | 185 var disapprovalIndex = 0; |
bsw/jbe@5 | 186 for (var j=0; j<sections.length; j++) { |
bsw/jbe@5 | 187 var section = sections[j]; |
bsw/jbe@5 | 188 if ( |
bsw/jbe@5 | 189 section.className == "approval" || |
bsw/jbe@5 | 190 section.className == "abstention" || |
bsw/jbe@5 | 191 section.className == "disapproval" |
bsw/jbe@5 | 192 ) { |
bsw/jbe@5 | 193 var score; |
bsw/jbe@5 | 194 if (section.className == "approval") { |
bsw/jbe@5 | 195 score = approvalCount - approvalIndex; |
bsw/jbe@5 | 196 approvalIndex++; |
bsw/jbe@5 | 197 } else if (section.className == "abstention") { |
bsw/jbe@5 | 198 score = 0; |
bsw/jbe@5 | 199 } else if (section.className == "disapproval") { |
bsw/jbe@5 | 200 score = -1 - disapprovalIndex; |
bsw/jbe@5 | 201 disapprovalIndex++; |
bsw/jbe@5 | 202 } |
bsw/jbe@5 | 203 var entries = section.childNodes; |
bsw/jbe@5 | 204 for (var k=0; k<entries.length; k++) { |
bsw/jbe@5 | 205 var entry = entries[k]; |
bsw/jbe@5 | 206 if (entry.className == "movable") { |
bsw/jbe@5 | 207 var id = entry.id.match(/[0-9]+/); |
bsw/jbe@5 | 208 var field = document.createElement("input"); |
bsw/jbe@5 | 209 scoringString += id + ":" + score + ";"; |
bsw/jbe@5 | 210 } |
bsw/jbe@5 | 211 } |
bsw/jbe@5 | 212 } |
bsw/jbe@5 | 213 } |
bsw/jbe@5 | 214 var fields = form.childNodes; |
bsw/jbe@5 | 215 for (var j=0; j<fields.length; j++) { |
bsw/jbe@5 | 216 var field = fields[j]; |
bsw/jbe@5 | 217 if (field.name == "scoring") { |
bsw/jbe@5 | 218 field.setAttribute("value", scoringString); |
bsw/jbe@5 | 219 form.submit(); |
bsw/jbe@5 | 220 return; |
bsw/jbe@5 | 221 } |
bsw/jbe@5 | 222 } |
bsw/jbe@5 | 223 alert('Hidden input field named "scoring" not found.'); |
bsw/jbe@5 | 224 }, false); |
bsw/jbe@5 | 225 } |
bsw/jbe@5 | 226 } |
bsw/jbe@5 | 227 }, false); |