liquid_feedback_frontend

view app/main/initiative/_show.lua @ 275:fc14e76afe31

Made filter better useable
author bsw
date Sun Feb 12 13:42:08 2012 +0100 (2012-02-12)
parents aec9df5b4cd3
children f460555c9896
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 ui.tag{
34 attr = { class = "initiator_names" },
35 content = function()
36 ui.tag{ content = _"by" }
37 slot.put(" ")
38 for i, initiator in ipairs(initiators) do
39 if i == #initiators and i > 1 then
40 slot.put(" ", _"and", " ")
41 elseif i > 1 then
42 slot.put(", ")
43 end
44 ui.link{
45 text = initiator.name,
46 module = "member", view = "show", id = initiator.id
47 }
48 end
49 end
50 }
52 if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
53 slot.put(" · ")
54 ui.link{
55 attr = { class = "action" },
56 content = function()
57 slot.put(_"Invite initiator")
58 end,
59 module = "initiative",
60 view = "add_initiator",
61 params = { initiative_id = initiative.id }
62 }
63 if #initiators > 1 then
64 slot.put(" · ")
65 ui.link{
66 content = function()
67 slot.put(_"Remove initiator")
68 end,
69 module = "initiative",
70 view = "remove_initiator",
71 params = { initiative_id = initiative.id }
72 }
73 end
74 end
75 if initiator and initiator.accepted == false then
76 slot.put(" · ")
77 ui.link{
78 text = _"Cancel refuse of invitation",
79 module = "initiative",
80 action = "remove_initiator",
81 params = {
82 initiative_id = initiative.id,
83 member_id = app.session.member.id
84 },
85 routing = {
86 ok = {
87 mode = "redirect",
88 module = "initiative",
89 view = "show",
90 id = initiative.id
91 }
92 }
93 }
94 end
97 end )
99 util.help("initiative.show")
102 if initiative.issue.ranks_available and initiative.admitted then
103 local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
104 ui.container{
105 attr = { class = class },
106 content = function()
107 local max_value = initiative.issue.voter_count
108 slot.put(" ")
109 local positive_votes = initiative.positive_votes
110 local negative_votes = initiative.negative_votes
111 local sum_votes = initiative.positive_votes + initiative.negative_votes
112 local function perc(votes, sum)
113 if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
114 return ""
115 end
116 slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
117 slot.put(" &middot; ")
118 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>")
119 slot.put(" &middot; ")
120 slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
121 slot.put(" &middot; ")
122 slot.put("<b>")
123 if initiative.rank == 1 then
124 slot.put(_"Approved")
125 elseif initiative.rank then
126 slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
127 else
128 slot.put(_"Not approved")
129 end
130 slot.put("</b>")
131 end
132 }
133 end
135 if initiative.admitted == false then
136 local policy = initiative.issue.policy
137 ui.container{
138 attr = { class = "not_admitted_info" },
139 content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
140 }
141 end
143 local web20 = config.user_tab_mode == "accordeon"
144 or config.user_tab_mode == "accordeon_first_expanded"
145 or config.user_tab_mode == "accordeon_all_expanded"
147 if not web20 and initiative.issue.state == "cancelled" then
148 local policy = initiative.issue.policy
149 ui.container{
150 attr = { class = "not_admitted_info" },
151 content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
152 }
153 end
155 if initiative.revoked then
156 ui.container{
157 attr = { class = "revoked_info" },
158 content = function()
159 slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
160 local suggested_initiative = initiative.suggested_initiative
161 if suggested_initiative then
162 slot.put("<br /><br />")
163 slot.put(_("The initiators suggest to support the following initiative:"))
164 slot.put(" ")
165 ui.link{
166 content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
167 module = "initiative",
168 view = "show",
169 id = suggested_initiative.id
170 }
171 end
172 end
173 }
174 end
176 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
177 ui.container{
178 attr = { class = "initiator_invite_info" },
179 content = function()
180 slot.put(_"You are invited to become initiator of this initiative.")
181 slot.put(" ")
182 ui.link{
183 image = { static = "icons/16/tick.png" },
184 text = _"Accept invitation",
185 module = "initiative",
186 action = "accept_invitation",
187 id = initiative.id,
188 routing = {
189 default = {
190 mode = "redirect",
191 module = request.get_module(),
192 view = request.get_view(),
193 id = param.get_id_cgi(),
194 params = param.get_all_cgi()
195 }
196 }
197 }
198 slot.put(" ")
199 ui.link{
200 image = { static = "icons/16/cross.png" },
201 text = _"Refuse invitation",
202 module = "initiative",
203 action = "reject_initiator_invitation",
204 params = {
205 initiative_id = initiative.id,
206 member_id = app.session.member.id
207 },
208 routing = {
209 default = {
210 mode = "redirect",
211 module = request.get_module(),
212 view = request.get_view(),
213 id = param.get_id_cgi(),
214 params = param.get_all_cgi()
215 }
216 }
217 }
218 end
219 }
220 slot.put("<br />")
221 end
224 local supporter
226 if app.session.member_id then
227 supporter = app.session.member:get_reference_selector("supporters")
228 :add_where{ "initiative_id = ?", initiative.id }
229 :optional_object_mode()
230 :exec()
231 end
233 if supporter and not initiative.issue.closed then
234 local old_draft_id = supporter.draft_id
235 local new_draft_id = initiative.current_draft.id
236 if old_draft_id ~= new_draft_id then
237 ui.container{
238 attr = { class = "draft_updated_info" },
239 content = function()
240 slot.put(_"The draft of this initiative has been updated!")
241 slot.put(" ")
242 ui.link{
243 content = _"Show diff",
244 module = "draft",
245 view = "diff",
246 params = {
247 old_draft_id = old_draft_id,
248 new_draft_id = new_draft_id
249 }
250 }
251 if not initiative.revoked then
252 slot.put(" ")
253 ui.link{
254 text = _"Refresh support to current draft",
255 module = "initiative",
256 action = "add_support",
257 id = initiative.id,
258 routing = {
259 default = {
260 mode = "redirect",
261 module = "initiative",
262 view = "show",
263 id = initiative.id
264 }
265 }
266 }
267 end
268 end
269 }
270 end
271 end
274 if app.session.member_id then
275 ui.container{
276 attr = {
277 id = "initiative_" .. tostring(initiative.id) .. "_support"
278 },
279 content = function()
280 execute.view{
281 module = "initiative",
282 view = "show_support",
283 params = {
284 initiative = initiative
285 }
286 }
287 end
288 }
289 end
292 execute.view{
293 module = "initiative",
294 view = "show_tab",
295 params = {
296 initiative = initiative,
297 initiator = initiator
298 }
299 }

Impressum / About Us