liquid_feedback_frontend

view app/main/initiative/_show.lua @ 725:344e5fdce8c9

Fixed public search, made draft history available again
author bsw
date Thu Jun 28 13:52:42 2012 +0200 (2012-06-28)
parents
children 161cebfc44d4
line source
1 local initiative = param.get("initiative", "table")
3 local show_as_head = param.get("show_as_head", atom.boolean)
5 initiative:load_everything_for_member_id(app.session.member_id)
7 local issue = initiative.issue
9 -- TODO performance
10 local initiator
11 if app.session.member_id then
12 initiator = Initiator:by_pk(initiative.id, app.session.member.id)
13 end
15 if app.session.member_id then
16 issue:load_everything_for_member_id(app.session.member_id)
17 end
19 app.html_title.title = initiative.name
20 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
22 slot.select("head", function()
23 execute.view{
24 module = "issue", view = "_head",
25 params = { issue = issue, initiative = initiative }
26 }
27 end)
29 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
30 :add_field("initiator.accepted", "accepted")
31 :add_order_by("member.name")
32 if initiator and initiator.accepted then
33 initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
34 else
35 initiators_members_selector:add_where("initiator.accepted")
36 end
38 local initiators = initiators_members_selector:exec()
41 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
42 slot.select("head", function()
43 execute.view{
44 module = "issue",
45 view = "_show",
46 params = {
47 issue = initiative.issue,
48 initiative_limit = 3,
49 for_initiative = initiative
50 }
51 }
52 end)
54 util.help("initiative.show")
56 ui.container{ attr = { class = "initiative_head" }, content = function()
58 local text = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
59 if show_as_head then
60 ui.link{
61 attr = { class = "title" }, text = text,
62 module = "initiative", view = "show", id = initiative.id
63 }
64 else
65 ui.container{ attr = { class = "title" }, content = text }
66 end
67 ui.container{ attr = { class = "content" }, content = function()
68 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
69 ui.tag{
70 attr = { class = "initiator_names" },
71 content = function()
72 for i, initiator in ipairs(initiators) do
73 slot.put(" ")
74 if app.session.member_id or config.public_access == "full" then
75 ui.link{
76 content = function ()
77 execute.view{
78 module = "member_image",
79 view = "_show",
80 params = {
81 member = initiator,
82 image_type = "avatar",
83 show_dummy = true,
84 class = "micro_avatar",
85 popup_text = text
86 }
87 }
88 end,
89 module = "member", view = "show", id = initiator.id
90 }
91 slot.put(" ")
92 end
93 ui.link{
94 text = initiator.name,
95 module = "member", view = "show", id = initiator.id
96 }
97 if not initiator.accepted then
98 ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
99 end
100 end
101 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
102 slot.put(" · ")
103 ui.link{
104 attr = { class = "action" },
105 content = function()
106 slot.put(_"Invite initiator")
107 end,
108 module = "initiative",
109 view = "add_initiator",
110 params = { initiative_id = initiative.id }
111 }
112 if #initiators > 1 then
113 slot.put(" · ")
114 ui.link{
115 content = function()
116 slot.put(_"Remove initiator")
117 end,
118 module = "initiative",
119 view = "remove_initiator",
120 params = { initiative_id = initiative.id }
121 }
122 end
123 end
124 if initiator and initiator.accepted == false then
125 slot.put(" · ")
126 ui.link{
127 text = _"Cancel refuse of invitation",
128 module = "initiative",
129 action = "remove_initiator",
130 params = {
131 initiative_id = initiative.id,
132 member_id = app.session.member.id
133 },
134 routing = {
135 ok = {
136 mode = "redirect",
137 module = "initiative",
138 view = "show",
139 id = initiative.id
140 }
141 }
142 }
143 end
144 if (initiative.discussion_url and #initiative.discussion_url > 0) then
145 slot.put(" · ")
146 if initiative.discussion_url:find("^https?://") then
147 if initiative.discussion_url and #initiative.discussion_url > 0 then
148 ui.link{
149 attr = {
150 target = "_blank",
151 title = _"Discussion with initiators"
152 },
153 text = _"Discuss with initiators",
154 external = initiative.discussion_url
155 }
156 end
157 else
158 slot.put(encode.html(initiative.discussion_url))
159 end
160 end
161 if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
162 slot.put(" · ")
163 ui.link{
164 text = _"change discussion URL",
165 module = "initiative",
166 view = "edit",
167 id = initiative.id
168 }
169 slot.put(" ")
170 end
171 end
172 }
173 end
175 end }
176 ui.container{ attr = { class = "content" }, content = function()
177 if app.session.member_id then
178 execute.view{
179 module = "supporter",
180 view = "_show_box",
181 params = {
182 initiative = initiative
183 }
184 }
185 end
187 end }
190 -- voting results
191 if initiative.issue.ranks_available and initiative.admitted then
192 local class = initiative.winner and "admitted_info" or "not_admitted_info"
193 ui.container{
194 attr = { class = class },
195 content = function()
196 local max_value = initiative.issue.voter_count
197 slot.put(" ")
198 local positive_votes = initiative.positive_votes
199 local negative_votes = initiative.negative_votes
200 local sum_votes = initiative.positive_votes + initiative.negative_votes
201 local function perc(votes, sum)
202 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
203 return ""
204 end
205 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
206 slot.put(" &middot; ")
207 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
208 slot.put(" &middot; ")
209 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
210 slot.put(" &middot; ")
211 slot.put("<b>")
212 if initiative.winner then
213 slot.put(_"Approved")
214 elseif initiative.rank then
215 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
216 else
217 slot.put(_"Not approved")
218 end
219 slot.put("</b>")
220 end
221 }
222 end
224 ui.container{ attr = { class = "content" }, content = function()
225 execute.view{
226 module = "initiative",
227 view = "_battles",
228 params = { initiative = initiative }
229 }
230 end }
232 -- initiative not admitted info
233 if initiative.admitted == false then
234 local policy = initiative.issue.policy
235 ui.container{
236 attr = { class = "not_admitted_info" },
237 content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
238 }
239 end
241 -- initiative revoked info
242 if initiative.revoked then
243 ui.container{
244 attr = { class = "revoked_info" },
245 content = function()
246 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
247 local suggested_initiative = initiative.suggested_initiative
248 if suggested_initiative then
249 slot.put("<br /><br />")
250 slot.put(_("The initiators suggest to support the following initiative:"))
251 slot.put(" ")
252 ui.link{
253 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
254 module = "initiative",
255 view = "show",
256 id = suggested_initiative.id
257 }
258 end
259 end
260 }
261 end
264 -- invited as initiator
265 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
266 ui.container{
267 attr = { class = "initiator_invite_info" },
268 content = function()
269 slot.put(_"You are invited to become initiator of this initiative.")
270 slot.put(" ")
271 ui.link{
272 image = { static = "icons/16/tick.png" },
273 text = _"Accept invitation",
274 module = "initiative",
275 action = "accept_invitation",
276 id = initiative.id,
277 routing = {
278 default = {
279 mode = "redirect",
280 module = request.get_module(),
281 view = request.get_view(),
282 id = param.get_id_cgi(),
283 params = param.get_all_cgi()
284 }
285 }
286 }
287 slot.put(" ")
288 ui.link{
289 image = { static = "icons/16/cross.png" },
290 text = _"Refuse invitation",
291 module = "initiative",
292 action = "reject_initiator_invitation",
293 params = {
294 initiative_id = initiative.id,
295 member_id = app.session.member.id
296 },
297 routing = {
298 default = {
299 mode = "redirect",
300 module = request.get_module(),
301 view = request.get_view(),
302 id = param.get_id_cgi(),
303 params = param.get_all_cgi()
304 }
305 }
306 }
307 end
308 }
309 end
311 -- draft updated
312 local supporter
314 if app.session.member_id then
315 supporter = app.session.member:get_reference_selector("supporters")
316 :add_where{ "initiative_id = ?", initiative.id }
317 :optional_object_mode()
318 :exec()
319 end
321 if supporter and not initiative.issue.closed then
322 local old_draft_id = supporter.draft_id
323 local new_draft_id = initiative.current_draft.id
324 if old_draft_id ~= new_draft_id then
325 ui.container{
326 attr = { class = "draft_updated_info" },
327 content = function()
328 slot.put(_"The draft of this initiative has been updated!")
329 slot.put(" ")
330 ui.link{
331 content = _"Show diff",
332 module = "draft",
333 view = "diff",
334 params = {
335 old_draft_id = old_draft_id,
336 new_draft_id = new_draft_id
337 }
338 }
339 if not initiative.revoked then
340 slot.put(" ")
341 ui.link{
342 text = _"Refresh support to current draft",
343 module = "initiative",
344 action = "add_support",
345 id = initiative.id,
346 routing = {
347 default = {
348 mode = "redirect",
349 module = "initiative",
350 view = "show",
351 id = initiative.id
352 }
353 }
354 }
355 end
356 end
357 }
358 end
359 end
361 if not show_as_head then
362 local drafts_count = initiative:get_reference_selector("drafts"):count()
364 ui.container{ attr = { class = "content" }, content = function()
366 if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
367 ui.link{
368 content = function()
369 slot.put(_"Edit draft")
370 end,
371 module = "draft",
372 view = "new",
373 params = { initiative_id = initiative.id }
374 }
375 slot.put(" &middot; ")
376 ui.link{
377 content = function()
378 slot.put(_"Revoke initiative")
379 end,
380 module = "initiative",
381 view = "revoke",
382 id = initiative.id
383 }
384 slot.put(" &middot; ")
385 end
387 ui.tag{
388 attr = { class = "draft_version" },
389 content = _("Latest draft created at #{date} #{time}", {
390 date = format.date(initiative.current_draft.created),
391 time = format.time(initiative.current_draft.created)
392 })
393 }
394 if drafts_count > 1 then
395 slot.put(" &middot; ")
396 ui.link{
397 module = "draft", view = "list", params = { initiative_id = initiative.id },
398 text = _("List all revisions (#{count})", { count = drafts_count })
399 }
400 end
401 end }
403 execute.view{
404 module = "draft",
405 view = "_show",
406 params = {
407 draft = initiative.current_draft
408 }
409 }
410 end
411 end }
413 if not show_as_head then
414 execute.view{
415 module = "suggestion",
416 view = "_list",
417 params = {
418 initiative = initiative,
419 suggestions_selector = initiative:get_reference_selector("suggestions"),
420 tab_id = param.get("tab_id")
421 }
422 }
425 if config.public_access == "full" or app.session.member_id then
426 if initiative.issue.ranks_available then
427 local members_selector = initiative.issue:get_reference_selector("direct_voters")
428 :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
429 :add_field("direct_voter.weight as voter_weight")
430 :add_field("coalesce(vote.grade, 0) as grade")
431 :left_join("initiative", nil, "initiative.id = vote.initiative_id")
432 :left_join("issue", nil, "issue.id = initiative.issue_id")
434 ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Member voter" }
436 execute.view{
437 module = "member",
438 view = "_list",
439 params = {
440 initiative = initiative,
441 for_votes = true,
442 members_selector = members_selector,
443 paginator_name = "voter"
444 }
445 }
446 end
448 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
449 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
450 :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")
451 :add_field("direct_interest_snapshot.weight")
452 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
453 :add_where("direct_supporter_snapshot.satisfied")
454 :add_field("direct_supporter_snapshot.informed", "is_informed")
456 if members_selector:count() > 0 then
457 if issue.fully_frozen then
458 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
459 else
460 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
461 end
463 execute.view{
464 module = "member",
465 view = "_list",
466 params = {
467 initiative = initiative,
468 members_selector = members_selector,
469 paginator_name = "supporters"
470 }
471 }
472 else
473 if issue.fully_frozen then
474 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
475 else
476 ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
477 end
478 slot.put("<br />")
479 end
481 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
482 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
483 :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")
484 :add_field("direct_interest_snapshot.weight")
485 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
486 :add_where("NOT direct_supporter_snapshot.satisfied")
487 :add_field("direct_supporter_snapshot.informed", "is_informed")
489 if members_selector:count() > 0 then
490 if issue.fully_frozen then
491 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
492 else
493 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
494 end
496 execute.view{
497 module = "member",
498 view = "_list",
499 params = {
500 initiative = initiative,
501 members_selector = members_selector,
502 paginator_name = "potential_supporters"
503 }
504 }
505 else
506 if issue.fully_frozen then
507 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
508 else
509 ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
510 end
511 slot.put("<br />")
512 end
514 ui.container{ attr = { class = "heading" }, content = _"Details" }
515 execute.view {
516 module = "initiative",
517 view = "_details",
518 params = {
519 initiative = initiative,
520 members_selector = members_selector
521 }
522 }
524 end
525 end

Impressum / About Us