rev |
line source |
bsw/jbe@0
|
1 local truster_id = app.session.member.id
|
bsw/jbe@0
|
2
|
bsw/jbe@0
|
3 local trustee_id = param.get("trustee_id", atom.integer)
|
bsw/jbe@0
|
4
|
bsw@248
|
5 local unit_id = param.get("unit_id", atom.integer)
|
bsw@248
|
6
|
bsw/jbe@0
|
7 local area_id = param.get("area_id", atom.integer)
|
bsw/jbe@0
|
8
|
bsw/jbe@0
|
9 local issue_id = param.get("issue_id", atom.integer)
|
bsw/jbe@0
|
10
|
bsw/jbe@0
|
11 if issue_id then
|
bsw/jbe@0
|
12 area_id = nil
|
bsw/jbe@0
|
13 end
|
bsw/jbe@0
|
14
|
bsw@293
|
15 local delegation = Delegation:by_pk(truster_id, unit_id, area_id, issue_id)
|
bsw@293
|
16
|
bsw@293
|
17
|
bsw/jbe@4
|
18 if param.get("delete") or trustee_id == -1 then
|
bsw/jbe@0
|
19
|
bsw/jbe@0
|
20 if delegation then
|
bsw/jbe@5
|
21
|
bsw/jbe@0
|
22 delegation:destroy()
|
bsw/jbe@5
|
23
|
bsw@278
|
24 --[[
|
bsw/jbe@0
|
25 if issue_id then
|
bsw/jbe@0
|
26 slot.put_into("notice", _"Your delegation for this issue has been deleted.")
|
bsw/jbe@0
|
27 elseif area_id then
|
bsw/jbe@0
|
28 slot.put_into("notice", _"Your delegation for this area has been deleted.")
|
bsw/jbe@0
|
29 else
|
bsw@248
|
30 slot.put_into("notice", _"Your delegation for this unit has been deleted.")
|
bsw/jbe@0
|
31 end
|
bsw@278
|
32 --]]
|
bsw/jbe@0
|
33 end
|
bsw/jbe@5
|
34
|
bsw/jbe@0
|
35 else
|
bsw@296
|
36
|
bsw@296
|
37 local trustee = Member:by_id(trustee_id)
|
bsw/jbe@0
|
38
|
bsw@281
|
39 local check_unit_id
|
bsw@281
|
40 if unit_id then
|
bsw@281
|
41 check_unit_id = unit_id
|
bsw@281
|
42 elseif area_id then
|
bsw@281
|
43 local area = Area:by_id(area_id)
|
bsw@281
|
44 check_unit_id = area.unit_id
|
bsw@281
|
45 else
|
bsw@281
|
46 local issue = Issue:by_id(issue_id)
|
bsw@281
|
47 local area = Area:by_id(issue.area_id)
|
bsw@281
|
48 check_unit_id = area.unit_id
|
bsw@281
|
49 end
|
bsw@296
|
50
|
bsw@296
|
51 if not trustee:has_voting_right_for_unit_id(check_unit_id) then
|
bsw@296
|
52 slot.put_into("error", _"Trustee has no voting right in this unit")
|
bsw@296
|
53 return false
|
bsw@296
|
54 end
|
bsw@281
|
55
|
bsw@281
|
56 if not app.session.member:has_voting_right_for_unit_id(check_unit_id) then
|
bsw@281
|
57 error("access denied")
|
bsw@281
|
58 end
|
bsw@281
|
59
|
bsw/jbe@0
|
60 if not delegation then
|
bsw/jbe@0
|
61 delegation = Delegation:new()
|
bsw/jbe@0
|
62 delegation.truster_id = truster_id
|
bsw@248
|
63 delegation.unit_id = unit_id
|
bsw/jbe@0
|
64 delegation.area_id = area_id
|
bsw/jbe@0
|
65 delegation.issue_id = issue_id
|
bsw/jbe@5
|
66 if issue_id then
|
bsw/jbe@5
|
67 delegation.scope = "issue"
|
bsw/jbe@5
|
68 elseif area_id then
|
bsw/jbe@5
|
69 delegation.scope = "area"
|
bsw@248
|
70 elseif unit_id then
|
bsw@248
|
71 delegation.scope = "unit"
|
bsw/jbe@5
|
72 end
|
bsw/jbe@0
|
73 end
|
bsw@180
|
74 if trustee_id == 0 then
|
bsw@180
|
75 delegation.trustee_id = nil
|
bsw@180
|
76 else
|
bsw@180
|
77 delegation.trustee_id = trustee_id
|
bsw@180
|
78 end
|
bsw/jbe@0
|
79
|
bsw/jbe@0
|
80 delegation:save()
|
bsw@278
|
81 --[[
|
bsw/jbe@0
|
82 if issue_id then
|
bsw/jbe@0
|
83 slot.put_into("notice", _"Your delegation for this issue has been updated.")
|
bsw/jbe@0
|
84 elseif area_id then
|
bsw/jbe@0
|
85 slot.put_into("notice", _"Your delegation for this area has been updated.")
|
bsw/jbe@0
|
86 else
|
bsw@248
|
87 slot.put_into("notice", _"Your delegation for this unit has been updated.")
|
bsw/jbe@0
|
88 end
|
bsw@278
|
89 --]]
|
bsw/jbe@0
|
90 end
|
bsw/jbe@0
|
91
|