liquid_feedback_frontend
view app/main/suggestion/_list.lua @ 118:93f4e465b50d
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) |
parents | 6a12fb7e4963 |
children | 44ba79952610 |
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 of supporters",
88 label_attr = { style = "width: 101px;" },
89 content = function(record)
90 if record.minus2_unfulfilled_count then
91 local max_value = record.initiative.supporter_count
92 ui.bargraph{
93 max_value = max_value,
94 width = 100,
95 bars = {
96 { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
97 { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
98 { 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},
99 { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
100 { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
101 }
102 }
103 end
104 end
105 },
106 {
107 label = _"My opinion",
108 label_attr = { style = "width: 130px; font-style: italic;" },
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 if degree == -2 then
124 ui.tag{
125 tag = "span",
126 attr = {
127 class = "action" .. (degree == -2 and " active_red2" or "")
128 },
129 content = _"must not"
130 }
131 end
132 if degree == -1 then
133 ui.tag{
134 tag = "span",
135 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
136 content = _"should not"
137 }
138 end
139 if degree == nil then
140 ui.tag{
141 tag = "span",
142 attr = { class = "action" .. (degree == nil and " active" or "") },
143 content = _"neutral"
144 }
145 end
146 if degree == 1 then
147 ui.tag{
148 tag = "span",
149 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
150 content = _"should"
151 }
152 end
153 if degree == 2 then
154 ui.tag{
155 tag = "span",
156 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
157 content = _"must"
158 }
159 end
160 else
161 ui.link{
162 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
163 text = _"must",
164 module = "opinion",
165 action = "update",
166 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
167 params = {
168 suggestion_id = record.id,
169 degree = 2
170 },
171 partial = partial
172 }
173 slot.put(" ")
174 ui.link{
175 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
176 text = _"should",
177 module = "opinion",
178 action = "update",
179 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
180 params = {
181 suggestion_id = record.id,
182 degree = 1
183 },
184 partial = partial
185 }
186 slot.put(" ")
187 ui.link{
188 attr = { class = "action" .. (degree == nil and " active" or "") },
189 text = _"neutral",
190 module = "opinion",
191 action = "update",
192 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
193 params = {
194 suggestion_id = record.id,
195 delete = true
196 },
197 partial = partial
198 }
199 slot.put(" ")
200 ui.link{
201 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
202 text = _"should not",
203 module = "opinion",
204 action = "update",
205 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
206 params = {
207 suggestion_id = record.id,
208 degree = -1
209 },
210 partial = partial
211 }
212 slot.put(" ")
213 ui.link{
214 attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
215 text = _"must not",
216 module = "opinion",
217 action = "update",
218 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
219 params = {
220 suggestion_id = record.id,
221 degree = -2
222 },
223 partial = partial
224 }
225 end
226 else
227 ui.field.text{ value = _"[Registered members only]" }
228 end
229 end
230 }
231 end
232 },
233 {
234 label = _"Suggestion currently not implemented",
235 label_attr = { style = "width: 101px;" },
236 content = function(record)
237 if record.minus2_unfulfilled_count then
238 local max_value = record.initiative.supporter_count
239 ui.bargraph{
240 max_value = max_value,
241 width = 100,
242 bars = {
243 { color = "#0a0", value = record.plus2_unfulfilled_count },
244 { color = "#8f8", value = record.plus1_unfulfilled_count },
245 { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
246 { color = "#f88", value = record.minus1_unfulfilled_count },
247 { color = "#a00", value = record.minus2_unfulfilled_count },
248 }
249 }
250 end
251 end
252 },
253 {
254 label = _"Suggestion currently implemented",
255 label_attr = { style = "width: 101px;" },
256 content = function(record)
257 if record.minus2_fulfilled_count then
258 local max_value = record.initiative.supporter_count
259 ui.bargraph{
260 max_value = max_value,
261 width = 100,
262 bars = {
263 { color = "#0a0", value = record.plus2_fulfilled_count },
264 { color = "#8f8", value = record.plus1_fulfilled_count },
265 { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
266 { color = "#f88", value = record.minus1_fulfilled_count },
267 { color = "#a00", value = record.minus2_fulfilled_count },
268 }
269 }
270 end
271 end
272 },
273 {
274 label = app.session.member_id and _"I consider suggestion as" or nil,
275 label_attr = { style = "width: 100px; font-style: italic;" },
276 content = function(record)
277 local degree
278 local opinion
279 if app.session.member_id then
280 opinion = Opinion:by_pk(app.session.member.id, record.id)
281 end
282 if opinion then
283 degree = opinion.degree
284 end
285 if opinion then
287 ui.link{
288 attr = { class = opinion.fulfilled and "action active" or "action" },
289 text = _"implemented",
290 module = "opinion",
291 action = "update",
292 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
293 params = {
294 suggestion_id = record.id,
295 fulfilled = true
296 },
297 partial = partial
298 }
299 slot.put("<br />")
300 ui.link{
301 attr = { class = not opinion.fulfilled and "action active" or "action" },
302 text = _"not implemented",
303 module = "opinion",
304 action = "update",
305 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
306 params = {
307 suggestion_id = record.id,
308 fulfilled = false
309 },
310 partial = partial
311 }
313 end
314 end
315 },
316 {
317 label = app.session.member_id and _"So I'm" or nil,
318 content = function(record)
319 local opinion
320 if app.session.member_id then
321 opinion = Opinion:by_pk(app.session.member.id, record.id)
322 end
323 if opinion then
324 if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
325 local title = _"satisfied"
326 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" }
327 elseif opinion.degree == 1 or opinion.degree == -1 then
328 local title = _"a bit unsatisfied"
329 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" }
330 else
331 local title = _"more unsatisfied"
332 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" }
333 end
334 end
335 end
336 },
337 }
338 }
339 end
340 }
341 end
342 }