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