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