liquid_feedback_frontend

annotate app/main/initiative/_list_element.lua @ 1084:6c9198d84e7c

merge
author jbe
date Wed Jul 23 23:09:53 2014 +0200 (2014-07-23)
parents 701a5cf6b067
children 904f6807f7fa
rev   line source
bsw/jbe@19 1 local initiative = param.get("initiative", "table")
bsw@1045 2 local for_event = param.get("for_event", atom.boolean)
bsw@1045 3
bsw@1045 4 local issue = initiative.issue
bsw/jbe@19 5
bsw@715 6 local class = "initiative"
bsw/jbe@19 7
bsw@1045 8 if initiative.rank == 1 then
bsw@1045 9 class = class .. " rank1"
bsw@715 10 end
bsw@715 11
bsw@1045 12 if initiative.revoked then
bsw@1045 13 class = class .. " revoked"
bsw@898 14 end
bsw@898 15
bsw@1045 16 ui.container{
bsw@1045 17 attr = { class = class },
bsw@1045 18 content = function ()
bsw@1045 19 if initiative.rank ~= 1 and not for_event then
bsw@1045 20 execute.view {
bsw@1045 21 module = "initiative", view = "_bargraph", params = {
bsw@1045 22 initiative = initiative,
bsw@1045 23 battled_initiative = issue.initiatives[1]
bsw@373 24 }
bsw/jbe@19 25 }
bsw@1045 26 slot.put(" ")
bsw/jbe@19 27 end
bsw@1045 28 ui.tag {
bsw@1045 29 attr = { class = "initiative_name" },
bsw@1045 30 content = function()
bsw@1045 31 ui.link {
bsw@1045 32 text = initiative.display_name,
bsw@1045 33 module = "initiative", view = "show", id = initiative.id
bsw@551 34 }
bsw@1045 35 slot.put(" ")
bsw@1045 36 if initiative.vote_grade ~= nil then
bsw@1045 37 if initiative.vote_grade > 0 then
bsw@1045 38 local text = _"voted yes"
bsw@1045 39 ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" }
bsw@1045 40 elseif initiative.vote_grade == 0 then
bsw@1045 41 elseif initiative.vote_grade < 0 then
bsw@1045 42 local text = _"voted no"
bsw@1045 43 ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/voted_no.png" }
bsw@862 44 end
bsw@1045 45 elseif app.session.member then
bsw@1045 46 if initiative.member_info.supported then
bsw@1045 47 if initiative.member_info.satisfied then
bsw@1045 48 local text = _"supporter"
bsw@1045 49 ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" }
bsw@1045 50 else
bsw@1045 51 local text = _"supporter with restricting suggestions"
bsw@1045 52 ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_unsatisfied.png" }
bsw@1045 53 end
bsw@862 54 end
bsw@556 55 end
bsw@551 56 end
bsw@1045 57 }
bsw@1045 58
bsw@556 59 end
bsw@1045 60 }
bsw@1045 61
bsw@1045 62 if initiative.rank == 1
bsw@1045 63 and issue.voter_count
bsw@1045 64 and initiative.positive_votes ~= nil
bsw@1045 65 and initiative.negative_votes ~= nil
bsw@1045 66 and not for_event
bsw@1045 67 then
bsw@1045 68 function percent(p, q)
bsw@1045 69 if q > 0 then
bsw@1045 70 return math.floor(p / q * 100) .. "%"
bsw@1045 71 else
bsw@1045 72 return "0%"
bsw@373 73 end
bsw@1045 74 end
bsw@1045 75 local result = ""
bsw@1045 76 if initiative.eligible then
bsw@1045 77 result = _("Reached #{sign}#{num}/#{den}", {
bsw@1045 78 sign = issue.policy.direct_majority_strict and ">" or "≥",
bsw@1045 79 num = issue.policy.direct_majority_num,
bsw@1045 80 den = issue.policy.direct_majority_den
bsw@1045 81 })
bsw@1045 82 else
bsw@1045 83 result = _("Failed #{sign}#{num}/#{den}", {
bsw@1045 84 sign = issue.policy.direct_majority_strict and ">" or "≥",
bsw@1045 85 num = issue.policy.direct_majority_num,
bsw@1045 86 den = issue.policy.direct_majority_den
bsw@1045 87 })
bsw@1045 88 end
bsw@1045 89 local neutral_count = issue.voter_count - initiative.positive_votes - initiative.negative_votes
bsw@1045 90
bsw@1045 91 local result_text
bsw@1045 92
bsw@1045 93 if issue.voter_count > 0 then
bsw@1045 94 result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", {
bsw@1045 95 result = result,
bsw@1045 96 yes_count = initiative.positive_votes,
bsw@1045 97 yes_percent = percent(initiative.positive_votes, issue.voter_count),
bsw@1045 98 neutral_count = neutral_count,
bsw@1045 99 neutral_percent = percent(neutral_count, issue.voter_count),
bsw@1045 100 no_count = initiative.negative_votes,
bsw@1045 101 no_percent = percent(initiative.negative_votes, issue.voter_count)
bsw@1045 102 })
bsw@1045 103 else
bsw@1045 104 result_text = _("#{result}: No votes (0)", { result = result })
bsw@1045 105 end
bsw@1045 106
bsw@1045 107 ui.container { attr = { class = "result" }, content = result_text }
bsw@373 108
bsw@1045 109 end
bsw@1045 110

Impressum / About Us