liquid_feedback_frontend

annotate app/main/vote/list.lua @ 16:559c6be0e1e9

"Vote later" feature; Refactored interest box
author bsw
date Tue Feb 02 00:10:17 2010 +0100 (2010-02-02)
parents 77d58efe99fd
children 00d1004545f1
rev   line source
bsw/jbe@5 1 local warning_text = _"Some JavaScript based functions (voting in particular) will not work.\nFor this beta, please use a current version of Firefox, Safari, Opera(?), Konqueror or another (more) standard compliant browser.\nAlternative access without JavaScript will be available soon."
bsw/jbe@5 2
bsw/jbe@5 3 ui.script{ static = "js/browser_warning.js" }
bsw/jbe@5 4 ui.script{ script = "checkBrowser(" .. encode.json(_"Your web browser is not fully supported yet." .. " " .. warning_text:gsub("\n", "\n\n")) .. ");" }
bsw/jbe@5 5
bsw/jbe@5 6 ui.tag{
bsw/jbe@5 7 tag = "noscript",
bsw/jbe@5 8 content = function()
bsw/jbe@5 9 slot.put(_"JavaScript is disabled or not available." .. " " .. encode.html_newlines(warning_text))
bsw/jbe@5 10 end
bsw/jbe@5 11 }
bsw/jbe@5 12
bsw/jbe@5 13
bsw/jbe@5 14 local issue = Issue:by_id(param.get("issue_id"), atom.integer)
bsw/jbe@5 15
bsw/jbe@5 16 local initiatives = issue.initiatives
bsw/jbe@5 17
bsw/jbe@5 18 local min_grade = -1;
bsw/jbe@5 19 local max_grade = 1;
bsw/jbe@5 20
bsw/jbe@5 21 for i, initiative in ipairs(initiatives) do
bsw/jbe@5 22 -- TODO performance
bsw/jbe@5 23 initiative.vote = Vote:by_pk(initiative.id, app.session.member.id)
bsw/jbe@5 24 if initiative.vote then
bsw/jbe@5 25 if initiative.vote.grade > max_grade then
bsw/jbe@5 26 max_grade = initiative.vote.grade
bsw/jbe@5 27 end
bsw/jbe@5 28 if initiative.vote.grade < min_grade then
bsw/jbe@5 29 min_grade = initiative.vote.grade
bsw/jbe@5 30 end
bsw/jbe@5 31 end
bsw/jbe@5 32 end
bsw/jbe@5 33
bsw/jbe@5 34 local sections = {}
bsw/jbe@5 35 for i = min_grade, max_grade do
bsw/jbe@5 36 sections[i] = {}
bsw/jbe@5 37 for j, initiative in ipairs(initiatives) do
bsw/jbe@5 38 if (initiative.vote and initiative.vote.grade == i) or (not initiative.vote and i == 0) then
bsw/jbe@5 39 sections[i][#(sections[i])+1] = initiative
bsw/jbe@5 40 end
bsw/jbe@5 41 end
bsw/jbe@5 42 end
bsw/jbe@5 43
bsw/jbe@5 44 slot.put_into("title", _"Voting")
bsw/jbe@5 45
bsw/jbe@5 46 slot.select("actions", function()
bsw/jbe@5 47 ui.link{
bsw/jbe@5 48 content = function()
bsw/jbe@5 49 ui.image{ static = "icons/16/cancel.png" }
bsw/jbe@5 50 slot.put(_"Cancel")
bsw/jbe@5 51 end,
bsw/jbe@5 52 module = "issue",
bsw/jbe@5 53 view = "show",
bsw/jbe@5 54 id = issue.id
bsw/jbe@5 55 }
bsw/jbe@5 56 end)
bsw/jbe@5 57
bsw/jbe@5 58 util.help("vote.list", _"Voting")
bsw/jbe@5 59
bsw/jbe@5 60
bsw/jbe@5 61 slot.put('<script src="' .. request.get_relative_baseurl() .. 'static/js/dragdrop.js"></script>')
bsw/jbe@5 62 slot.put('<script src="' .. request.get_relative_baseurl() .. 'static/js/voting.js"></script>')
bsw/jbe@5 63
bsw/jbe@5 64 ui.form{
bsw/jbe@5 65 attr = { id = "voting_form" },
bsw/jbe@5 66 module = "vote",
bsw/jbe@5 67 action = "update",
bsw/jbe@5 68 params = { issue_id = issue.id },
bsw/jbe@5 69 routing = {
bsw/jbe@5 70 default = {
bsw/jbe@5 71 mode = "redirect",
bsw/jbe@5 72 module = "issue",
bsw/jbe@5 73 view = "show",
bsw/jbe@5 74 id = issue.id
bsw/jbe@5 75 }
bsw/jbe@5 76 },
bsw/jbe@5 77 content = function()
bsw/jbe@5 78 slot.put('<input type="hidden" name="scoring" value=""/>')
bsw/jbe@5 79 -- TODO abstrahieren
bsw/jbe@5 80 ui.tag{
bsw/jbe@5 81 tag = "input",
bsw/jbe@5 82 attr = {
bsw/jbe@5 83 type = "button",
bsw/jbe@5 84 class = "voting_done",
bsw/jbe@5 85 value = _"Finish voting"
bsw/jbe@5 86 }
bsw/jbe@5 87 }
bsw/jbe@5 88 ui.container{
bsw/jbe@5 89 attr = { id = "voting" },
bsw/jbe@5 90 content = function()
bsw/jbe@5 91 for grade = max_grade, min_grade, -1 do
bsw/jbe@5 92 local section = sections[grade]
bsw/jbe@5 93 local class
bsw/jbe@5 94 if grade > 0 then
bsw/jbe@5 95 class = "approval"
bsw/jbe@5 96 elseif grade < 0 then
bsw/jbe@5 97 class = "disapproval"
bsw/jbe@5 98 else
bsw/jbe@5 99 class = "abstention"
bsw/jbe@5 100 end
bsw/jbe@5 101 ui.container{
bsw/jbe@5 102 attr = { class = class },
bsw/jbe@5 103 content = function()
bsw/jbe@5 104 slot.put('<div class="cathead"></div>')
bsw/jbe@5 105 for i, initiative in ipairs(section) do
bsw/jbe@5 106 ui.container{
bsw/jbe@5 107 attr = {
bsw/jbe@5 108 class = "movable",
bsw/jbe@5 109 id = "entry_" .. tostring(initiative.id)
bsw/jbe@5 110 },
bsw/jbe@5 111 content = function()
bsw@11 112 local initiators_selector = initiative:get_reference_selector("initiating_members")
bsw@11 113 :add_where("accepted")
bsw@11 114 local initiators = initiators_selector:exec()
bsw/jbe@6 115 local initiator_names = {}
bsw/jbe@6 116 for i, initiator in ipairs(initiators) do
bsw/jbe@6 117 initiator_names[#initiator_names+1] = initiator.name
bsw/jbe@6 118 end
bsw/jbe@6 119 local initiator_names_string = table.concat(initiator_names, ", ")
bsw/jbe@6 120 ui.container{
bsw/jbe@6 121 attr = { style = "float: right;" },
bsw/jbe@6 122 content = function()
bsw/jbe@6 123 ui.link{
bsw/jbe@6 124 attr = { class = "clickable" },
bsw/jbe@6 125 content = _"Show",
bsw/jbe@6 126 module = "initiative",
bsw/jbe@6 127 view = "show",
bsw/jbe@6 128 id = initiative.id
bsw/jbe@6 129 }
bsw/jbe@6 130 slot.put(" ")
bsw/jbe@6 131 ui.link{
bsw/jbe@6 132 attr = { class = "clickable", target = "_blank" },
bsw/jbe@6 133 content = _"(new window)",
bsw/jbe@6 134 module = "initiative",
bsw/jbe@6 135 view = "show",
bsw/jbe@6 136 id = initiative.id
bsw/jbe@6 137 }
bsw/jbe@6 138 slot.put(" ")
bsw/jbe@6 139 ui.image{ attr = { class = "grabber" }, static = "icons/grabber.png" }
bsw/jbe@6 140 end
bsw/jbe@5 141 }
bsw/jbe@6 142 slot.put(encode.html(initiative.shortened_name))
bsw/jbe@6 143 if #initiators > 1 then
bsw/jbe@6 144 ui.container{
bsw/jbe@6 145 attr = { style = "font-size: 80%;" },
bsw/jbe@6 146 content = _"Initiators" .. ": " .. initiator_names_string
bsw/jbe@6 147 }
bsw/jbe@6 148 else
bsw/jbe@6 149 ui.container{
bsw/jbe@6 150 attr = { style = "font-size: 80%;" },
bsw/jbe@6 151 content = _"Initiator" .. ": " .. initiator_names_string
bsw/jbe@6 152 }
bsw/jbe@6 153 end
bsw/jbe@5 154 end
bsw/jbe@5 155 }
bsw/jbe@5 156 end
bsw/jbe@5 157 end
bsw/jbe@5 158 }
bsw/jbe@5 159 end
bsw/jbe@5 160 end
bsw/jbe@5 161 }
bsw/jbe@5 162 ui.tag{
bsw/jbe@5 163 tag = "input",
bsw/jbe@5 164 attr = {
bsw/jbe@5 165 type = "button",
bsw/jbe@5 166 class = "voting_done",
bsw/jbe@5 167 value = _"Finish voting"
bsw/jbe@5 168 }
bsw/jbe@5 169 }
bsw/jbe@5 170 end
bsw/jbe@5 171 }
bsw/jbe@5 172
bsw/jbe@5 173

Impressum / About Us