rev |
line source |
bsw@212
|
1 slot.set_layout("lf2")
|
bsw@212
|
2
|
bsw@212
|
3 local area = Area:by_id(param.get("area_id", atom.integer))
|
bsw@212
|
4 local issue = Issue:by_id(param.get("issue_id", atom.integer))
|
bsw@217
|
5 local unit = Unit:by_id(param.get("unit_id", atom.integer))
|
bsw@217
|
6
|
bsw@217
|
7 local delegation = Delegation:by_pk(app.session.member_id, unit and unit.id or nil, area and area.id or nil, issue and issue.id or nil)
|
bsw@217
|
8
|
bsw@212
|
9 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
|
bsw@212
|
10
|
bsw@212
|
11 local contact_members = Member:build_selector{
|
bsw@212
|
12 is_contact_of_member_id = app.session.member_id,
|
bsw@212
|
13 order = "name"
|
bsw@212
|
14 }:exec()
|
bsw@212
|
15
|
bsw@212
|
16 if area then
|
bsw@217
|
17 title = _("Set delegation for area '#{name}'", { name = area.name })
|
bsw@212
|
18 end
|
bsw@212
|
19
|
bsw@212
|
20 if issue then
|
bsw@217
|
21 title = _("Set delegation for issue ##{number} in area '#{area_name}'", { number = issue.id, area_name = issue.area.name })
|
bsw@212
|
22 end
|
bsw@212
|
23
|
bsw@212
|
24 if not area and not issue then
|
bsw@217
|
25 title = _("Set delegation for unit #{name}", { name = unit.name })
|
bsw@212
|
26 end
|
bsw@212
|
27
|
bsw@212
|
28 ui.box{ content = function()
|
bsw@212
|
29
|
bsw@212
|
30 ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end }
|
bsw@212
|
31
|
bsw@212
|
32 ui.form{
|
bsw@212
|
33 attr = { class = "vertical" },
|
bsw@212
|
34 module = "delegation",
|
bsw@212
|
35 action = "update",
|
bsw@212
|
36 params = {
|
bsw@217
|
37 unit_id = unit and unit.id or nil,
|
bsw@212
|
38 area_id = area and area.id or nil,
|
bsw@212
|
39 issue_id = issue and issue.id or nil,
|
bsw@212
|
40 },
|
bsw@212
|
41 routing = {
|
bsw@212
|
42 default = {
|
bsw@212
|
43 mode = "redirect",
|
bsw@212
|
44 module = "lf2",
|
bsw@213
|
45 view = area and "area" or initiative and "initiative" or issue and "issue" or "index",
|
bsw@213
|
46 id = area and area.id or initiative and initiative.id or issue and issue.id or nil,
|
bsw@212
|
47 }
|
bsw@212
|
48 },
|
bsw@212
|
49 content = function()
|
bsw@212
|
50 local records
|
bsw@212
|
51
|
bsw@212
|
52 if issue then
|
bsw@212
|
53 local delegate_name = ""
|
bsw@212
|
54 local scope = "no delegation set"
|
bsw@212
|
55 local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id)
|
bsw@212
|
56 if area_delegation then
|
bsw@212
|
57 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
|
bsw@212
|
58 scope = _"area"
|
bsw@212
|
59 else
|
bsw@212
|
60 local unit_delegation = Delegation:by_pk(app.session.member_id)
|
bsw@212
|
61 if unit_delegation then
|
bsw@212
|
62 delegate_name = unit_delegation.trustee.name
|
bsw@212
|
63 scope = _"unit"
|
bsw@212
|
64 end
|
bsw@212
|
65 end
|
bsw@212
|
66 records = {
|
bsw@212
|
67 {
|
bsw@212
|
68 id = -1,
|
bsw@212
|
69 name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@212
|
70 },
|
bsw@212
|
71 {
|
bsw@212
|
72 id = 0,
|
bsw@212
|
73 name = _"Abandon unit and area delegations for this issue"
|
bsw@212
|
74 },
|
bsw@212
|
75
|
bsw@212
|
76 }
|
bsw@212
|
77 elseif area then
|
bsw@212
|
78 local delegate_name = ""
|
bsw@212
|
79 local scope = "no delegation set"
|
bsw@212
|
80 local unit_delegation = Delegation:by_pk(app.session.member_id)
|
bsw@212
|
81 if unit_delegation then
|
bsw@212
|
82 delegate_name = unit_delegation.trustee.name
|
bsw@212
|
83 scope = _"unit"
|
bsw@212
|
84 end
|
bsw@212
|
85 records = {
|
bsw@212
|
86 {
|
bsw@212
|
87 id = -1,
|
bsw@212
|
88 name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@212
|
89 },
|
bsw@212
|
90 {
|
bsw@212
|
91 id = 0,
|
bsw@212
|
92 name = _"Abandon unit delegation for this area"
|
bsw@212
|
93 }
|
bsw@212
|
94 }
|
bsw@212
|
95
|
bsw@212
|
96 else
|
bsw@212
|
97 records = {
|
bsw@212
|
98 {
|
bsw@212
|
99 id = -1,
|
bsw@212
|
100 name = _"No delegation"
|
bsw@212
|
101 }
|
bsw@212
|
102 }
|
bsw@212
|
103
|
bsw@212
|
104 end
|
bsw@214
|
105 disabled_records = {}
|
bsw@214
|
106 disabled_records["_"] = true
|
bsw@214
|
107
|
bsw@212
|
108 -- add saved members
|
bsw@212
|
109 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
|
bsw@212
|
110 for i, record in ipairs(contact_members) do
|
bsw@212
|
111 records[#records+1] = record
|
bsw@212
|
112 end
|
bsw@214
|
113
|
bsw@212
|
114 -- add initiative authors
|
bsw@212
|
115 if initiative then
|
bsw@212
|
116 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
|
bsw@212
|
117 for i,record in ipairs(initiative.initiators) do
|
bsw@212
|
118 records[#records+1] = record.member
|
bsw@214
|
119 if record.member.id == app.session.member_id then
|
bsw@214
|
120 disabled_records[record.member.id] = true
|
bsw@214
|
121 end
|
bsw@212
|
122 end
|
bsw@212
|
123 end
|
bsw@212
|
124
|
bsw@212
|
125
|
bsw@212
|
126
|
bsw@212
|
127 ui.box_row{ content = function() ui.box_col{ content = function()
|
bsw@212
|
128 ui.field.select{
|
bsw@217
|
129 label = _"Delegate",
|
bsw@212
|
130 name = "trustee_id",
|
bsw@212
|
131 foreign_records = records,
|
bsw@212
|
132 foreign_id = "id",
|
bsw@212
|
133 foreign_name = "name",
|
bsw@217
|
134 disabled_records = disabled_records,
|
bsw@217
|
135 value = delegation and delegation.trustee_id or nil
|
bsw@212
|
136 }
|
bsw@212
|
137 end } end }
|
bsw@212
|
138
|
bsw@215
|
139 ui.box_row{ content = function()
|
bsw@215
|
140 ui.box_col{ content = _"Please note: Member, interest and supporter counts are calculated periodically, therefore it can take some time until your changes become effective everywhere." }
|
bsw@215
|
141 end }
|
bsw@212
|
142 ui.box_row{ content = function() ui.box_col{ content = function()
|
bsw@212
|
143 ui.submit{ text = _"Save" }
|
bsw@212
|
144 end } end }
|
bsw@212
|
145 end
|
bsw@212
|
146 }
|
bsw@212
|
147
|
bsw@212
|
148 end } |