liquid_feedback_frontend
view app/main/suggestion/_list.lua @ 276:f460555c9896
Code cleanup
author | bsw |
---|---|
date | Sun Feb 12 20:03:26 2012 +0100 (2012-02-12) |
parents | 44ba79952610 |
children | b77e6a17ca77 |
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 selector = suggestions_selector,
36 {
37 {
38 name = "plus_unfulfilled",
39 label = _"requested",
40 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") end
41 },
42 {
43 name = "plus2",
44 label = _"must",
45 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus2_fulfilled_count DESC, id") end
46 },
47 {
48 name = "plus",
49 label = _"must/should",
50 selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count + plus2_fulfilled_count + plus1_fulfilled_count DESC, id") end
51 },
52 {
53 name = "minus",
54 label = _"must/should not",
55 selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus1_unfulfilled_count + minus2_fulfilled_count + minus1_fulfilled_count DESC, id") end
56 },
57 {
58 name = "minus2",
59 label = _"must not",
60 selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus2_fulfilled_count DESC, id") end
61 }
62 },
63 content = function()
64 ui.paginate{
65 selector = suggestions_selector,
66 content = function()
67 ui.list{
68 attr = { style = "table-layout: fixed;" },
69 records = suggestions_selector:exec(),
70 columns = {
71 {
72 label = show_name and _"Suggestion" or nil,
73 content = function(record)
74 if show_name then
75 ui.link{
76 text = record.name,
77 module = "suggestion",
78 view = "show",
79 id = record.id
80 }
81 end
82 end
83 },
84 {
85 label = _"Collective opinion of supporters",
86 label_attr = { style = "width: 101px;" },
87 content = function(record)
88 if record.minus2_unfulfilled_count then
89 local max_value = record.initiative.supporter_count
90 ui.bargraph{
91 max_value = max_value,
92 width = 100,
93 bars = {
94 { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
95 { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
96 { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count - record.plus1_fulfilled_count - record.plus2_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 }
100 }
101 end
102 end
103 },
104 {
105 label = _"My opinion",
106 label_attr = { style = "width: 130px; font-style: italic;" },
107 content = function(record)
108 local degree
109 local opinion
110 if app.session.member_id then
111 opinion = Opinion:by_pk(app.session.member.id, record.id)
112 end
113 if opinion then
114 degree = opinion.degree
115 end
116 ui.container{
117 attr = { class = "suggestion_my_opinion" },
118 content = function()
119 if app.session.member_id then
120 if initiative.issue.state == "voting" or initiative.issue.state == "closed" then
121 if degree == -2 then
122 ui.tag{
123 tag = "span",
124 attr = {
125 class = "action" .. (degree == -2 and " active_red2" or "")
126 },
127 content = _"must not"
128 }
129 end
130 if degree == -1 then
131 ui.tag{
132 tag = "span",
133 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
134 content = _"should not"
135 }
136 end
137 if degree == nil then
138 ui.tag{
139 tag = "span",
140 attr = { class = "action" .. (degree == nil and " active" or "") },
141 content = _"neutral"
142 }
143 end
144 if degree == 1 then
145 ui.tag{
146 tag = "span",
147 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
148 content = _"should"
149 }
150 end
151 if degree == 2 then
152 ui.tag{
153 tag = "span",
154 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
155 content = _"must"
156 }
157 end
158 else
159 -- we need to put initiative_id into the parameters to have a redirect target in case the suggestion is gone after the action
160 params = param.get_all_cgi()
161 params['initiative_id'] = initiative.id
163 ui.link{
164 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
165 text = _"must",
166 module = "opinion",
167 action = "update",
168 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
169 params = {
170 suggestion_id = record.id,
171 degree = 2
172 },
173 partial = partial
174 }
175 slot.put(" ")
176 ui.link{
177 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
178 text = _"should",
179 module = "opinion",
180 action = "update",
181 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params} },
182 params = {
183 suggestion_id = record.id,
184 degree = 1
185 },
186 partial = partial
187 }
188 slot.put(" ")
189 ui.link{
190 attr = { class = "action" .. (degree == nil and " active" or "") },
191 text = _"neutral",
192 module = "opinion",
193 action = "update",
194 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
195 params = {
196 suggestion_id = record.id,
197 delete = true
198 },
199 partial = partial
200 }
201 slot.put(" ")
202 ui.link{
203 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
204 text = _"should not",
205 module = "opinion",
206 action = "update",
207 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
208 params = {
209 suggestion_id = record.id,
210 degree = -1
211 },
212 partial = partial
213 }
214 slot.put(" ")
215 ui.link{
216 attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
217 text = _"must not",
218 module = "opinion",
219 action = "update",
220 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
221 params = {
222 suggestion_id = record.id,
223 degree = -2
224 },
225 partial = partial
226 }
227 end
228 else
229 ui.field.text{ value = _"[Registered members only]" }
230 end
231 end
232 }
233 end
234 },
235 {
236 label = _"Suggestion currently not implemented",
237 label_attr = { style = "width: 101px;" },
238 content = function(record)
239 if record.minus2_unfulfilled_count then
240 local max_value = record.initiative.supporter_count
241 ui.bargraph{
242 max_value = max_value,
243 width = 100,
244 bars = {
245 { color = "#0a0", value = record.plus2_unfulfilled_count },
246 { color = "#8f8", value = record.plus1_unfulfilled_count },
247 { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
248 { color = "#f88", value = record.minus1_unfulfilled_count },
249 { color = "#a00", value = record.minus2_unfulfilled_count },
250 }
251 }
252 end
253 end
254 },
255 {
256 label = _"Suggestion currently implemented",
257 label_attr = { style = "width: 101px;" },
258 content = function(record)
259 if record.minus2_fulfilled_count then
260 local max_value = record.initiative.supporter_count
261 ui.bargraph{
262 max_value = max_value,
263 width = 100,
264 bars = {
265 { color = "#0a0", value = record.plus2_fulfilled_count },
266 { color = "#8f8", value = record.plus1_fulfilled_count },
267 { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
268 { color = "#f88", value = record.minus1_fulfilled_count },
269 { color = "#a00", value = record.minus2_fulfilled_count },
270 }
271 }
272 end
273 end
274 },
275 {
276 label = app.session.member_id and _"I consider suggestion as" or nil,
277 label_attr = { style = "width: 100px; font-style: italic;" },
278 content = function(record)
279 local degree
280 local opinion
281 if app.session.member_id then
282 opinion = Opinion:by_pk(app.session.member.id, record.id)
283 end
284 if opinion then
285 degree = opinion.degree
286 end
287 if opinion then
289 ui.link{
290 attr = { class = opinion.fulfilled and "action active" or "action" },
291 text = _"implemented",
292 module = "opinion",
293 action = "update",
294 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
295 params = {
296 suggestion_id = record.id,
297 fulfilled = true
298 },
299 partial = partial
300 }
301 slot.put("<br />")
302 ui.link{
303 attr = { class = not opinion.fulfilled and "action active" or "action" },
304 text = _"not implemented",
305 module = "opinion",
306 action = "update",
307 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
308 params = {
309 suggestion_id = record.id,
310 fulfilled = false
311 },
312 partial = partial
313 }
315 end
316 end
317 },
318 {
319 label = app.session.member_id and _"So I'm" or nil,
320 content = function(record)
321 local opinion
322 if app.session.member_id then
323 opinion = Opinion:by_pk(app.session.member.id, record.id)
324 end
325 if opinion then
326 if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
327 local title = _"satisfied"
328 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" }
329 elseif opinion.degree == 1 or opinion.degree == -1 then
330 local title = _"a bit unsatisfied"
331 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" }
332 else
333 local title = _"more unsatisfied"
334 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" }
335 end
336 end
337 end
338 },
339 }
340 }
341 end
342 }
343 end
344 }