bsw@1045: local issue = param.get("issue", "table") bsw@1045: local initiative = param.get("initiative", "table") bsw@1045: bsw@1045: local view_module bsw@1045: local view_id bsw@1045: bsw@1045: if initiative then bsw@1045: issue = initiative.issue bsw@1045: view_module = "initiative" bsw@1045: view_id = initiative.id bsw@1045: else bsw@1045: view_module = "issue" bsw@1045: view_id = issue.id bsw@1045: end bsw@1045: bsw@1045: ui.sidebar( "tab-whatcanido", function() bsw@1045: bsw@1045: ui.sidebarHead( function() bsw@1045: ui.heading{ level = 2, content = function() bsw@1045: ui.link{ bsw@1045: content = issue.name, bsw@1045: module = "issue", view = "show", id = issue.id bsw@1045: } bsw@1045: end } bsw@1045: end ) bsw@1045: bsw@1045: local current_occured = false bsw@1045: local failed = false bsw@1045: bsw@1045: for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do bsw@1045: local current = state == issue.state bsw@1045: bsw@1045: if current then bsw@1045: current_occured = true bsw@1045: end bsw@1045: bsw@1045: local phase_success = ( bsw@1045: (state == "admission" and issue.accepted) bsw@1045: or (state == "discussion" and issue.half_frozen) bsw@1045: or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted") bsw@1045: or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin") bsw@1045: ) bsw@1045: bsw@1045: if not failed then bsw@1060: ui.link{ attr = { bsw@1060: onclick = "$('#phase-help-" .. state .. "').toggle();return false;", bsw@1060: class = "sidebarRow sidebarRowNarrow", bsw@1060: }, content = function() bsw@1045: bsw@1045: local state_names = { bsw@1045: admission = _"Admission", bsw@1045: discussion = _"Discussion", bsw@1045: verification = _"Verification", bsw@1045: voting = _"Voting" bsw@1045: } bsw@1045: bsw@1045: local state_name = "(" .. i .. ") " .. state_names[state] or state bsw@1045: bsw@1045: local function quorum_text(policy, quorum) bsw@1045: local num bsw@1045: local den bsw@1045: bsw@1045: if quorum == 1 then bsw@1045: num = policy.issue_quorum_num bsw@1045: den = policy.issue_quorum_den bsw@1045: elseif quorum == 2 then bsw@1045: num = policy.initiative_quorum_num bsw@1045: den = policy.initiative_quorum_den bsw@1045: end bsw@1045: bsw@1060: if num == nil or den == nil then bsw@1060: return 0 bsw@1060: end bsw@1060: bsw@1060: if den == 100 or den == 10 then bsw@1060: return _("#{percentage}%", { percentage = num * 100 / den }) bsw@1045: else bsw@1045: return num .. "/" .. den bsw@1045: end bsw@1045: bsw@1045: end bsw@1045: bsw@1045: local quorum bsw@1045: if state == "admission" then bsw@1045: quorum = quorum_text(issue.policy, 1) bsw@1045: elseif state == "verification" then bsw@1045: quorum = quorum_text(issue.policy, 2) bsw@1045: end bsw@1045: bsw@1045: if current then bsw@1045: local time_left bsw@1045: if issue.state_time_left:sub(1,1) ~= "-" then bsw@1045: time_left = format.interval_text(issue.state_time_left, { mode = "time_left" }) bsw@1045: else bsw@1045: time_left = "phase ends soon" bsw@1045: end bsw@1045: bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = time_left bsw@1045: } bsw@1045: elseif current_occured then bsw@1245: local phase_duration = issue[state .. "_time_text"] bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = _("#{duration}", { bsw@1045: duration = format.interval_text(phase_duration) bsw@1045: } ) bsw@1045: } bsw@1045: else bsw@1045: local text = "failed" bsw@1045: if quorum then bsw@1045: text = _("failed #{quorum}", { quorum = quorum }) bsw@1045: end bsw@1045: if phase_success then bsw@1060: if quorum == 0 then bsw@1060: text = _"without quorum" bsw@1060: elseif quorum then bsw@1045: text = _("reached #{quorum}", { quorum = quorum }) bsw@1045: else bsw@1045: text = _"finished" bsw@1045: end bsw@1045: elseif issue.state == "canceled_revoked_before_accepted" or bsw@1045: issue.state == "canceled_after_revocation_during_discussion" or bsw@1045: issue.state == "canceled_after_revocation_during_verification" bsw@1045: then bsw@1045: text = _"revoked" bsw@1045: elseif issue.state == "canceled_by_admin" then bsw@1045: text = _"canceled" bsw@1045: end bsw@1045: bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = text bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: ui.heading{ level = 3, content = function() bsw@1045: if current then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" } bsw@1045: elseif not current_occured and not phase_success then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" } bsw@1045: elseif current_occured then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" } bsw@1045: else bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" } bsw@1045: end bsw@1045: slot.put(" ") bsw@1045: ui.tag{ content = state_name } bsw@1045: end } bsw@1060: bsw@1045: local help_texts = { bsw@1081: admission = _("As soon as one initiative of this issue reaches the 1st quorum of #{quorum} support, the issue will proceed to discussion phase.", { quorum = quorum_text(issue.policy, 1) }), bsw@1081: discussion = _"During the discussion phase, the issue is debated on while the initiators improve the proposals and reasons in their initiatives. Supporters of initiatives can write and rate suggestions for improvement.", bsw@1081: verification = _("During the verification phase, existing initiatives cannot be changed anymore. Initiatives need to pass the 2nd quorum of #{quorum} at end of verification phase to become admitted for voting.", { quorum = quorum_text(issue.policy, 2) }), bsw@1081: voting = _"During the voting phase, votes for all admitted initiatives in this issue can be cast. The final result will be calculated as soon as this phase ends." bsw@1045: } bsw@1060: ui.container { attr = { id = "phase-help-" .. state, style = "display: none;" }, content = help_texts[state] } bsw@1045: bsw@1060: end } bsw@1045: end bsw@1045: bsw@1045: if not phase_success and not current and not current_occured then bsw@1045: failed = true bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: if issue.closed then bsw@1045: ui.sidebarSection( function() bsw@1045: ui.heading { level = 1, content = issue.state_name } bsw@1045: end ) bsw@1045: end bsw@1045: bsw@1101: if issue.admin_notice then bsw@1101: ui.sidebarSection( function() bsw@1101: ui.heading { level = 3, content = _"Administrative notice:" } bsw@1101: slot.put(encode.html_newlines(issue.admin_notice)) bsw@1101: end ) bsw@1101: end bsw@1245: end )