# HG changeset patch # User bsw # Date 1334611627 -7200 # Node ID 7492497005bd8e90070cf4508795192f782f7bb3 # Parent 46c05d8837b724016b15786b1593ca6d44da6ec6 Fixed voting for non javascript capable browser, removed browser warning diff -r 46c05d8837b7 -r 7492497005bd app/main/_layout/default.html --- a/app/main/_layout/default.html Sun Apr 15 18:26:06 2012 +0200 +++ b/app/main/_layout/default.html Mon Apr 16 23:27:07 2012 +0200 @@ -7,6 +7,10 @@ + + + + diff -r 46c05d8837b7 -r 7492497005bd app/main/vote/_action/update.lua --- a/app/main/vote/_action/update.lua Sun Apr 15 18:26:06 2012 +0200 +++ b/app/main/vote/_action/update.lua Mon Apr 16 23:27:07 2012 +0200 @@ -15,9 +15,22 @@ end +local move_up +local move_down -local move_up = param.get("move_up", atom.integer) -local move_down = param.get("move_down", atom.integer) +local tempvoting_string = param.get("scoring") + +local tempvotings = {} +for match in tempvoting_string:gmatch("([^;]+)") do + for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do + tempvotings[tonumber(initiative_id)] = tonumber(grade) + if param.get("move_up_" .. initiative_id .. ".x", atom.integer) then + move_up = tonumber(initiative_id) + elseif param.get("move_down_" .. initiative_id .. ".x", atom.integer) then + move_down = tonumber(initiative_id) + end + end +end if not move_down and not move_up then local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id) @@ -60,15 +73,6 @@ else - local tempvoting_string = param.get("scoring") - - local tempvotings = {} - for match in tempvoting_string:gmatch("([^;]+)") do - for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do - tempvotings[tonumber(initiative_id)] = tonumber(grade) - end - end - local current_initiative_id = move_up or move_down local current_grade = tempvotings[current_initiative_id] or 0 diff -r 46c05d8837b7 -r 7492497005bd app/main/vote/list.lua --- a/app/main/vote/list.lua Sun Apr 15 18:26:06 2012 +0200 +++ b/app/main/vote/list.lua Mon Apr 16 23:27:07 2012 +0200 @@ -81,12 +81,6 @@ end -local warning_text = _"Some JavaScript based functions (voting in particular) will not work.\nFor this beta, please use a current version of Firefox, Safari, Chrome, Opera(?), Konqueror or another (more) standard compliant browser.\nAlternative access without JavaScript will be available soon." - -ui.script{ static = "js/browser_warning.js" } -ui.script{ script = "checkBrowser(" .. encode.json(_"Your web browser is not fully supported yet." .. " " .. warning_text:gsub("\n", "\n\n")) .. ");" } - - local tempvoting_string = param.get("scoring") local tempvotings = {} @@ -341,7 +335,7 @@ end local initiator_names_string = table.concat(initiator_names, ", ") ui.container{ - attr = { style = "float: right;" }, + attr = { style = "float: right; position: relative;" }, content = function() ui.link{ attr = { class = "clickable" }, @@ -366,14 +360,13 @@ } if not readonly then ui.container{ - attr = { style = "float: left;" }, + attr = { style = "float: left; position: relative;" }, content = function() ui.tag{ tag = "input", attr = { - onclick = "voting_moveUp(this.parentNode.parentNode); return(false);", - name = "move_up", - value = initiative.id, + onclick = "if (jsFail) return true; voting_moveUp(this.parentNode.parentNode); return(false);", + name = "move_up_" .. tostring(initiative.id), class = not disabled and "clickable" or nil, type = "image", src = encode.url{ static = "icons/move_up.png" }, @@ -384,9 +377,8 @@ ui.tag{ tag = "input", attr = { - onclick = "voting_moveDown(this.parentNode.parentNode); return(false);", - name = "move_down", - value = initiative.id, + onclick = "if (jsFail) return true; voting_moveDown(this.parentNode.parentNode); return(false);", + name = "move_down_" .. tostring(initiative.id), class = not disabled and "clickable" or nil, type = "image", src = encode.url{ static = "icons/move_down.png" }, diff -r 46c05d8837b7 -r 7492497005bd static/js/browser_warning.js --- a/static/js/browser_warning.js Sun Apr 15 18:26:06 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function evilBrowser() { - return (navigator.appName == "Microsoft Internet Explorer" || ! window.addEventListener); -} - -function checkBrowser(message) { - if (evilBrowser()) { - document.getElementById("layout_warning").innerHTML += '
' + message + '
' ; - } -} diff -r 46c05d8837b7 -r 7492497005bd static/js/dragdrop.js --- a/static/js/dragdrop.js Sun Apr 15 18:26:06 2012 +0200 +++ b/static/js/dragdrop.js Mon Apr 16 23:27:07 2012 +0200 @@ -1,73 +1,76 @@ -window.addEventListener("load", function(event) { - var originalElement; - var draggedElement; - var mouseX; - var mouseY; - var mouseOffsetX; - var mouseOffsetY; - var elementOffsetX; - var elementOffsetY; - var dropFunc; - var dragElement = function(element, func) { - //if (typeof(element) == "string") element = document.getElementById(element); - originalElement = element; - draggedElement = originalElement.cloneNode(true); - originalElement.style.visibility = "hidden"; - draggedElement.style.margin = 0; - draggedElement.style.position = "absolute"; - draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; - draggedElement.style.top = elementOffsetY = originalElement.offsetTop; - draggedElement.style.width = originalElement.clientWidth; - draggedElement.style.height = originalElement.clientHeight; - draggedElement.style.backgroundColor = "#eee"; - draggedElement.style.opacity = 0.8; - originalElement.offsetParent.appendChild(draggedElement); - // workaround for wrong clientWidth and clientHeight information: - draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; - draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; - mouseOffsetX = mouseX; - mouseOffsetY = mouseY; - dropFunc = func; - }; - window.addEventListener("mousemove", function(event) { - mouseX = event.pageX; - mouseY = event.pageY; - if (draggedElement) { - draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; - draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; +if (!jsFail) { + window.addEventListener("load", function(event) { + var originalElement; + var draggedElement; + var mouseX; + var mouseY; + var mouseOffsetX; + var mouseOffsetY; + var elementOffsetX; + var elementOffsetY; + var dropFunc; + var dragElement = function(element, func) { + //if (typeof(element) == "string") element = document.getElementById(element); + originalElement = element; + draggedElement = originalElement.cloneNode(true); + originalElement.style.visibility = "hidden"; + draggedElement.style.margin = 0; + draggedElement.style.position = "absolute"; + draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; + draggedElement.style.top = elementOffsetY = originalElement.offsetTop; + draggedElement.style.width = originalElement.clientWidth; + draggedElement.style.height = originalElement.clientHeight; + draggedElement.style.backgroundColor = "#eee"; + draggedElement.style.opacity = 0.8; + originalElement.offsetParent.appendChild(draggedElement); + // workaround for wrong clientWidth and clientHeight information: + draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; + draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; + mouseOffsetX = mouseX; + mouseOffsetY = mouseY; + dropFunc = func; + }; + window.addEventListener("mousemove", function(event) { + mouseX = event.pageX; + mouseY = event.pageY; + if (draggedElement) { + draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; + draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; + } + }, true); + var mouseDrop = function(event) { + if (draggedElement) { + dropFunc( + originalElement, + elementOffsetX + mouseX - mouseOffsetX, + elementOffsetY + mouseY - mouseOffsetY + ); + originalElement.style.visibility = ''; + draggedElement.parentNode.removeChild(draggedElement); + originalElement = null; + draggedElement = null; + } + }; + window.addEventListener("mouseup", mouseDrop, true); + window.addEventListener("mousedown", mouseDrop, true); + var elements = document.getElementsByTagName("*"); + for (var i=0; i 1) { - if (approvalIndex == 0) { - if (count == 1) setHeading(voting_text_first_preference_single); - else setHeading(voting_text_first_preference_multi); - } else if (approvalIndex == 1) { - if (count == 1) setHeading(voting_text_second_preference_single); - else setHeading(voting_text_second_preference_multi); - } else if (approvalIndex == 2) { - if (count == 1) setHeading(voting_text_third_preference_single); - else setHeading(voting_text_third_preference_multi); - } else { - var text; - if (count == 1) text = voting_text_numeric_preference_single; - else text = voting_text_numeric_preference_multi; - text = text.replace(/#/, "" + (approvalIndex + 1)) - setHeading(text); - } - } else { - if (count == 1) setHeading(voting_text_approval_single); - else setHeading(voting_text_approval_multi); - } - approvalIndex++; - } else if (section.className == "abstention") { - if (count == 1) setHeading(voting_text_abstention_single); - else setHeading(voting_text_abstention_multi); - } else if (section.className == "disapproval") { - if (disapprovalCount > disapprovalIndex + 2) { - if (count == 1) setHeading(voting_text_disapproval_above_many_single); - else setHeading(voting_text_disapproval_above_many_multi); - } else if (disapprovalCount == 2 && disapprovalIndex == 0) { - if (count == 1) setHeading(voting_text_disapproval_above_one_single); - else setHeading(voting_text_disapproval_above_one_multi); - } else if (disapprovalIndex == disapprovalCount - 2) { - if (count == 1) setHeading(voting_text_disapproval_above_last_single); - else setHeading(voting_text_disapproval_above_last_multi); - } else { - if (count == 1) setHeading(voting_text_disapproval_single); - else setHeading(voting_text_disapproval_multi); - } - disapprovalIndex++; - } + function voting_setCategoryHeadings() { + var approvalCount = 0; + var disapprovalCount = 0; + var sections = document.getElementById("voting").childNodes; + for (var i=0; i= section.offsetTop && - centerY < section.offsetTop + section.clientHeight - ) { - var entries = section.childNodes; - for (var j=0; j 1) { + if (approvalIndex == 0) { + if (count == 1) setHeading(voting_text_first_preference_single); + else setHeading(voting_text_first_preference_multi); + } else if (approvalIndex == 1) { + if (count == 1) setHeading(voting_text_second_preference_single); + else setHeading(voting_text_second_preference_multi); + } else if (approvalIndex == 2) { + if (count == 1) setHeading(voting_text_third_preference_single); + else setHeading(voting_text_third_preference_multi); + } else { + var text; + if (count == 1) text = voting_text_numeric_preference_single; + else text = voting_text_numeric_preference_multi; + text = text.replace(/#/, "" + (approvalIndex + 1)) + setHeading(text); + } + } else { + if (count == 1) setHeading(voting_text_approval_single); + else setHeading(voting_text_approval_multi); } - break; + approvalIndex++; + } else if (section.className == "abstention") { + if (count == 1) setHeading(voting_text_abstention_single); + else setHeading(voting_text_abstention_multi); + } else if (section.className == "disapproval") { + if (disapprovalCount > disapprovalIndex + 2) { + if (count == 1) setHeading(voting_text_disapproval_above_many_single); + else setHeading(voting_text_disapproval_above_many_multi); + } else if (disapprovalCount == 2 && disapprovalIndex == 0) { + if (count == 1) setHeading(voting_text_disapproval_above_one_single); + else setHeading(voting_text_disapproval_above_one_multi); + } else if (disapprovalIndex == disapprovalCount - 2) { + if (count == 1) setHeading(voting_text_disapproval_above_last_single); + else setHeading(voting_text_disapproval_above_last_multi); + } else { + if (count == 1) setHeading(voting_text_disapproval_single); + else setHeading(voting_text_disapproval_multi); + } + disapprovalIndex++; } } } - if (i == sections.length) { - var newSection = document.createElement("div"); - var cathead = document.createElement("div"); - cathead.setAttribute("class", "cathead"); - newSection.appendChild(cathead); + } + function voting_move(element, up, dropX, dropY) { + if (typeof(element) == "string") element = document.getElementById(element); + var mouse = (up == null); + var oldParent = element.parentNode; + if (mouse) var centerY = dropY + element.clientHeight / 2; + var approvalCount = 0; + var disapprovalCount = 0; + var mainDiv = document.getElementById("voting"); + var sections = mainDiv.childNodes; + for (var i=0; i= section.offsetTop && + centerY < section.offsetTop + section.clientHeight + ) { + var entries = section.childNodes; + for (var j=0; j 1) || + (section.className == "disapproval" && disapprovalCount > 1) ) { - newSection.setAttribute("class", "approval"); - approvalCount++; - } else { - newSection.setAttribute("class", "disapproval"); - disapprovalCount++; - } - if (up) { - mainDiv.insertBefore(newSection, oldParent); - } else { - if (nextSection) mainDiv.insertBefore(newSection, nextSection); - else mainDiv.appendChild(newSection); - } - } else { - if (up) newSection = prevSection; - else newSection = nextSection; - } - if (newSection) { - oldParent.removeChild(element); - if (create || up) { - newSection.appendChild(element); - } else { - var inserted = false; - for (var i=0; i 1) || - (section.className == "disapproval" && disapprovalCount > 1) - ) { - var entries = section.childNodes; - for (var j=0; j