liquid_feedback_frontend
diff app/main/suggestion/_list.lua @ 718:cc64a4fc6ab6
Cleaned up initiative page
| author | bsw |
|---|---|
| date | Wed Jun 27 14:37:46 2012 +0200 (2012-06-27) |
| parents | 1e7ce3fafc26 |
| children | cdd0bcbbef8b |
line diff
1.1 --- a/app/main/suggestion/_list.lua Wed Jun 27 12:35:34 2012 +0200 1.2 +++ b/app/main/suggestion/_list.lua Wed Jun 27 14:37:46 2012 +0200 1.3 @@ -4,319 +4,95 @@ 1.4 1.5 suggestions_selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") 1.6 1.7 -local tab_id = param.get("tab_id") 1.8 -local show_name = param.get("show_name", atom.boolean) 1.9 -if show_name == nil then 1.10 - show_name = true 1.11 -end 1.12 -local show_filter = param.get("show_filter", atom.boolean) 1.13 -if show_filter == nil then 1.14 - show_filter = true 1.15 -end 1.16 - 1.17 -local partial = { 1.18 - routing = { 1.19 - default = { 1.20 - mode = "redirect", 1.21 - module = "initiative", 1.22 - view = "show_tab", 1.23 - params = { 1.24 - initiative_id = initiative.id, 1.25 - tab = "suggestions", 1.26 - tab_id = tab_id 1.27 - }, 1.28 - } 1.29 - } 1.30 -} 1.31 - 1.32 local ui_filters = ui.filters 1.33 if true or not show_filter then 1.34 ui_filters = function(args) args.content() end 1.35 end 1.36 1.37 -ui.container{ attr = { class = "box" }, 1.38 + 1.39 +ui.container{ attr = { class = "initiative_head" }, 1.40 content = function() 1.41 - ui.paginate{ 1.42 - selector = suggestions_selector, 1.43 - content = function() 1.44 - ui.list{ 1.45 - attr = { style = "table-layout: fixed;" }, 1.46 - records = suggestions_selector:exec(), 1.47 - columns = { 1.48 - { 1.49 - label = show_name and _"Suggestion" or nil, 1.50 - content = function(record) 1.51 - if show_name then 1.52 - ui.link{ 1.53 - text = record.name, 1.54 - module = "suggestion", 1.55 - view = "show", 1.56 - id = record.id 1.57 - } 1.58 - end 1.59 - end 1.60 - }, 1.61 - { 1.62 - label = _"Collective opinion of supporters", 1.63 - label_attr = { style = "width: 101px;" }, 1.64 - content = function(record) 1.65 - if record.minus2_unfulfilled_count then 1.66 - local max_value = record.initiative.supporter_count 1.67 - ui.bargraph{ 1.68 - max_value = max_value, 1.69 - width = 100, 1.70 - bars = { 1.71 - { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count }, 1.72 - { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count }, 1.73 - { 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}, 1.74 - { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count }, 1.75 - { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count }, 1.76 - } 1.77 - } 1.78 - end 1.79 - end 1.80 - }, 1.81 - { 1.82 - label = _"My opinion", 1.83 - label_attr = { style = "width: 130px; font-style: italic;" }, 1.84 - content = function(record) 1.85 - local degree 1.86 - local opinion 1.87 - if app.session.member_id then 1.88 - opinion = Opinion:by_pk(app.session.member.id, record.id) 1.89 - end 1.90 - if opinion then 1.91 - degree = opinion.degree 1.92 - end 1.93 - ui.container{ 1.94 - attr = { class = "suggestion_my_opinion" }, 1.95 - content = function() 1.96 - local has_voting_right = app.session.member and app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id) 1.97 - if app.session.member_id and has_voting_right then 1.98 - if initiative.issue.state == "voting" or initiative.issue.state == "closed" then 1.99 - if degree == -2 then 1.100 - ui.tag{ 1.101 - tag = "span", 1.102 - attr = { 1.103 - class = "action" .. (degree == -2 and " active_red2" or "") 1.104 - }, 1.105 - content = _"must not" 1.106 - } 1.107 - end 1.108 - if degree == -1 then 1.109 - ui.tag{ 1.110 - tag = "span", 1.111 - attr = { class = "action" .. (degree == -1 and " active_red1" or "") }, 1.112 - content = _"should not" 1.113 - } 1.114 - end 1.115 - if degree == nil then 1.116 - ui.tag{ 1.117 - tag = "span", 1.118 - attr = { class = "action" .. (degree == nil and " active" or "") }, 1.119 - content = _"neutral" 1.120 - } 1.121 - end 1.122 - if degree == 1 then 1.123 - ui.tag{ 1.124 - tag = "span", 1.125 - attr = { class = "action" .. (degree == 1 and " active_green1" or "") }, 1.126 - content = _"should" 1.127 - } 1.128 - end 1.129 - if degree == 2 then 1.130 - ui.tag{ 1.131 - tag = "span", 1.132 - attr = { class = "action" .. (degree == 2 and " active_green2" or "") }, 1.133 - content = _"must" 1.134 - } 1.135 - end 1.136 - else 1.137 - -- we need to put initiative_id into the parameters to have a redirect target in case the suggestion is gone after the action 1.138 - params = param.get_all_cgi() 1.139 - params['initiative_id'] = initiative.id 1.140 - 1.141 - ui.link{ 1.142 - attr = { class = "action" .. (degree == 2 and " active_green2" or "") }, 1.143 - text = _"must", 1.144 - module = "opinion", 1.145 - action = "update", 1.146 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } }, 1.147 - params = { 1.148 - suggestion_id = record.id, 1.149 - degree = 2 1.150 - }, 1.151 - partial = partial 1.152 + ui.container{ attr = { class = "title" }, content = _"Suggestions" } 1.153 + ui.container{ attr = { class = "content" }, content = function() 1.154 + ui.paginate{ 1.155 + selector = suggestions_selector, 1.156 + content = function() 1.157 + local suggestions = suggestions_selector:exec() 1.158 + if #suggestions < 1 then 1.159 + if not initiative.issue.fully_frozen and not initiative.issue.closed then 1.160 + ui.tag{ content = _"No suggestions yet" } 1.161 + else 1.162 + ui.tag{ content = _"No suggestions" } 1.163 + end 1.164 + else 1.165 + ui.list{ 1.166 + attr = { style = "table-layout: fixed;" }, 1.167 + records = suggestions, 1.168 + columns = { 1.169 + { 1.170 + label_attr = { style = "width: 101px;" }, 1.171 + content = function(record) 1.172 + if record.minus2_unfulfilled_count then 1.173 + local max_value = record.initiative.supporter_count 1.174 + ui.bargraph{ 1.175 + max_value = max_value, 1.176 + width = 100, 1.177 + bars = { 1.178 + { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count }, 1.179 + { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count }, 1.180 + { 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}, 1.181 + { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count }, 1.182 + { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count }, 1.183 } 1.184 - slot.put(" ") 1.185 - ui.link{ 1.186 - attr = { class = "action" .. (degree == 1 and " active_green1" or "") }, 1.187 - text = _"should", 1.188 - module = "opinion", 1.189 - action = "update", 1.190 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params} }, 1.191 - params = { 1.192 - suggestion_id = record.id, 1.193 - degree = 1 1.194 - }, 1.195 - partial = partial 1.196 - } 1.197 - slot.put(" ") 1.198 - ui.link{ 1.199 - attr = { class = "action" .. (degree == nil and " active" or "") }, 1.200 - text = _"neutral", 1.201 - module = "opinion", 1.202 - action = "update", 1.203 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } }, 1.204 - params = { 1.205 - suggestion_id = record.id, 1.206 - delete = true 1.207 - }, 1.208 - partial = partial 1.209 - } 1.210 - slot.put(" ") 1.211 - ui.link{ 1.212 - attr = { class = "action" .. (degree == -1 and " active_red1" or "") }, 1.213 - text = _"should not", 1.214 - module = "opinion", 1.215 - action = "update", 1.216 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } }, 1.217 - params = { 1.218 - suggestion_id = record.id, 1.219 - degree = -1 1.220 - }, 1.221 - partial = partial 1.222 - } 1.223 - slot.put(" ") 1.224 - ui.link{ 1.225 - attr = { class = "action" .. (degree == -2 and " active_red2" or "") }, 1.226 - text = _"must not", 1.227 - module = "opinion", 1.228 - action = "update", 1.229 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } }, 1.230 - params = { 1.231 - suggestion_id = record.id, 1.232 - degree = -2 1.233 - }, 1.234 - partial = partial 1.235 - } 1.236 - end 1.237 - elseif app.session.member_id then 1.238 - ui.field.text{ value = _"[No voting privilege]" } 1.239 - else 1.240 - ui.field.text{ value = _"[Registered members only]" } 1.241 + } 1.242 end 1.243 end 1.244 - } 1.245 - end 1.246 - }, 1.247 - { 1.248 - label = _"Suggestion currently not implemented", 1.249 - label_attr = { style = "width: 101px;" }, 1.250 - content = function(record) 1.251 - if record.minus2_unfulfilled_count then 1.252 - local max_value = record.initiative.supporter_count 1.253 - ui.bargraph{ 1.254 - max_value = max_value, 1.255 - width = 100, 1.256 - bars = { 1.257 - { color = "#0a0", value = record.plus2_unfulfilled_count }, 1.258 - { color = "#8f8", value = record.plus1_unfulfilled_count }, 1.259 - { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count }, 1.260 - { color = "#f88", value = record.minus1_unfulfilled_count }, 1.261 - { color = "#a00", value = record.minus2_unfulfilled_count }, 1.262 - } 1.263 - } 1.264 - end 1.265 - end 1.266 - }, 1.267 - { 1.268 - label = _"Suggestion currently implemented", 1.269 - label_attr = { style = "width: 101px;" }, 1.270 - content = function(record) 1.271 - if record.minus2_fulfilled_count then 1.272 - local max_value = record.initiative.supporter_count 1.273 - ui.bargraph{ 1.274 - max_value = max_value, 1.275 - width = 100, 1.276 - bars = { 1.277 - { color = "#0a0", value = record.plus2_fulfilled_count }, 1.278 - { color = "#8f8", value = record.plus1_fulfilled_count }, 1.279 - { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count}, 1.280 - { color = "#f88", value = record.minus1_fulfilled_count }, 1.281 - { color = "#a00", value = record.minus2_fulfilled_count }, 1.282 + }, 1.283 + { 1.284 + content = function(record) 1.285 + ui.link{ 1.286 + text = record.name, 1.287 + module = "suggestion", 1.288 + view = "show", 1.289 + id = record.id 1.290 } 1.291 - } 1.292 - end 1.293 - end 1.294 - }, 1.295 - { 1.296 - label = app.session.member_id and _"I consider suggestion as" or nil, 1.297 - label_attr = { style = "width: 100px; font-style: italic;" }, 1.298 - content = function(record) 1.299 - local degree 1.300 - local opinion 1.301 - if app.session.member_id then 1.302 - opinion = Opinion:by_pk(app.session.member.id, record.id) 1.303 - end 1.304 - if opinion then 1.305 - degree = opinion.degree 1.306 - end 1.307 - if opinion then 1.308 - 1.309 - ui.link{ 1.310 - attr = { class = opinion.fulfilled and "action active" or "action" }, 1.311 - text = _"implemented", 1.312 - module = "opinion", 1.313 - action = "update", 1.314 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } }, 1.315 - params = { 1.316 - suggestion_id = record.id, 1.317 - fulfilled = true 1.318 - }, 1.319 - partial = partial 1.320 - } 1.321 - slot.put("<br />") 1.322 - ui.link{ 1.323 - attr = { class = not opinion.fulfilled and "action active" or "action" }, 1.324 - text = _"not implemented", 1.325 - module = "opinion", 1.326 - action = "update", 1.327 - routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } }, 1.328 - params = { 1.329 - suggestion_id = record.id, 1.330 - fulfilled = false 1.331 - }, 1.332 - partial = partial 1.333 - } 1.334 - 1.335 - end 1.336 - end 1.337 - }, 1.338 - { 1.339 - label = app.session.member_id and _"So I'm" or nil, 1.340 - content = function(record) 1.341 - local opinion 1.342 - if app.session.member_id then 1.343 - opinion = Opinion:by_pk(app.session.member.id, record.id) 1.344 - end 1.345 - if opinion then 1.346 - if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then 1.347 - local title = _"satisfied" 1.348 - ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" } 1.349 - elseif opinion.degree == 1 or opinion.degree == -1 then 1.350 - local title = _"a bit unsatisfied" 1.351 - ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" } 1.352 - else 1.353 - local title = _"more unsatisfied" 1.354 - ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" } 1.355 + local degree 1.356 + local opinion 1.357 + if app.session.member_id then 1.358 + opinion = Opinion:by_pk(app.session.member.id, record.id) 1.359 + end 1.360 + if opinion then 1.361 + local degrees = { 1.362 + ["-2"] = _"must not", 1.363 + ["-1"] = _"should not", 1.364 + ["0"] = _"neutral", 1.365 + ["1"] = _"should", 1.366 + ["2"] = _"must" 1.367 + } 1.368 + slot.put(" · ") 1.369 + ui.tag{ content = degrees[tostring(opinion.degree)] } 1.370 + slot.put(" · ") 1.371 + if opinion.fulfilled then 1.372 + ui.tag{ content = _"implemented" } 1.373 + else 1.374 + ui.tag{ content = _"not implemented" } 1.375 + end 1.376 + end 1.377 end 1.378 - end 1.379 - end 1.380 - }, 1.381 - } 1.382 + }, 1.383 + } 1.384 + } 1.385 + end 1.386 + end 1.387 + } 1.388 + end } 1.389 + if not initiative.issue.fully_frozen and not initiative.issue.closed then 1.390 + ui.container{ attr = { class = "content" }, content = function() 1.391 + ui.link{ 1.392 + module = "suggestion", view = "new", params = { initiative_id = initiative.id }, 1.393 + text = _"New suggestion" 1.394 } 1.395 - end 1.396 - } 1.397 + end } 1.398 + end 1.399 end 1.400 }