liquid_feedback_frontend

view app/main/initiative/_show.lua @ 493:01cf3c50cbee

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

Impressum / About Us