liquid_feedback_frontend

view app/main/delegation/show.lua @ 570:b904fc12cc1a

Show only units with voting privilege in member_home page
author bsw
date Tue Jun 19 23:18:39 2012 +0200 (2012-06-19)
parents 774d8804ce65
children e7baf2713987
line source
1 local voting_right_unit_id
2 local current_trustee_id
3 local current_trustee_name
5 local unit = Unit:by_id(param.get("unit_id", atom.integer))
6 if unit then
7 unit:load_delegation_info_once_for_member_id(app.session.member_id)
8 voting_right_unit_id = unit.id
9 if unit.delegation_info.own_delegation_scope == 'unit' then
10 current_trustee_id = unit.delegation_info.first_trustee_id
11 current_trustee_name = unit.delegation_info.first_trustee_name
12 end
13 ui.title(config.single_unit_id and _"Set global delegation" or _"Set unit delegation")
14 util.help("delegation.new.unit")
15 end
17 local area = Area:by_id(param.get("area_id", atom.integer))
18 if area then
19 area:load_delegation_info_once_for_member_id(app.session.member_id)
20 voting_right_unit_id = area.unit_id
21 if area.delegation_info.own_delegation_scope == 'area' then
22 current_trustee_id = area.delegation_info.first_trustee_id
23 current_trustee_name = area.delegation_info.first_trustee_name
24 end
25 ui.title(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name))
26 util.help("delegation.new.area")
27 end
29 local issue = Issue:by_id(param.get("issue_id", atom.integer))
30 if issue then
31 issue:load("member_info", { member_id = app.session.member_id })
32 voting_right_unit_id = issue.area.unit_id
33 if issue.member_info.own_delegation_scope == 'issue' then
34 current_trustee_id = issue.member_info.first_trustee_id
35 current_trustee_name = issue.member_info.first_trustee_name
36 end
37 ui.title(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name))
38 util.help("delegation.new.issue")
39 end
41 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
43 local contact_members = Member:build_selector{
44 is_contact_of_member_id = app.session.member_id,
45 voting_right_for_unit_id = voting_right_unit_id,
46 active = true,
47 order = "name"
48 }:exec()
50 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
52 ui.script{ static = "js/update_delegation_info.js" }
54 slot.select("actions", function()
55 if issue then
56 ui.link{
57 module = "issue",
58 view = "show",
59 id = issue.id,
60 content = function()
61 ui.image{ static = "icons/16/cancel.png" }
62 slot.put(_"Cancel")
63 end,
64 }
65 elseif area then
66 ui.link{
67 module = "area",
68 view = "show",
69 id = area.id,
70 content = function()
71 ui.image{ static = "icons/16/cancel.png" }
72 slot.put(_"Cancel")
73 end,
74 }
75 else
76 ui.link{
77 module = "index",
78 view = "index",
79 content = function()
80 ui.image{ static = "icons/16/cancel.png" }
81 slot.put(_"Cancel")
82 end,
83 }
84 end
85 end)
88 ui.form{
89 attr = { class = "vertical", id = "delegationForm" },
90 module = "delegation",
91 action = "update",
92 params = {
93 unit_id = unit and unit.id or nil,
94 area_id = area and area.id or nil,
95 issue_id = issue and issue.id or nil,
96 },
97 routing = {
98 default = {
99 mode = "redirect",
100 module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
101 view = "show",
102 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
103 }
104 },
105 content = function()
106 local records
108 if issue then
109 local delegate_name = ""
110 local scope = "no delegation set"
111 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
112 if area_delegation then
113 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
114 scope = _"area"
115 else
116 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
117 if unit_delegation then
118 delegate_name = unit_delegation.trustee.name
119 scope = config.single_unit_id and _"global" or _"unit"
120 end
121 end
122 local text_apply
123 local text_abandon
124 if config.single_unit_id then
125 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
126 text_abandon = _"Abandon unit and area delegations for this issue"
127 else
128 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
129 text_abandon = _"Abandon unit and area delegations for this issue"
130 end
131 records = {
132 { id = -1, name = text_apply },
133 { id = 0, name = text_abandon }
134 }
135 elseif area then
136 local delegate_name = ""
137 local scope = "no delegation set"
138 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
139 if unit_delegation then
140 delegate_name = unit_delegation.trustee.name
141 scope = config.single_unit_id and _"global" or _"unit"
142 end
143 local text_apply
144 local text_abandon
145 if config.single_unit_id then
146 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
147 text_abandon = _"Abandon global delegation for this area"
148 else
149 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
150 text_abandon = _"Abandon unit delegation for this area"
151 end
152 records = {
153 {
154 id = -1,
155 name = text_apply
156 },
157 {
158 id = 0,
159 name = text_abandon
160 }
161 }
163 else
164 records = {
165 {
166 id = -1,
167 name = _"No delegation"
168 }
169 }
171 end
172 -- add saved members
173 if current_trustee_id then
174 records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"}
175 records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
176 end
177 -- add saved members
178 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
179 for i, record in ipairs(contact_members) do
180 records[#records+1] = record
181 end
182 -- add initiative authors
183 if initiative then
184 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
185 for i,record in ipairs(initiative.initiators) do
186 records[#records+1] = record.member
187 end
188 end
190 disabled_records = {}
191 disabled_records["_"] = true
192 disabled_records[app.session.member_id] = true
194 ui.field.select{
195 attr = { onchange = "updateDelegationInfo();" },
196 label = _"Trustee",
197 name = "trustee_id",
198 foreign_records = records,
199 foreign_id = "id",
200 foreign_name = "name",
201 disabled_records = disabled_records,
202 value = preview_trustee_id or current_trustee_id
203 }
205 ui.field.hidden{ name = "preview" }
207 ui.submit{ text = _"Save" }
209 end
210 }
214 -- ------------------------
219 local delegation
220 local unit_id
221 local area_id
222 local issue_id
223 local initiative_id
225 local scope = "unit"
227 unit_id = param.get("unit_id", atom.integer)
229 local inline = param.get("inline", atom.boolean)
231 if param.get("initiative_id", atom.integer) then
232 initiative_id = param.get("initiative_id", atom.integer)
233 issue_id = Initiative:by_id(initiative_id).issue_id
234 scope = "issue"
235 end
237 if param.get("issue_id", atom.integer) then
238 issue_id = param.get("issue_id", atom.integer)
239 scope = "issue"
240 end
242 if param.get("area_id", atom.integer) then
243 area_id = param.get("area_id", atom.integer)
244 scope = "area"
245 end
249 local delegation
250 local issue
252 if issue_id then
253 issue = Issue:by_id(issue_id)
254 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
255 if not delegation then
256 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
257 end
258 if not delegation then
259 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
260 end
261 elseif area_id then
262 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
263 if not delegation then
264 local area = Area:by_id(area_id)
265 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
266 end
267 end
269 if not delegation then
270 delegation = Delegation:by_pk(app.session.member.id, unit_id)
271 end
273 local slot_name = "actions"
275 if inline then
276 slot_name = "default"
277 end
279 if delegation and not delegation.trustee_id then
280 ui.image{
281 static = "icons/16/table_go_crossed.png"
282 }
283 if delegation.issue_id then
284 slot.put(_"Delegation turned off for issue")
285 elseif delegation.area_id then
286 slot.put(_"Delegation turned off for area")
287 end
288 end
290 local delegation_chain = Member:new_selector()
291 :add_field("delegation_chain.*")
292 :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
293 :add_order_by("index")
294 :exec()
296 for i, record in ipairs(delegation_chain) do
297 local style
298 local overridden = (not issue or issue.state ~= 'voting') and record.overridden
299 if record.scope_in then
300 if not overridden then
301 ui.image{
302 attr = { class = "delegation_arrow" },
303 static = "delegation_arrow_24_vertical.png"
304 }
305 else
306 ui.image{
307 attr = { class = "delegation_arrow delegation_arrow_overridden" },
308 static = "delegation_arrow_24_vertical.png"
309 }
310 end
311 ui.tag{
312 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
313 content = function()
314 if record.scope_in == "unit" then
315 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
316 elseif record.scope_in == "area" then
317 slot.put(_"Area delegation")
318 elseif record.scope_in == "issue" then
319 slot.put(_"Issue delegation")
320 end
321 end
322 }
323 end
324 ui.container{
325 attr = { class = overridden and "delegation_overridden" or "" },
326 content = function()
327 execute.view{
328 module = "member",
329 view = "_show_thumb",
330 params = { member = record }
331 }
332 end
333 }
334 if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
335 ui.container{
336 attr = { class = "delegation_participation" },
337 content = function()
338 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
339 end
340 }
341 end
342 slot.put("<br style='clear: left'/>")
343 end

Impressum / About Us