bsw/jbe@19: local initiative = param.get("initiative", "table") bsw@1045: local for_event = param.get("for_event", atom.boolean) bsw@1045: bsw@1045: local issue = initiative.issue bsw/jbe@19: bsw@715: local class = "initiative" bsw/jbe@19: bsw@1045: if initiative.rank == 1 then bsw@1045: class = class .. " rank1" bsw@715: end bsw@715: bsw@1045: if initiative.revoked then bsw@1045: class = class .. " revoked" bsw@898: end bsw@898: bsw@1045: ui.container{ bsw@1045: attr = { class = class }, bsw@1045: content = function () bsw@1045: if initiative.rank ~= 1 and not for_event then bsw@1045: execute.view { bsw@1045: module = "initiative", view = "_bargraph", params = { bsw@1045: initiative = initiative, bsw@1045: battled_initiative = issue.initiatives[1] bsw@373: } bsw/jbe@19: } bsw@1045: slot.put(" ") bsw/jbe@19: end bsw@1045: ui.tag { bsw@1045: attr = { class = "initiative_name" }, bsw@1045: content = function() bsw@1045: ui.link { bsw@1045: text = initiative.display_name, bsw@1045: module = "initiative", view = "show", id = initiative.id bsw@551: } bsw@1045: slot.put(" ") bsw@1045: if initiative.vote_grade ~= nil then bsw@1045: if initiative.vote_grade > 0 then bsw@1045: local text = _"voted yes" bsw@1045: ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" } bsw@1045: elseif initiative.vote_grade == 0 then bsw@1045: elseif initiative.vote_grade < 0 then bsw@1045: local text = _"voted no" bsw@1045: ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/voted_no.png" } bsw@862: end bsw@1045: elseif app.session.member then bsw@1045: if initiative.member_info.supported then bsw@1045: if initiative.member_info.satisfied then bsw@1045: local text = _"supporter" bsw@1045: ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" } bsw@1045: else bsw@1045: local text = _"supporter with restricting suggestions" bsw@1045: ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_unsatisfied.png" } bsw@1045: end bsw@862: end bsw@556: end bsw@551: end bsw@1045: } bsw@1045: bsw@556: end bsw@1045: } bsw@1045: bsw@1045: if initiative.rank == 1 bsw@1045: and issue.voter_count bsw@1045: and initiative.positive_votes ~= nil bsw@1045: and initiative.negative_votes ~= nil bsw@1045: and not for_event bsw@1045: then bsw@1045: function percent(p, q) bsw@1045: if q > 0 then bsw@1045: return math.floor(p / q * 100) .. "%" bsw@1045: else bsw@1045: return "0%" bsw@373: end bsw@1045: end bsw@1045: local result = "" bsw@1045: if initiative.eligible then bsw@1045: result = _("Reached #{sign}#{num}/#{den}", { bsw@1045: sign = issue.policy.direct_majority_strict and ">" or "≥", bsw@1045: num = issue.policy.direct_majority_num, bsw@1045: den = issue.policy.direct_majority_den bsw@1045: }) bsw@1045: else bsw@1045: result = _("Failed #{sign}#{num}/#{den}", { bsw@1045: sign = issue.policy.direct_majority_strict and ">" or "≥", bsw@1045: num = issue.policy.direct_majority_num, bsw@1045: den = issue.policy.direct_majority_den bsw@1045: }) bsw@1045: end bsw@1045: local neutral_count = issue.voter_count - initiative.positive_votes - initiative.negative_votes bsw@1045: bsw@1045: local result_text bsw@1045: bsw@1045: if issue.voter_count > 0 then bsw@1045: result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", { bsw@1045: result = result, bsw@1045: yes_count = initiative.positive_votes, bsw@1045: yes_percent = percent(initiative.positive_votes, issue.voter_count), bsw@1045: neutral_count = neutral_count, bsw@1045: neutral_percent = percent(neutral_count, issue.voter_count), bsw@1045: no_count = initiative.negative_votes, bsw@1045: no_percent = percent(initiative.negative_votes, issue.voter_count) bsw@1045: }) bsw@1045: else bsw@1045: result_text = _("#{result}: No votes (0)", { result = result }) bsw@1045: end bsw@1045: bsw@1045: ui.container { attr = { class = "result" }, content = result_text } bsw@373: bsw@1045: end bsw@1045: