liquid_feedback_frontend

view app/main/issue/_sidebar_state.lua @ 1060:d6ab5f231178

Fixed error when displaying initiatives in polling mode, made inline help for phases available
author bsw
date Wed Jul 16 21:50:26 2014 +0200 (2014-07-16)
parents 701a5cf6b067
children 86073b9999dc
line source
1 local issue = param.get("issue", "table")
2 local initiative = param.get("initiative", "table")
4 local view_module
5 local view_id
7 if initiative then
8 issue = initiative.issue
9 view_module = "initiative"
10 view_id = initiative.id
11 else
12 view_module = "issue"
13 view_id = issue.id
14 end
16 ui.sidebar( "tab-whatcanido", function()
18 ui.sidebarHead( function()
19 ui.heading{ level = 2, content = function()
20 ui.link{
21 content = issue.name,
22 module = "issue", view = "show", id = issue.id
23 }
24 end }
25 end )
27 local current_occured = false
28 local failed = false
30 for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do
31 local current = state == issue.state
33 if current then
34 current_occured = true
35 end
37 local phase_success = (
38 (state == "admission" and issue.accepted)
39 or (state == "discussion" and issue.half_frozen)
40 or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
41 or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
42 )
44 if not failed then
45 ui.link{ attr = {
46 onclick = "$('#phase-help-" .. state .. "').toggle();return false;",
47 class = "sidebarRow sidebarRowNarrow",
48 }, content = function()
50 local state_names = {
51 admission = _"Admission",
52 discussion = _"Discussion",
53 verification = _"Verification",
54 voting = _"Voting"
55 }
57 local state_name = "(" .. i .. ") " .. state_names[state] or state
59 local function quorum_text(policy, quorum)
60 local num
61 local den
63 if quorum == 1 then
64 num = policy.issue_quorum_num
65 den = policy.issue_quorum_den
66 elseif quorum == 2 then
67 num = policy.initiative_quorum_num
68 den = policy.initiative_quorum_den
69 end
71 if num == nil or den == nil then
72 return 0
73 end
75 if den == 100 or den == 10 then
76 return _("#{percentage}%", { percentage = num * 100 / den })
77 else
78 return num .. "/" .. den
79 end
81 end
83 local quorum
84 if state == "admission" then
85 quorum = quorum_text(issue.policy, 1)
86 elseif state == "verification" then
87 quorum = quorum_text(issue.policy, 2)
88 end
90 if current then
91 local time_left
92 if issue.state_time_left:sub(1,1) ~= "-" then
93 time_left = format.interval_text(issue.state_time_left, { mode = "time_left" })
94 else
95 time_left = "phase ends soon"
96 end
98 ui.tag{ attr = { class = "right" },
99 content = time_left
100 }
101 elseif current_occured then
102 local phase_duration = issue[state .. "_time"]
103 ui.tag{ attr = { class = "right" },
104 content = _("#{duration}", {
105 duration = format.interval_text(phase_duration)
106 } )
107 }
108 else
109 local text = "failed"
110 if quorum then
111 text = _("failed #{quorum}", { quorum = quorum })
112 end
113 if phase_success then
114 if quorum == 0 then
115 text = _"without quorum"
116 elseif quorum then
117 text = _("reached #{quorum}", { quorum = quorum })
118 else
119 text = _"finished"
120 end
121 elseif issue.state == "canceled_revoked_before_accepted" or
122 issue.state == "canceled_after_revocation_during_discussion" or
123 issue.state == "canceled_after_revocation_during_verification"
124 then
125 text = _"revoked"
126 elseif issue.state == "canceled_by_admin" then
127 text = _"canceled"
128 end
130 ui.tag{ attr = { class = "right" },
131 content = text
132 }
133 end
135 ui.heading{ level = 3, content = function()
136 if current then
137 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" }
138 elseif not current_occured and not phase_success then
139 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" }
140 elseif current_occured then
141 ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" }
142 else
143 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" }
144 end
145 slot.put(" ")
146 ui.tag{ content = state_name }
147 end }
149 local help_texts = {
150 admission = _("As soon as one initiative of this issue reaches #{quorum} support, the issue will go into discussion phase.", { quorum = quorum_text(issue.policy, 1) }),
151 discussion = _"During the discussion phase the issue is debated between initiators while the initiatives are improved by suggestions from the supporters.",
152 verification = _("During the verification phase the initiative drafts cannot be changed anymore. Initiatives needs to reach a quorum of #{quorum} to become admitted for voting.", { quorum = quorum_text(issue.policy, 2) }),
153 voting = _"On this issue can be voted now."
154 }
155 ui.container { attr = { id = "phase-help-" .. state, style = "display: none;" }, content = help_texts[state] }
157 end }
158 end
160 if not phase_success and not current and not current_occured then
161 failed = true
162 end
163 end
165 if issue.closed then
166 ui.sidebarSection( function()
167 ui.heading { level = 1, content = issue.state_name }
168 end )
169 if issue.admin_notice then
170 ui.sidebarSection( function()
171 ui.heading { level = 3, content = _"Administrative notice:" }
172 slot.put(encode.html_newlines(issue.admin_notice))
173 end )
174 end
175 end
177 end )

Impressum / About Us