liquid_feedback_frontend

view app/main/initiative/show.lua @ 719:17a33bd0d48a

Cleaned up issue page
author bsw
date Wed Jun 27 14:48:35 2012 +0200 (2012-06-27)
parents cc64a4fc6ab6
children cdd0bcbbef8b
line source
1 local initiative = Initiative:by_id(param.get_id())
2 initiative:load_everything_for_member_id(app.session.member_id)
4 local issue = initiative.issue
6 if app.session.member_id then
7 issue:load_everything_for_member_id(app.session.member_id)
8 end
10 app.html_title.title = initiative.name
11 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
13 slot.select("head", function()
14 execute.view{
15 module = "issue", view = "_head",
16 params = { issue = issue, initiative = initiative }
17 }
18 end)
20 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
21 :add_field("initiator.accepted", "accepted")
22 :add_order_by("member.name")
23 if initiator and initiator.accepted then
24 initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
25 else
26 initiators_members_selector:add_where("initiator.accepted")
27 end
29 local initiators = initiators_members_selector:exec()
32 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
33 slot.select("head", function()
34 execute.view{
35 module = "issue",
36 view = "_show",
37 params = {
38 issue = initiative.issue,
39 initiative_limit = 3,
40 for_initiative = initiative
41 }
42 }
43 end)
45 util.help("initiative.show")
47 ui.container{ attr = { class = "initiative_head" }, content = function()
49 ui.container{
50 attr = { class = "title" },
51 content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
52 }
54 ui.container{ attr = { class = "content" }, content = function()
55 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
56 ui.tag{
57 attr = { class = "initiator_names" },
58 content = function()
59 for i, initiator in ipairs(initiators) do
60 slot.put(" ")
61 if app.session.member_id or config.public_access == "full" then
62 ui.link{
63 content = function ()
64 execute.view{
65 module = "member_image",
66 view = "_show",
67 params = {
68 member = initiator,
69 image_type = "avatar",
70 show_dummy = true,
71 class = "micro_avatar",
72 popup_text = text
73 }
74 }
75 end,
76 module = "member", view = "show", id = initiator.id
77 }
78 slot.put(" ")
79 end
80 ui.link{
81 text = initiator.name,
82 module = "member", view = "show", id = initiator.id
83 }
84 if not initiator.accepted then
85 ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
86 end
87 end
88 end
89 }
90 end
92 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
93 slot.put(" · ")
94 ui.link{
95 attr = { class = "action" },
96 content = function()
97 slot.put(_"Invite initiator")
98 end,
99 module = "initiative",
100 view = "add_initiator",
101 params = { initiative_id = initiative.id }
102 }
103 if #initiators > 1 then
104 slot.put(" · ")
105 ui.link{
106 content = function()
107 slot.put(_"Remove initiator")
108 end,
109 module = "initiative",
110 view = "remove_initiator",
111 params = { initiative_id = initiative.id }
112 }
113 end
114 end
115 if initiator and initiator.accepted == false then
116 slot.put(" · ")
117 ui.link{
118 text = _"Cancel refuse of invitation",
119 module = "initiative",
120 action = "remove_initiator",
121 params = {
122 initiative_id = initiative.id,
123 member_id = app.session.member.id
124 },
125 routing = {
126 ok = {
127 mode = "redirect",
128 module = "initiative",
129 view = "show",
130 id = initiative.id
131 }
132 }
133 }
134 end
135 end }
136 ui.container{ attr = { class = "content" }, content = function()
137 if app.session.member_id then
138 execute.view{
139 module = "supporter",
140 view = "_show_box",
141 params = {
142 initiative = initiative
143 }
144 }
145 end
147 end }
150 -- voting results
151 if initiative.issue.ranks_available and initiative.admitted then
152 local class = initiative.winner and "admitted_info" or "not_admitted_info"
153 ui.container{
154 attr = { class = class },
155 content = function()
156 local max_value = initiative.issue.voter_count
157 slot.put(" ")
158 local positive_votes = initiative.positive_votes
159 local negative_votes = initiative.negative_votes
160 local sum_votes = initiative.positive_votes + initiative.negative_votes
161 local function perc(votes, sum)
162 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
163 return ""
164 end
165 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
166 slot.put(" &middot; ")
167 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
168 slot.put(" &middot; ")
169 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
170 slot.put(" &middot; ")
171 slot.put("<b>")
172 if initiative.winner then
173 slot.put(_"Approved")
174 elseif initiative.rank then
175 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
176 else
177 slot.put(_"Not approved")
178 end
179 slot.put("</b>")
180 end
181 }
182 end
184 ui.container{ attr = { class = "content" }, content = function()
185 execute.view{
186 module = "initiative",
187 view = "_battles",
188 params = { initiative = initiative }
189 }
190 end }
192 -- initiative not admitted info
193 if initiative.admitted == false then
194 local policy = initiative.issue.policy
195 ui.container{
196 attr = { class = "not_admitted_info" },
197 content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
198 }
199 end
201 -- initiative revoked info
202 if initiative.revoked then
203 ui.container{
204 attr = { class = "revoked_info" },
205 content = function()
206 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
207 local suggested_initiative = initiative.suggested_initiative
208 if suggested_initiative then
209 slot.put("<br /><br />")
210 slot.put(_("The initiators suggest to support the following initiative:"))
211 slot.put(" ")
212 ui.link{
213 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
214 module = "initiative",
215 view = "show",
216 id = suggested_initiative.id
217 }
218 end
219 end
220 }
221 end
224 -- invited as initiator
225 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
226 ui.container{
227 attr = { class = "initiator_invite_info" },
228 content = function()
229 slot.put(_"You are invited to become initiator of this initiative.")
230 slot.put(" ")
231 ui.link{
232 image = { static = "icons/16/tick.png" },
233 text = _"Accept invitation",
234 module = "initiative",
235 action = "accept_invitation",
236 id = initiative.id,
237 routing = {
238 default = {
239 mode = "redirect",
240 module = request.get_module(),
241 view = request.get_view(),
242 id = param.get_id_cgi(),
243 params = param.get_all_cgi()
244 }
245 }
246 }
247 slot.put(" ")
248 ui.link{
249 image = { static = "icons/16/cross.png" },
250 text = _"Refuse invitation",
251 module = "initiative",
252 action = "reject_initiator_invitation",
253 params = {
254 initiative_id = initiative.id,
255 member_id = app.session.member.id
256 },
257 routing = {
258 default = {
259 mode = "redirect",
260 module = request.get_module(),
261 view = request.get_view(),
262 id = param.get_id_cgi(),
263 params = param.get_all_cgi()
264 }
265 }
266 }
267 end
268 }
269 end
271 -- draft updated
272 local supporter
274 if app.session.member_id then
275 supporter = app.session.member:get_reference_selector("supporters")
276 :add_where{ "initiative_id = ?", initiative.id }
277 :optional_object_mode()
278 :exec()
279 end
281 if supporter and not initiative.issue.closed then
282 local old_draft_id = supporter.draft_id
283 local new_draft_id = initiative.current_draft.id
284 if old_draft_id ~= new_draft_id then
285 ui.container{
286 attr = { class = "draft_updated_info" },
287 content = function()
288 slot.put(_"The draft of this initiative has been updated!")
289 slot.put(" ")
290 ui.link{
291 content = _"Show diff",
292 module = "draft",
293 view = "diff",
294 params = {
295 old_draft_id = old_draft_id,
296 new_draft_id = new_draft_id
297 }
298 }
299 if not initiative.revoked then
300 slot.put(" ")
301 ui.link{
302 text = _"Refresh support to current draft",
303 module = "initiative",
304 action = "add_support",
305 id = initiative.id,
306 routing = {
307 default = {
308 mode = "redirect",
309 module = "initiative",
310 view = "show",
311 id = initiative.id
312 }
313 }
314 }
315 end
316 end
317 }
318 end
319 end
322 execute.view{
323 module = "draft",
324 view = "_show",
325 params = {
326 draft = initiative.current_draft
327 }
328 }
330 end }
332 execute.view{
333 module = "suggestion",
334 view = "_list",
335 params = {
336 initiative = initiative,
337 suggestions_selector = initiative:get_reference_selector("suggestions"),
338 tab_id = param.get("tab_id")
339 }
340 }
343 if config.public_access == "full" or app.session.member_id then
344 if initiative.issue.ranks_available then
345 local members_selector = initiative.issue:get_reference_selector("direct_voters")
346 :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
347 :add_field("direct_voter.weight as voter_weight")
348 :add_field("coalesce(vote.grade, 0) as grade")
349 :left_join("initiative", nil, "initiative.id = vote.initiative_id")
350 :left_join("issue", nil, "issue.id = initiative.issue_id")
352 ui.container{ attr = { class = "heading"}, content = _"Member voting" }
354 execute.view{
355 module = "member",
356 view = "_list",
357 params = {
358 initiative = initiative,
359 for_votes = true,
360 members_selector = members_selector
361 }
362 }
363 end
365 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
366 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
367 :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
368 :add_field("direct_interest_snapshot.weight")
369 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
370 :add_where("direct_supporter_snapshot.satisfied")
371 :add_field("direct_supporter_snapshot.informed", "is_informed")
375 if members_selector:count() > 0 then
376 if issue.fully_frozen then
377 ui.container{ attr = { class = "heading"}, content = _"Supporters (before begin of voting)" }
378 else
379 ui.container{ attr = { class = "heading"}, content = _"Supporters" }
380 end
382 execute.view{
383 module = "member",
384 view = "_list",
385 params = {
387 initiative = initiative,
388 members_selector = members_selector
389 }
390 }
391 else
392 if issue.fully_frozen then
393 ui.container{ attr = { class = "heading"}, content = _"No supporters (before begin of voting)" }
394 else
395 ui.container{ attr = { class = "heading"}, content = _"No supporters" }
396 end
397 slot.put("<br />")
398 end
400 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
401 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
402 :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
403 :add_field("direct_interest_snapshot.weight")
404 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
405 :add_where("NOT direct_supporter_snapshot.satisfied")
406 :add_field("direct_supporter_snapshot.informed", "is_informed")
409 if members_selector:count() > 0 then
410 if issue.fully_frozen then
411 ui.container{ attr = { class = "heading"}, content = _"Potential supporters (before begin of voting" }
412 else
413 ui.container{ attr = { class = "heading"}, content = _"Potential supporters" }
414 end
416 execute.view{
417 module = "member",
418 view = "_list",
419 params = {
421 initiative = initiative,
422 members_selector = members_selector
423 }
424 }
425 else
426 if issue.fully_frozen then
427 ui.container{ attr = { class = "heading"}, content = _"No potential supporters (before begin of voting)" }
428 else
429 ui.container{ attr = { class = "heading"}, content = _"No potential supporters" }
430 end
431 slot.put("<br />")
432 end
434 ui.container{ attr = { class = "heading"}, content = _"Details" }
435 execute.view {
436 module = "initiative",
437 view = "_details",
438 params = {
439 initiative = initiative,
440 members_selector = members_selector
441 }
442 }
444 end
447 --[[
448 execute.view{
449 module = "initiative",
450 view = "show_tab",
451 params = {
452 initiative = initiative,
453 initiator = initiator
454 }
455 }
457 if initiative.issue.snapshot then
458 slot.put("<br />")
459 ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
460 end
463 --]]

Impressum / About Us