liquid_feedback_frontend
view app/main/delegation/show.lua @ 1122:9ba82d3a9445
Added missing arrow to title when showing member sub pages
author | bsw |
---|---|
date | Wed Dec 24 12:05:28 2014 +0100 (2014-12-24) |
parents | 286bbd976e84 |
children | 904f6807f7fa |
line source
1 local voting_right_unit_id
2 local current_trustee_id
3 local current_trustee_name
5 local head_text
7 local unit = Unit:by_id(param.get("unit_id", atom.integer))
8 local area = Area:by_id(param.get("area_id", atom.integer))
9 local issue = Issue:by_id(param.get("issue_id", atom.integer))
10 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
12 if initiative then
13 issue = initiative.issue
14 end
16 if unit then
17 unit:load_delegation_info_once_for_member_id(app.session.member_id)
18 voting_right_unit_id = unit.id
19 if unit.delegation_info.own_delegation_scope == 'unit' then
20 current_trustee_id = unit.delegation_info.first_trustee_id
21 current_trustee_name = unit.delegation_info.first_trustee_name
22 end
23 execute.view { module = "unit", view = "_head", params = { unit = unit } }
24 head_text = _"Set unit delegation"
25 end
27 if area then
28 area:load_delegation_info_once_for_member_id(app.session.member_id)
29 voting_right_unit_id = area.unit_id
30 if area.delegation_info.own_delegation_scope == 'area' then
31 current_trustee_id = area.delegation_info.first_trustee_id
32 current_trustee_name = area.delegation_info.first_trustee_name
33 end
34 execute.view { module = "area", view = "_head", params = { area = area } }
35 head_text = _"Set area delegation"
36 end
38 if issue then
39 issue:load("member_info", { member_id = app.session.member_id })
40 voting_right_unit_id = issue.area.unit_id
41 if issue.member_info.own_delegation_scope == 'issue' then
42 current_trustee_id = issue.member_info.first_trustee_id
43 current_trustee_name = issue.member_info.first_trustee_name
44 end
45 execute.view { module = "issue", view = "_head", params = { issue = issue } }
46 head_text = _"Set issue delegation"
47 end
49 if param.get("initiative_id", atom.integer) then
50 issue_id = initiative.issue_id
51 scope = "issue"
52 end
55 local delegation
56 local unit_id
57 local area_id
58 local issue_id
59 local initiative_id
61 local scope = "unit"
63 local inline = param.get("inline", atom.boolean)
66 unit_id = param.get("unit_id", atom.integer)
68 if param.get("initiative_id", atom.integer) then
69 initiative_id = initiative.id
70 issue_id = initiative.issue_id
71 scope = "issue"
72 end
74 if param.get("issue_id", atom.integer) then
75 issue_id = param.get("issue_id", atom.integer)
76 scope = "issue"
77 end
79 if param.get("area_id", atom.integer) then
80 area_id = param.get("area_id", atom.integer)
81 scope = "area"
82 end
86 local delegation
87 local issue
89 if issue_id then
90 issue = Issue:by_id(issue_id)
91 delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
92 if not delegation then
93 delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
94 end
95 if not delegation then
96 delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
97 end
98 elseif area_id then
99 delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
100 if not delegation then
101 local area = Area:by_id(area_id)
102 delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
103 end
104 end
106 if not delegation then
107 delegation = Delegation:by_pk(app.session.member.id, unit_id)
108 end
110 local contact_members = Member:build_selector{
111 is_contact_of_member_id = app.session.member_id,
112 voting_right_for_unit_id = voting_right_unit_id,
113 active = true,
114 order = "name"
115 }:exec()
117 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
119 ui.script{ static = "js/update_delegation_info.js" }
122 ui.section( function ()
124 ui.sectionHead( function ()
125 ui.heading{ level = 1, content = head_text }
126 end )
128 ui.sectionRow( function ()
130 ui.form{
131 attr = { class = "wide section", id = "delegationForm" },
132 module = "delegation",
133 action = "update",
134 params = {
135 unit_id = unit and unit.id or nil,
136 area_id = area and area.id or nil,
137 issue_id = issue and issue.id or nil,
138 initiative_id = initiative_id
139 },
140 routing = {
141 default = {
142 mode = "redirect",
143 module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
144 view = "show",
145 id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
146 }
147 },
148 content = function()
149 local record
150 if issue then
151 local delegate_name = ""
152 local scope = _"no delegation set"
153 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
154 if area_delegation then
155 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
156 scope = _"area"
157 else
158 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
159 if unit_delegation then
160 delegate_name = unit_delegation.trustee.name
161 scope = config.single_unit_id and _"global" or _"unit"
162 end
163 end
164 local text_apply
165 local text_abandon
166 if config.single_unit_id then
167 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
168 text_abandon = _"Abandon unit and area delegations for this issue"
169 else
170 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
171 text_abandon = _"Abandon unit and area delegations for this issue"
172 end
174 records = {
175 { id = -1, name = text_apply },
176 { id = 0, name = text_abandon }
177 }
178 elseif area then
179 local delegate_name = ""
180 local scope = _"no delegation set"
181 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
182 if unit_delegation then
183 delegate_name = unit_delegation.trustee.name
184 scope = config.single_unit_id and _"global" or _"unit"
185 end
186 local text_apply
187 local text_abandon
188 if config.single_unit_id then
189 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
190 text_abandon = _"Abandon global delegation for this area"
191 else
192 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
193 text_abandon = _"Abandon unit delegation for this area"
194 end
195 records = {
196 {
197 id = -1,
198 name = text_apply
199 },
200 {
201 id = 0,
202 name = text_abandon
203 }
204 }
206 else
207 records = {
208 {
209 id = -1,
210 name = _"No delegation"
211 }
212 }
214 end
215 -- add current trustee
216 if current_trustee_id then
217 records[#records+1] = {id="_", name= "--- " .. _"Current delegatee" .. " ---"}
218 records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
219 end
220 -- add initiative authors
221 if initiative then
222 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
223 for i,record in ipairs(initiative.initiators) do
224 records[#records+1] = record.member
225 end
226 end
227 -- add saved members
228 if #contact_members > 0 then
229 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
230 for i, record in ipairs(contact_members) do
231 records[#records+1] = record
232 end
233 end
235 disabled_records = {}
236 disabled_records["_"] = true
237 disabled_records[app.session.member_id] = true
239 local value = current_trustee_id
240 if preview_trustee_id then
241 value = preview_trustee_id
242 end
243 if preview_trustee_id == nil and delegation and not delegation.trustee_id then
244 value = 0
245 end
247 ui.heading{ level = 2, content = _"Choose your delegatee" }
249 ui.field.select{
250 attr = { onchange = "updateDelegationInfo();" },
251 name = "trustee_id",
252 foreign_records = records,
253 foreign_id = "id",
254 foreign_name = "name",
255 disabled_records = disabled_records,
256 value = value
257 }
259 ui.container{ content = _"You can choose only members which you have been saved as contact before." }
261 ui.field.hidden{ name = "preview" }
263 slot.put("<br />")
264 ui.tag { tag = "input", content = "", attr = {
265 type = "submit",
266 value = _"Save",
267 class = "btn btn-default",
268 } }
270 slot.put("<br /><br /><br />")
271 if initiative then
272 ui.link{
273 module = "initiative",
274 view = "show",
275 id = initiative.id,
276 content = function()
277 slot.put(_"Cancel")
278 end,
279 }
280 elseif issue then
281 ui.link{
282 module = "issue",
283 view = "show",
284 id = issue.id,
285 content = function()
286 slot.put(_"Cancel")
287 end,
288 }
289 elseif area then
290 ui.link{
291 module = "area",
292 view = "show",
293 id = area.id,
294 content = function()
295 slot.put(_"Cancel")
296 end,
297 }
298 else
299 ui.link{
300 module = "index",
301 view = "index",
302 content = function()
303 slot.put(_"Cancel")
304 end,
305 }
306 end
308 end
309 }
311 end ) end )
312 -- ------------------------
314 ui.sidebar( "tab-members", function ()
316 ui.sidebarHead( function ()
317 ui.heading { level = 1, content = _"Preview of delegation" }
318 end )
320 local preview_inherit = false
321 local tmp_preview_trustee_id = preview_trustee_id
322 if preview_trustee_id == -1 then
323 preview_inherit = true
324 tmp_preview_trustee_id = nil
325 end
326 local delegation_chain = Member:new_selector()
327 :add_field("delegation_chain.*")
328 :join({ "delegation_chain(?,?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, tmp_preview_trustee_id, preview_inherit }, "delegation_chain", "member.id = delegation_chain.member_id")
329 :add_order_by("index")
330 :exec()
332 for i, record in ipairs(delegation_chain) do
333 local style
334 local overridden = (not issue or issue.state ~= 'voting') and record.overridden
335 ui.sidebarSection( function ()
336 if record.scope_in then
337 if not overridden then
338 local text = _"delegated to"
339 ui.image{
340 attr = { class = "delegation_arrow", alt = text, title = text },
341 static = "delegation_arrow_24_vertical.png"
342 }
343 else
344 local text = _"delegated to"
345 ui.image{
346 attr = { class = "delegation_arrow delegation_arrow_overridden", alt = text, title = text },
347 static = "delegation_arrow_24_vertical.png"
348 }
349 end
350 ui.tag{
351 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
352 content = function()
353 if record.scope_in == "unit" then
354 slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
355 elseif record.scope_in == "area" then
356 slot.put(_"Area delegation")
357 elseif record.scope_in == "issue" then
358 slot.put(_"Issue delegation")
359 end
360 end
361 }
362 end
363 ui.container{
364 attr = { class = overridden and "delegation_overridden" or "" },
365 content = function()
366 execute.view{
367 module = "member",
368 view = "_show_thumb",
369 params = { member = record }
370 }
371 end
372 }
373 if issue and issue.state ~= 'voting' and record.participation and not record.overridden then
374 ui.container{
375 attr = { class = "delegation_participation" },
376 content = function()
377 if i == #delegation_chain then
378 ui.tag{ content = _"This member is currently participating in this issue." }
379 else
380 ui.tag{ content = _"This member is participating, the remaining delegation chain is suspended during discussing." }
381 end
382 end
383 }
384 end
385 slot.put("<br style='clear: left'/>")
386 end )
387 end
389 if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
390 ui.image{
391 static = "icons/16/table_go_crossed.png"
392 }
393 if issue_id then
394 slot.put(_"Delegation turned off for issue")
395 elseif area_id then
396 slot.put(_"Delegation turned off for area")
397 end
398 end
401 end )