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