liquid_feedback_frontend

view app/main/initiative/_show.lua @ 525:63d6549cc00b

Delegation chain preview improved, better visualisation of current context, code cleanup
author bsw
date Fri May 18 19:07:07 2012 +0200 (2012-05-18)
parents 01cf3c50cbee
children 4cee33ad5e16
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("head", function()
18 execute.view{
19 module = "issue",
20 view = "_show",
21 params = {
22 issue = initiative.issue,
23 initiative_limit = 3
24 }
25 }
26 end)
28 ui.container{ attr = { class = "initiative_head" }, content = function()
30 ui.container{
31 attr = { class = "title" },
32 content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
33 }
35 ui.container{ attr = { class = "content" }, content = function()
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 end }
117 ui.container{ attr = { class = "content" }, content = function()
118 if app.session.member_id then
119 execute.view{
120 module = "supporter",
121 view = "_show_box",
122 params = {
123 initiative = initiative
124 }
125 }
126 end
128 end }
130 end }
133 util.help("initiative.show")
135 --slot.select("initiative_head", function()
137 if initiative.issue.ranks_available and initiative.admitted then
138 local class = initiative.winner and "admitted_info" or "not_admitted_info"
139 ui.container{
140 attr = { class = class },
141 content = function()
142 local max_value = initiative.issue.voter_count
143 slot.put(" ")
144 local positive_votes = initiative.positive_votes
145 local negative_votes = initiative.negative_votes
146 local sum_votes = initiative.positive_votes + initiative.negative_votes
147 local function perc(votes, sum)
148 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
149 return ""
150 end
151 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
152 slot.put(" &middot; ")
153 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
154 slot.put(" &middot; ")
155 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
156 slot.put(" &middot; ")
157 slot.put("<b>")
158 if initiative.winner then
159 slot.put(_"Approved")
160 elseif initiative.rank then
161 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
162 else
163 slot.put(_"Not approved")
164 end
165 slot.put("</b>")
166 end
167 }
168 end
170 if initiative.admitted == false then
171 local policy = initiative.issue.policy
172 ui.container{
173 attr = { class = "not_admitted_info" },
174 content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
175 }
176 end
178 if initiative.revoked then
179 ui.container{
180 attr = { class = "revoked_info" },
181 content = function()
182 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
183 local suggested_initiative = initiative.suggested_initiative
184 if suggested_initiative then
185 slot.put("<br /><br />")
186 slot.put(_("The initiators suggest to support the following initiative:"))
187 slot.put(" ")
188 ui.link{
189 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
190 module = "initiative",
191 view = "show",
192 id = suggested_initiative.id
193 }
194 end
195 end
196 }
197 end
199 if initiative.issue.state == "cancelled" then
200 local policy = initiative.issue.policy
201 ui.container{
202 attr = { class = "not_admitted_info" },
203 content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
204 }
205 end
206 --end)
208 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
209 ui.container{
210 attr = { class = "initiator_invite_info" },
211 content = function()
212 slot.put(_"You are invited to become initiator of this initiative.")
213 slot.put(" ")
214 ui.link{
215 image = { static = "icons/16/tick.png" },
216 text = _"Accept invitation",
217 module = "initiative",
218 action = "accept_invitation",
219 id = initiative.id,
220 routing = {
221 default = {
222 mode = "redirect",
223 module = request.get_module(),
224 view = request.get_view(),
225 id = param.get_id_cgi(),
226 params = param.get_all_cgi()
227 }
228 }
229 }
230 slot.put(" ")
231 ui.link{
232 image = { static = "icons/16/cross.png" },
233 text = _"Refuse invitation",
234 module = "initiative",
235 action = "reject_initiator_invitation",
236 params = {
237 initiative_id = initiative.id,
238 member_id = app.session.member.id
239 },
240 routing = {
241 default = {
242 mode = "redirect",
243 module = request.get_module(),
244 view = request.get_view(),
245 id = param.get_id_cgi(),
246 params = param.get_all_cgi()
247 }
248 }
249 }
250 end
251 }
252 slot.put("<br />")
253 end
256 local supporter
258 if app.session.member_id then
259 supporter = app.session.member:get_reference_selector("supporters")
260 :add_where{ "initiative_id = ?", initiative.id }
261 :optional_object_mode()
262 :exec()
263 end
265 if supporter and not initiative.issue.closed then
266 local old_draft_id = supporter.draft_id
267 local new_draft_id = initiative.current_draft.id
268 if old_draft_id ~= new_draft_id then
269 ui.container{
270 attr = { class = "draft_updated_info" },
271 content = function()
272 slot.put(_"The draft of this initiative has been updated!")
273 slot.put(" ")
274 ui.link{
275 content = _"Show diff",
276 module = "draft",
277 view = "diff",
278 params = {
279 old_draft_id = old_draft_id,
280 new_draft_id = new_draft_id
281 }
282 }
283 if not initiative.revoked then
284 slot.put(" ")
285 ui.link{
286 text = _"Refresh support to current draft",
287 module = "initiative",
288 action = "add_support",
289 id = initiative.id,
290 routing = {
291 default = {
292 mode = "redirect",
293 module = "initiative",
294 view = "show",
295 id = initiative.id
296 }
297 }
298 }
299 end
300 end
301 }
302 end
303 end
305 execute.view{
306 module = "initiative",
307 view = "show_tab",
308 params = {
309 initiative = initiative,
310 initiator = initiator
311 }
312 }
314 if initiative.issue.snapshot then
315 slot.put("<br />")
316 ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
317 end

Impressum / About Us