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