liquid_feedback_frontend

view app/main/initiative/_show.lua @ 278:fecd4c13054a

Code/css clean up and minor enhancements
author bsw
date Mon Feb 13 01:53:41 2012 +0100 (2012-02-13)
parents f460555c9896
children 808269b7f41c
line source
1 local initiative = param.get("initiative", "table")
2 local initiator = param.get("initiator", "table")
4 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
5 :add_field("initiator.accepted", "accepted")
7 if not (initiator and initiator.accepted) then
8 initiators_members_selector:add_where("initiator.accepted")
9 end
11 local initiators = initiators_members_selector:exec()
14 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
15 slot.select("initiatives_list", function()
16 execute.view{
17 module = "initiative",
18 view = "_list",
19 params = {
20 issue = initiative.issue,
21 initiatives_selector = initiatives_selector,
22 no_sort = true, highlight_initiative = initiative, limit = 3
23 }
24 }
25 end)
27 slot.select("initiative_head", function()
29 ui.container{
30 attr = { class = "initiative_name" },
31 content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
32 }
33 if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
34 ui.tag{
35 attr = { class = "initiator_names" },
36 content = function()
37 ui.tag{ content = _"by" }
38 slot.put(" ")
39 for i, initiator in ipairs(initiators) do
40 if i == #initiators and i > 1 then
41 slot.put(" ", _"and", " ")
42 elseif i > 1 then
43 slot.put(", ")
44 end
45 ui.link{
46 text = initiator.name,
47 module = "member", view = "show", id = initiator.id
48 }
49 end
50 end
51 }
52 end
54 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
55 slot.put(" · ")
56 ui.link{
57 attr = { class = "action" },
58 content = function()
59 slot.put(_"Invite initiator")
60 end,
61 module = "initiative",
62 view = "add_initiator",
63 params = { initiative_id = initiative.id }
64 }
65 if #initiators > 1 then
66 slot.put(" · ")
67 ui.link{
68 content = function()
69 slot.put(_"Remove initiator")
70 end,
71 module = "initiative",
72 view = "remove_initiator",
73 params = { initiative_id = initiative.id }
74 }
75 end
76 end
77 if initiator and initiator.accepted == false then
78 slot.put(" · ")
79 ui.link{
80 text = _"Cancel refuse of invitation",
81 module = "initiative",
82 action = "remove_initiator",
83 params = {
84 initiative_id = initiative.id,
85 member_id = app.session.member.id
86 },
87 routing = {
88 ok = {
89 mode = "redirect",
90 module = "initiative",
91 view = "show",
92 id = initiative.id
93 }
94 }
95 }
96 end
99 end )
101 util.help("initiative.show")
104 if initiative.issue.ranks_available and initiative.admitted then
105 local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
106 ui.container{
107 attr = { class = class },
108 content = function()
109 local max_value = initiative.issue.voter_count
110 slot.put(" ")
111 local positive_votes = initiative.positive_votes
112 local negative_votes = initiative.negative_votes
113 local sum_votes = initiative.positive_votes + initiative.negative_votes
114 local function perc(votes, sum)
115 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
116 return ""
117 end
118 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
119 slot.put(" &middot; ")
120 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
121 slot.put(" &middot; ")
122 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
123 slot.put(" &middot; ")
124 slot.put("<b>")
125 if initiative.rank == 1 then
126 slot.put(_"Approved")
127 elseif initiative.rank then
128 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
129 else
130 slot.put(_"Not approved")
131 end
132 slot.put("</b>")
133 end
134 }
135 end
137 if initiative.admitted == false then
138 local policy = initiative.issue.policy
139 ui.container{
140 attr = { class = "not_admitted_info" },
141 content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
142 }
143 end
145 if initiative.issue.state == "cancelled" then
146 local policy = initiative.issue.policy
147 ui.container{
148 attr = { class = "not_admitted_info" },
149 content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
150 }
151 end
153 if initiative.revoked then
154 ui.container{
155 attr = { class = "revoked_info" },
156 content = function()
157 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
158 local suggested_initiative = initiative.suggested_initiative
159 if suggested_initiative then
160 slot.put("<br /><br />")
161 slot.put(_("The initiators suggest to support the following initiative:"))
162 slot.put(" ")
163 ui.link{
164 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
165 module = "initiative",
166 view = "show",
167 id = suggested_initiative.id
168 }
169 end
170 end
171 }
172 end
174 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
175 ui.container{
176 attr = { class = "initiator_invite_info" },
177 content = function()
178 slot.put(_"You are invited to become initiator of this initiative.")
179 slot.put(" ")
180 ui.link{
181 image = { static = "icons/16/tick.png" },
182 text = _"Accept invitation",
183 module = "initiative",
184 action = "accept_invitation",
185 id = initiative.id,
186 routing = {
187 default = {
188 mode = "redirect",
189 module = request.get_module(),
190 view = request.get_view(),
191 id = param.get_id_cgi(),
192 params = param.get_all_cgi()
193 }
194 }
195 }
196 slot.put(" ")
197 ui.link{
198 image = { static = "icons/16/cross.png" },
199 text = _"Refuse invitation",
200 module = "initiative",
201 action = "reject_initiator_invitation",
202 params = {
203 initiative_id = initiative.id,
204 member_id = app.session.member.id
205 },
206 routing = {
207 default = {
208 mode = "redirect",
209 module = request.get_module(),
210 view = request.get_view(),
211 id = param.get_id_cgi(),
212 params = param.get_all_cgi()
213 }
214 }
215 }
216 end
217 }
218 slot.put("<br />")
219 end
222 local supporter
224 if app.session.member_id then
225 supporter = app.session.member:get_reference_selector("supporters")
226 :add_where{ "initiative_id = ?", initiative.id }
227 :optional_object_mode()
228 :exec()
229 end
231 if supporter and not initiative.issue.closed then
232 local old_draft_id = supporter.draft_id
233 local new_draft_id = initiative.current_draft.id
234 if old_draft_id ~= new_draft_id then
235 ui.container{
236 attr = { class = "draft_updated_info" },
237 content = function()
238 slot.put(_"The draft of this initiative has been updated!")
239 slot.put(" ")
240 ui.link{
241 content = _"Show diff",
242 module = "draft",
243 view = "diff",
244 params = {
245 old_draft_id = old_draft_id,
246 new_draft_id = new_draft_id
247 }
248 }
249 if not initiative.revoked then
250 slot.put(" ")
251 ui.link{
252 text = _"Refresh support to current draft",
253 module = "initiative",
254 action = "add_support",
255 id = initiative.id,
256 routing = {
257 default = {
258 mode = "redirect",
259 module = "initiative",
260 view = "show",
261 id = initiative.id
262 }
263 }
264 }
265 end
266 end
267 }
268 end
269 end
272 if app.session.member_id then
273 execute.view{
274 module = "supporter",
275 view = "_show_box",
276 params = {
277 initiative = initiative
278 }
279 }
280 end
282 execute.view{
283 module = "initiative",
284 view = "show_tab",
285 params = {
286 initiative = initiative,
287 initiator = initiator
288 }
289 }

Impressum / About Us