rev |
line source |
bsw@248
|
1 local unit = Unit:by_id(param.get("unit_id", atom.integer))
|
bsw@248
|
2 if unit then
|
bsw@264
|
3 slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
|
bsw@248
|
4 util.help("delegation.new.unit")
|
bsw@248
|
5 end
|
bsw@248
|
6
|
bsw/jbe@0
|
7 local area = Area:by_id(param.get("area_id", atom.integer))
|
bsw/jbe@0
|
8 if area then
|
bsw/jbe@0
|
9 slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
|
bsw/jbe@4
|
10 util.help("delegation.new.area")
|
bsw/jbe@0
|
11 end
|
bsw/jbe@0
|
12
|
bsw/jbe@0
|
13 local issue = Issue:by_id(param.get("issue_id", atom.integer))
|
bsw/jbe@0
|
14 if issue then
|
bsw/jbe@0
|
15 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/jbe@4
|
16 util.help("delegation.new.issue")
|
bsw/jbe@0
|
17 end
|
bsw/jbe@0
|
18
|
poelzi@111
|
19 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
|
poelzi@111
|
20
|
bsw/jbe@4
|
21 slot.select("actions", function()
|
bsw/jbe@4
|
22 if issue then
|
bsw/jbe@4
|
23 ui.link{
|
bsw/jbe@4
|
24 module = "issue",
|
bsw/jbe@4
|
25 view = "show",
|
bsw/jbe@4
|
26 id = issue.id,
|
bsw/jbe@4
|
27 content = function()
|
bsw/jbe@4
|
28 ui.image{ static = "icons/16/cancel.png" }
|
bsw/jbe@4
|
29 slot.put(_"Cancel")
|
bsw/jbe@4
|
30 end,
|
bsw/jbe@4
|
31 }
|
bsw/jbe@4
|
32 elseif area then
|
bsw/jbe@4
|
33 ui.link{
|
bsw/jbe@4
|
34 module = "area",
|
bsw/jbe@4
|
35 view = "show",
|
bsw/jbe@4
|
36 id = area.id,
|
bsw/jbe@4
|
37 content = function()
|
bsw/jbe@4
|
38 ui.image{ static = "icons/16/cancel.png" }
|
bsw/jbe@4
|
39 slot.put(_"Cancel")
|
bsw/jbe@4
|
40 end,
|
bsw/jbe@4
|
41 }
|
bsw/jbe@4
|
42 else
|
bsw/jbe@4
|
43 ui.link{
|
bsw/jbe@4
|
44 module = "index",
|
bsw/jbe@4
|
45 view = "index",
|
bsw/jbe@4
|
46 content = function()
|
bsw/jbe@4
|
47 ui.image{ static = "icons/16/cancel.png" }
|
bsw/jbe@4
|
48 slot.put(_"Cancel")
|
bsw/jbe@4
|
49 end,
|
bsw/jbe@4
|
50 }
|
bsw/jbe@4
|
51 end
|
bsw/jbe@4
|
52 end)
|
bsw/jbe@4
|
53
|
bsw/jbe@4
|
54
|
bsw@199
|
55 local contact_members = Member:build_selector{
|
bsw@199
|
56 is_contact_of_member_id = app.session.member_id,
|
bsw@199
|
57 order = "name"
|
bsw@199
|
58 }:exec()
|
bsw/jbe@0
|
59
|
bsw/jbe@0
|
60 ui.form{
|
bsw/jbe@0
|
61 attr = { class = "vertical" },
|
bsw/jbe@0
|
62 module = "delegation",
|
bsw/jbe@0
|
63 action = "update",
|
bsw/jbe@0
|
64 params = {
|
bsw@248
|
65 unit_id = unit and unit.id or nil,
|
bsw/jbe@0
|
66 area_id = area and area.id or nil,
|
bsw/jbe@0
|
67 issue_id = issue and issue.id or nil,
|
bsw/jbe@0
|
68 },
|
bsw/jbe@0
|
69 routing = {
|
bsw/jbe@0
|
70 default = {
|
bsw/jbe@0
|
71 mode = "redirect",
|
bsw/jbe@4
|
72 module = area and "area" or issue and "issue" or "index",
|
bsw/jbe@4
|
73 view = (area or issue) and "show" or "index",
|
bsw/jbe@4
|
74 id = area and area.id or issue and issue.id or nil,
|
bsw/jbe@0
|
75 }
|
bsw/jbe@0
|
76 },
|
bsw/jbe@0
|
77 content = function()
|
bsw@180
|
78 local records
|
bsw@180
|
79
|
bsw@180
|
80 if issue then
|
bsw@183
|
81 local delegate_name = ""
|
bsw@183
|
82 local scope = "no delegation set"
|
bsw@248
|
83 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
|
bsw@183
|
84 if area_delegation then
|
bsw@187
|
85 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
|
bsw@183
|
86 scope = _"area"
|
bsw@183
|
87 else
|
bsw@248
|
88 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
|
bsw@248
|
89 if unit_delegation then
|
bsw@248
|
90 delegate_name = unit_delegation.trustee.name
|
bsw@264
|
91 scope = config.single_unit_id and _"global" or _"unit"
|
bsw@248
|
92 end
|
bsw@183
|
93 end
|
bsw@264
|
94 local text_apply
|
bsw@264
|
95 local text_abandon
|
bsw@264
|
96 if config.single_unit_id then
|
bsw@264
|
97 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@264
|
98 text_abandon = _"Abandon unit and area delegations for this issue"
|
bsw@264
|
99 else
|
bsw@264
|
100 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@264
|
101 text_abandon = _"Abandon unit and area delegations for this issue"
|
bsw@264
|
102 end
|
bsw@180
|
103 records = {
|
bsw@264
|
104 { id = -1, name = text_apply },
|
bsw@264
|
105 { id = 0, name = text_abandom }
|
bsw/jbe@4
|
106 }
|
bsw@180
|
107 elseif area then
|
bsw@183
|
108 local delegate_name = ""
|
bsw@183
|
109 local scope = "no delegation set"
|
bsw@248
|
110 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
|
bsw@248
|
111 if unit_delegation then
|
bsw@248
|
112 delegate_name = unit_delegation.trustee.name
|
bsw@264
|
113 scope = config.single_unit_id and _"global" or _"unit"
|
bsw@264
|
114 end
|
bsw@264
|
115 local text_apply
|
bsw@264
|
116 local text_abandon
|
bsw@264
|
117 if config.single_unit_id then
|
bsw@264
|
118 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@264
|
119 text_abandon = _"Abandon global delegation for this area"
|
bsw@264
|
120 else
|
bsw@264
|
121 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
|
bsw@264
|
122 text_abandon = _"Abandon unit delegation for this area"
|
bsw@183
|
123 end
|
bsw@180
|
124 records = {
|
bsw@180
|
125 {
|
bsw@180
|
126 id = -1,
|
bsw@264
|
127 name = text_apply
|
bsw@180
|
128 },
|
bsw@180
|
129 {
|
bsw@180
|
130 id = 0,
|
bsw@264
|
131 name = text_abandon
|
bsw@180
|
132 }
|
bsw@180
|
133 }
|
bsw@180
|
134
|
bsw@180
|
135 else
|
bsw@180
|
136 records = {
|
bsw@180
|
137 {
|
bsw@180
|
138 id = -1,
|
bsw@180
|
139 name = _"No delegation"
|
bsw@180
|
140 }
|
bsw@180
|
141 }
|
bsw@180
|
142
|
bsw@180
|
143 end
|
bsw@183
|
144 -- add saved members
|
bsw@183
|
145 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
|
bsw/jbe@4
|
146 for i, record in ipairs(contact_members) do
|
bsw/jbe@4
|
147 records[#records+1] = record
|
bsw/jbe@4
|
148 end
|
poelzi@111
|
149 -- add initiative authors
|
poelzi@111
|
150 if initiative then
|
bsw@183
|
151 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
|
poelzi@111
|
152 for i,record in ipairs(initiative.initiators) do
|
poelzi@111
|
153 records[#records+1] = record.member
|
poelzi@111
|
154 end
|
poelzi@111
|
155 end
|
bsw/jbe@4
|
156
|
bsw@183
|
157 disabled_records = {}
|
bsw@183
|
158 disabled_records["_"] = true
|
bsw@183
|
159
|
bsw/jbe@0
|
160 ui.field.select{
|
bsw/jbe@0
|
161 label = _"Trustee",
|
bsw/jbe@0
|
162 name = "trustee_id",
|
bsw/jbe@4
|
163 foreign_records = records,
|
bsw/jbe@0
|
164 foreign_id = "id",
|
bsw/jbe@4
|
165 foreign_name = "name",
|
poelzi@111
|
166 disabled_records = disabled_records
|
bsw/jbe@0
|
167 }
|
poelzi@111
|
168
|
bsw/jbe@0
|
169 ui.submit{ text = _"Save" }
|
bsw/jbe@0
|
170 end
|
bsw/jbe@4
|
171 }
|