liquid_feedback_frontend

annotate app/main/issue/_sidebar_state.lua @ 1101:b18e198c2624

Show administrative notice in any case as long as a message is set
author bsw
date Mon Oct 27 12:03:54 2014 +0100 (2014-10-27)
parents 86073b9999dc
children 9578cef4018a
rev   line source
bsw@1045 1 local issue = param.get("issue", "table")
bsw@1045 2 local initiative = param.get("initiative", "table")
bsw@1045 3
bsw@1045 4 local view_module
bsw@1045 5 local view_id
bsw@1045 6
bsw@1045 7 if initiative then
bsw@1045 8 issue = initiative.issue
bsw@1045 9 view_module = "initiative"
bsw@1045 10 view_id = initiative.id
bsw@1045 11 else
bsw@1045 12 view_module = "issue"
bsw@1045 13 view_id = issue.id
bsw@1045 14 end
bsw@1045 15
bsw@1045 16 ui.sidebar( "tab-whatcanido", function()
bsw@1045 17
bsw@1045 18 ui.sidebarHead( function()
bsw@1045 19 ui.heading{ level = 2, content = function()
bsw@1045 20 ui.link{
bsw@1045 21 content = issue.name,
bsw@1045 22 module = "issue", view = "show", id = issue.id
bsw@1045 23 }
bsw@1045 24 end }
bsw@1045 25 end )
bsw@1045 26
bsw@1045 27 local current_occured = false
bsw@1045 28 local failed = false
bsw@1045 29
bsw@1045 30 for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do
bsw@1045 31 local current = state == issue.state
bsw@1045 32
bsw@1045 33 if current then
bsw@1045 34 current_occured = true
bsw@1045 35 end
bsw@1045 36
bsw@1045 37 local phase_success = (
bsw@1045 38 (state == "admission" and issue.accepted)
bsw@1045 39 or (state == "discussion" and issue.half_frozen)
bsw@1045 40 or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
bsw@1045 41 or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
bsw@1045 42 )
bsw@1045 43
bsw@1045 44 if not failed then
bsw@1060 45 ui.link{ attr = {
bsw@1060 46 onclick = "$('#phase-help-" .. state .. "').toggle();return false;",
bsw@1060 47 class = "sidebarRow sidebarRowNarrow",
bsw@1060 48 }, content = function()
bsw@1045 49
bsw@1045 50 local state_names = {
bsw@1045 51 admission = _"Admission",
bsw@1045 52 discussion = _"Discussion",
bsw@1045 53 verification = _"Verification",
bsw@1045 54 voting = _"Voting"
bsw@1045 55 }
bsw@1045 56
bsw@1045 57 local state_name = "(" .. i .. ") " .. state_names[state] or state
bsw@1045 58
bsw@1045 59 local function quorum_text(policy, quorum)
bsw@1045 60 local num
bsw@1045 61 local den
bsw@1045 62
bsw@1045 63 if quorum == 1 then
bsw@1045 64 num = policy.issue_quorum_num
bsw@1045 65 den = policy.issue_quorum_den
bsw@1045 66 elseif quorum == 2 then
bsw@1045 67 num = policy.initiative_quorum_num
bsw@1045 68 den = policy.initiative_quorum_den
bsw@1045 69 end
bsw@1045 70
bsw@1060 71 if num == nil or den == nil then
bsw@1060 72 return 0
bsw@1060 73 end
bsw@1060 74
bsw@1060 75 if den == 100 or den == 10 then
bsw@1060 76 return _("#{percentage}%", { percentage = num * 100 / den })
bsw@1045 77 else
bsw@1045 78 return num .. "/" .. den
bsw@1045 79 end
bsw@1045 80
bsw@1045 81 end
bsw@1045 82
bsw@1045 83 local quorum
bsw@1045 84 if state == "admission" then
bsw@1045 85 quorum = quorum_text(issue.policy, 1)
bsw@1045 86 elseif state == "verification" then
bsw@1045 87 quorum = quorum_text(issue.policy, 2)
bsw@1045 88 end
bsw@1045 89
bsw@1045 90 if current then
bsw@1045 91 local time_left
bsw@1045 92 if issue.state_time_left:sub(1,1) ~= "-" then
bsw@1045 93 time_left = format.interval_text(issue.state_time_left, { mode = "time_left" })
bsw@1045 94 else
bsw@1045 95 time_left = "phase ends soon"
bsw@1045 96 end
bsw@1045 97
bsw@1045 98 ui.tag{ attr = { class = "right" },
bsw@1045 99 content = time_left
bsw@1045 100 }
bsw@1045 101 elseif current_occured then
bsw@1045 102 local phase_duration = issue[state .. "_time"]
bsw@1045 103 ui.tag{ attr = { class = "right" },
bsw@1045 104 content = _("#{duration}", {
bsw@1045 105 duration = format.interval_text(phase_duration)
bsw@1045 106 } )
bsw@1045 107 }
bsw@1045 108 else
bsw@1045 109 local text = "failed"
bsw@1045 110 if quorum then
bsw@1045 111 text = _("failed #{quorum}", { quorum = quorum })
bsw@1045 112 end
bsw@1045 113 if phase_success then
bsw@1060 114 if quorum == 0 then
bsw@1060 115 text = _"without quorum"
bsw@1060 116 elseif quorum then
bsw@1045 117 text = _("reached #{quorum}", { quorum = quorum })
bsw@1045 118 else
bsw@1045 119 text = _"finished"
bsw@1045 120 end
bsw@1045 121 elseif issue.state == "canceled_revoked_before_accepted" or
bsw@1045 122 issue.state == "canceled_after_revocation_during_discussion" or
bsw@1045 123 issue.state == "canceled_after_revocation_during_verification"
bsw@1045 124 then
bsw@1045 125 text = _"revoked"
bsw@1045 126 elseif issue.state == "canceled_by_admin" then
bsw@1045 127 text = _"canceled"
bsw@1045 128 end
bsw@1045 129
bsw@1045 130 ui.tag{ attr = { class = "right" },
bsw@1045 131 content = text
bsw@1045 132 }
bsw@1045 133 end
bsw@1045 134
bsw@1045 135 ui.heading{ level = 3, content = function()
bsw@1045 136 if current then
bsw@1045 137 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" }
bsw@1045 138 elseif not current_occured and not phase_success then
bsw@1045 139 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" }
bsw@1045 140 elseif current_occured then
bsw@1045 141 ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" }
bsw@1045 142 else
bsw@1045 143 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" }
bsw@1045 144 end
bsw@1045 145 slot.put(" ")
bsw@1045 146 ui.tag{ content = state_name }
bsw@1045 147 end }
bsw@1060 148
bsw@1045 149 local help_texts = {
bsw@1081 150 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 151 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 152 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 153 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 154 }
bsw@1060 155 ui.container { attr = { id = "phase-help-" .. state, style = "display: none;" }, content = help_texts[state] }
bsw@1045 156
bsw@1060 157 end }
bsw@1045 158 end
bsw@1045 159
bsw@1045 160 if not phase_success and not current and not current_occured then
bsw@1045 161 failed = true
bsw@1045 162 end
bsw@1045 163 end
bsw@1045 164
bsw@1045 165 if issue.closed then
bsw@1045 166 ui.sidebarSection( function()
bsw@1045 167 ui.heading { level = 1, content = issue.state_name }
bsw@1045 168 end )
bsw@1045 169 end
bsw@1045 170
bsw@1101 171 if issue.admin_notice then
bsw@1101 172 ui.sidebarSection( function()
bsw@1101 173 ui.heading { level = 3, content = _"Administrative notice:" }
bsw@1101 174 slot.put(encode.html_newlines(issue.admin_notice))
bsw@1101 175 end )
bsw@1101 176 end
bsw@1045 177 end )

Impressum / About Us