liquid_feedback_frontend

view app/main/delegation/show.lua @ 577:fd41ff8d9563

Fixed display of turned off delegations in delegation form
author bsw
date Wed Jun 20 00:24:36 2012 +0200 (2012-06-20)
parents 5650f8163a29
children edf6b6814a68
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
42 local delegation
43 local unit_id
44 local area_id
45 local issue_id
46 local initiative_id
47 local initiative
49 local scope = "unit"
51 unit_id = param.get("unit_id", atom.integer)
53 local inline = param.get("inline", atom.boolean)
55 if param.get("initiative_id", atom.integer) then
56 initiative_id = param.get("initiative_id", atom.integer)
57 initiative = Initiative:by_id(initiative_id)
58 issue_id = initiative.issue_id
59 scope = "issue"
60 end
62 if param.get("issue_id", atom.integer) then
63 issue_id = param.get("issue_id", atom.integer)
64 scope = "issue"
65 end
67 if param.get("area_id", atom.integer) then
68 area_id = param.get("area_id", atom.integer)
69 scope = "area"
70 end
74 local delegation
75 local issue
77 if issue_id then
78 issue = Issue:by_id(issue_id)
79 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
80 if not delegation then
81 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
82 end
83 if not delegation then
84 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
85 end
86 elseif area_id then
87 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
88 if not delegation then
89 local area = Area:by_id(area_id)
90 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
91 end
92 end
94 if not delegation then
95 delegation = Delegation:by_pk(app.session.member.id, unit_id)
96 end
98 local contact_members = Member:build_selector{
99 is_contact_of_member_id = app.session.member_id,
100 voting_right_for_unit_id = voting_right_unit_id,
101 active = true,
102 order = "name"
103 }:exec()
105 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
107 ui.script{ static = "js/update_delegation_info.js" }
109 slot.select("actions", function()
110 if issue then
111 ui.link{
112 module = "issue",
113 view = "show",
114 id = issue.id,
115 content = function()
116 ui.image{ static = "icons/16/cancel.png" }
117 slot.put(_"Cancel")
118 end,
119 }
120 elseif area then
121 ui.link{
122 module = "area",
123 view = "show",
124 id = area.id,
125 content = function()
126 ui.image{ static = "icons/16/cancel.png" }
127 slot.put(_"Cancel")
128 end,
129 }
130 else
131 ui.link{
132 module = "index",
133 view = "index",
134 content = function()
135 ui.image{ static = "icons/16/cancel.png" }
136 slot.put(_"Cancel")
137 end,
138 }
139 end
140 end)
143 ui.form{
144 attr = { class = "vertical", id = "delegationForm" },
145 module = "delegation",
146 action = "update",
147 params = {
148 unit_id = unit and unit.id or nil,
149 area_id = area and area.id or nil,
150 issue_id = issue and issue.id or nil,
151 initiative_id = initiative_id
152 },
153 routing = {
154 default = {
155 mode = "redirect",
156 module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
157 view = "show",
158 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
159 }
160 },
161 content = function()
162 local records
164 if issue then
165 local delegate_name = ""
166 local scope = "no delegation set"
167 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
168 if area_delegation then
169 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
170 scope = _"area"
171 else
172 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
173 if unit_delegation then
174 delegate_name = unit_delegation.trustee.name
175 scope = config.single_unit_id and _"global" or _"unit"
176 end
177 end
178 local text_apply
179 local text_abandon
180 if config.single_unit_id then
181 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
182 text_abandon = _"Abandon unit and area delegations for this issue"
183 else
184 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
185 text_abandon = _"Abandon unit and area delegations for this issue"
186 end
187 records = {
188 { id = -1, name = text_apply },
189 { id = 0, name = text_abandon }
190 }
191 elseif area then
192 local delegate_name = ""
193 local scope = "no delegation set"
194 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
195 if unit_delegation then
196 delegate_name = unit_delegation.trustee.name
197 scope = config.single_unit_id and _"global" or _"unit"
198 end
199 local text_apply
200 local text_abandon
201 if config.single_unit_id then
202 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
203 text_abandon = _"Abandon global delegation for this area"
204 else
205 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
206 text_abandon = _"Abandon unit delegation for this area"
207 end
208 records = {
209 {
210 id = -1,
211 name = text_apply
212 },
213 {
214 id = 0,
215 name = text_abandon
216 }
217 }
219 else
220 records = {
221 {
222 id = -1,
223 name = _"No delegation"
224 }
225 }
227 end
228 -- add current trustee
229 if current_trustee_id then
230 records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"}
231 records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
232 end
233 -- add initiative authors
234 if initiative then
235 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
236 for i,record in ipairs(initiative.initiators) do
237 records[#records+1] = record.member
238 end
239 end
240 -- add saved members
241 if #contact_members > 0 then
242 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
243 for i, record in ipairs(contact_members) do
244 records[#records+1] = record
245 end
246 end
248 disabled_records = {}
249 disabled_records["_"] = true
250 disabled_records[app.session.member_id] = true
252 local value = current_trustee_id
253 if preview_trustee_id then
254 value = preview_trustee_id
255 end
256 if preview_trustee_id == nil and delegation and not delegation.trustee_id then
257 value = 0
258 end
260 ui.field.select{
261 attr = { onchange = "updateDelegationInfo();" },
262 label = _"Trustee",
263 name = "trustee_id",
264 foreign_records = records,
265 foreign_id = "id",
266 foreign_name = "name",
267 disabled_records = disabled_records,
268 value = value
269 }
271 ui.field.hidden{ name = "preview" }
273 ui.submit{ text = _"Save" }
275 end
276 }
279 -- ------------------------
282 local delegation_chain = Member:new_selector()
283 :add_field("delegation_chain.*")
284 :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
285 :add_order_by("index")
286 :exec()
288 for i, record in ipairs(delegation_chain) do
289 local style
290 local overridden = (not issue or issue.state ~= 'voting') and record.overridden
291 if record.scope_in then
292 if not overridden then
293 ui.image{
294 attr = { class = "delegation_arrow" },
295 static = "delegation_arrow_24_vertical.png"
296 }
297 else
298 ui.image{
299 attr = { class = "delegation_arrow delegation_arrow_overridden" },
300 static = "delegation_arrow_24_vertical.png"
301 }
302 end
303 ui.tag{
304 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
305 content = function()
306 if record.scope_in == "unit" then
307 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
308 elseif record.scope_in == "area" then
309 slot.put(_"Area delegation")
310 elseif record.scope_in == "issue" then
311 slot.put(_"Issue delegation")
312 end
313 end
314 }
315 end
316 ui.container{
317 attr = { class = overridden and "delegation_overridden" or "" },
318 content = function()
319 execute.view{
320 module = "member",
321 view = "_show_thumb",
322 params = { member = record }
323 }
324 end
325 }
326 if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
327 ui.container{
328 attr = { class = "delegation_participation" },
329 content = function()
330 slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
331 end
332 }
333 end
334 slot.put("<br style='clear: left'/>")
335 end
337 if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
338 ui.image{
339 static = "icons/16/table_go_crossed.png"
340 }
341 if issue_id then
342 slot.put(_"Delegation turned off for issue")
343 elseif area_id then
344 slot.put(_"Delegation turned off for area")
345 end
346 end

Impressum / About Us