liquid_feedback_frontend
view app/main/suggestion/_list.lua @ 64:3ec1dea6eefb
Bug when creating alternative initiatives fixed; Policy list link only shown when creating new issue
author | bsw |
---|---|
date | Thu Apr 22 17:05:18 2010 +0200 (2010-04-22) |
parents | 0849be391140 |
children | 6a12fb7e4963 |
line source
2 local initiative = param.get("initiative", "table")
3 local suggestions_selector = param.get("suggestions_selector", "table")
4 local tab_id = param.get("tab_id")
5 local show_name = param.get("show_name", atom.boolean)
6 if show_name == nil then
7 show_name = true
8 end
9 local show_filter = param.get("show_filter", atom.boolean)
10 if show_filter == nil then
11 show_filter = true
12 end
14 local partial = {
15 routing = {
16 default = {
17 mode = "redirect",
18 module = "initiative",
19 view = "show_tab",
20 params = {
21 initiative_id = initiative.id,
22 tab = "suggestions",
23 tab_id = tab_id
24 },
25 }
26 }
27 }
29 local ui_filters = ui.filters
30 if not show_filter then
31 ui_filters = function(args) args.content() end
32 end
34 ui_filters{
35 label = _"Show filter",
36 selector = suggestions_selector,
37 {
38 label = _"Order by",
39 {
40 name = "plus_unfulfilled",
41 label = _"requested",
42 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") end
43 },
44 {
45 name = "plus2",
46 label = _"must",
47 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus2_fulfilled_count DESC, id") end
48 },
49 {
50 name = "plus",
51 label = _"must/should",
52 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count + plus2_fulfilled_count + plus1_fulfilled_count DESC, id") end
53 },
54 {
55 name = "minus",
56 label = _"must/should not",
57 selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus1_unfulfilled_count + minus2_fulfilled_count + minus1_fulfilled_count DESC, id") end
58 },
59 {
60 name = "minus2",
61 label = _"must not",
62 selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus2_fulfilled_count DESC, id") end
63 }
64 },
65 content = function()
66 ui.paginate{
67 selector = suggestions_selector,
68 content = function()
69 ui.list{
70 attr = { style = "table-layout: fixed;" },
71 records = suggestions_selector:exec(),
72 columns = {
73 {
74 label = show_name and _"Suggestion" or nil,
75 content = function(record)
76 if show_name then
77 ui.link{
78 text = record.name,
79 module = "suggestion",
80 view = "show",
81 id = record.id
82 }
83 end
84 end
85 },
86 {
87 label = _"Collective opinion",
88 label_attr = { style = "width: 101px;" },
89 content = function(record)
90 if record.minus2_unfulfilled_count then
91 local max_value = record.initiative.issue.population
92 ui.bargraph{
93 max_value = max_value,
94 width = 50,
95 bars = {
96 { color = "#ddd", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.minus2_fulfilled_count - record.minus1_fulfilled_count },
97 { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
98 { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
99 { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
100 { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
101 { color = "#ddd", value = max_value - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count },
102 }
103 }
104 end
105 end
106 },
107 {
108 label = _"My opinion",
109 content = function(record)
110 local degree
111 local opinion
112 if app.session.member_id then
113 opinion = Opinion:by_pk(app.session.member.id, record.id)
114 end
115 if opinion then
116 degree = opinion.degree
117 end
118 ui.container{
119 attr = { class = "suggestion_my_opinion" },
120 content = function()
121 if app.session.member_id then
122 if initiative.issue.state == "voting" or initiative.issue.state == "closed" then
123 ui.tag{
124 tag = "span",
125 attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
126 content = _"must not"
127 }
128 ui.tag{
129 tag = "span",
130 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
131 content = _"should not"
132 }
133 ui.tag{
134 tag = "span",
135 attr = { class = "action" .. (degree == nil and " active" or "") },
136 content = _"neutral"
137 }
138 ui.tag{
139 tag = "span",
140 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
141 content = _"should"
142 }
143 ui.tag{
144 tag = "span",
145 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
146 content = _"must"
147 }
148 else
149 ui.link{
150 attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
151 text = _"must not",
152 module = "opinion",
153 action = "update",
154 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
155 params = {
156 suggestion_id = record.id,
157 degree = -2
158 },
159 partial = partial
160 }
161 slot.put(" ")
162 ui.link{
163 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
164 text = _"should not",
165 module = "opinion",
166 action = "update",
167 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
168 params = {
169 suggestion_id = record.id,
170 degree = -1
171 },
172 partial = partial
173 }
174 slot.put(" ")
175 ui.link{
176 attr = { class = "action" .. (degree == nil and " active" or "") },
177 text = _"neutral",
178 module = "opinion",
179 action = "update",
180 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
181 params = {
182 suggestion_id = record.id,
183 delete = true
184 },
185 partial = partial
186 }
187 slot.put(" ")
188 ui.link{
189 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
190 text = _"should",
191 module = "opinion",
192 action = "update",
193 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
194 params = {
195 suggestion_id = record.id,
196 degree = 1
197 },
198 partial = partial
199 }
200 slot.put(" ")
201 ui.link{
202 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
203 text = _"must",
204 module = "opinion",
205 action = "update",
206 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
207 params = {
208 suggestion_id = record.id,
209 degree = 2
210 },
211 partial = partial
212 }
213 end
214 else
215 ui.field.text{ value = _"[Registered members only]" }
216 end
217 end
218 }
219 end
220 },
221 {
222 content = function(record)
223 local opinion
224 if app.session.member_id then
225 opinion = Opinion:by_pk(app.session.member.id, record.id)
226 end
227 if opinion and not opinion.fulfilled then
228 ui.image{ static = "icons/16/cross.png" }
229 end
230 end
231 },
232 {
233 label = _"Suggestion currently not implemented",
234 label_attr = { style = "width: 101px;" },
235 content = function(record)
236 if record.minus2_unfulfilled_count then
237 local max_value = record.initiative.issue.population
238 ui.bargraph{
239 max_value = max_value,
240 width = 50,
241 bars = {
242 { color = "#ddd", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count },
243 { color = "#f88", value = record.minus1_unfulfilled_count },
244 { color = "#a00", value = record.minus2_unfulfilled_count },
245 { color = "#0a0", value = record.plus2_unfulfilled_count },
246 { color = "#8f8", value = record.plus1_unfulfilled_count },
247 { color = "#ddd", value = max_value - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
248 }
249 }
250 end
251 end
252 },
253 {
254 content = function(record)
255 local opinion
256 if app.session.member_id then
257 opinion = Opinion:by_pk(app.session.member.id, record.id)
258 end
259 if opinion and opinion.fulfilled then
260 ui.image{ static = "icons/16/tick.png" }
261 end
262 end
263 },
264 {
265 label = _"Suggestion currently implemented",
266 label_attr = { style = "width: 101px;" },
267 content = function(record)
268 if record.minus2_fulfilled_count then
269 local max_value = record.initiative.issue.population
270 ui.bargraph{
271 max_value = max_value,
272 width = 50,
273 bars = {
274 { color = "#ddd", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count },
275 { color = "#f88", value = record.minus1_fulfilled_count },
276 { color = "#a00", value = record.minus2_fulfilled_count },
277 { color = "#0a0", value = record.plus2_fulfilled_count },
278 { color = "#8f8", value = record.plus1_fulfilled_count },
279 { color = "#ddd", value = max_value - record.plus1_fulfilled_count - record.plus2_fulfilled_count },
280 }
281 }
282 end
283 end
284 },
285 {
286 label_attr = { style = "width: 200px;" },
287 content = function(record)
288 local degree
289 local opinion
290 if app.session.member_id then
291 opinion = Opinion:by_pk(app.session.member.id, record.id)
292 end
293 if opinion then
294 degree = opinion.degree
295 end
296 if opinion then
297 if not opinion.fulfilled then
298 local text = ""
299 if opinion.degree > 0 then
300 text = _"Mark suggestion as implemented and express satisfaction"
301 else
302 text = _"Mark suggestion as implemented and express dissatisfaction"
303 end
304 ui.link{
305 attr = { class = "action" },
306 text = text,
307 module = "opinion",
308 action = "update",
309 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
310 params = {
311 suggestion_id = record.id,
312 fulfilled = true
313 },
314 partial = partial
315 }
316 else
317 if opinion.degree > 0 then
318 text = _"Mark suggestion as not implemented and express dissatisfaction"
319 else
320 text = _"Mark suggestion as not implemented and express satisfaction"
321 end
322 ui.link{
323 attr = { class = "action" },
324 text = text,
325 module = "opinion",
326 action = "update",
327 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
328 params = {
329 suggestion_id = record.id,
330 fulfilled = false
331 },
332 partial = partial
333 }
334 end
335 end
336 end
337 },
338 {
339 content = function(record)
340 local opinion
341 if app.session.member_id then
342 opinion = Opinion:by_pk(app.session.member.id, record.id)
343 end
344 if opinion then
345 if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
346 ui.image{ static = "icons/16/thumb_up_green.png" }
347 else
348 ui.image{ static = "icons/16/thumb_down_red.png" }
349 end
350 end
351 end
352 },
353 }
354 }
355 end
356 }
357 end
358 }