rev |
line source |
bsw/jbe@0
|
1 local id = param.get_id()
|
bsw/jbe@0
|
2
|
bsw@1045
|
3 local hint = not id
|
bsw@1045
|
4
|
bsw@193
|
5 local area = Area:by_id(id) or Area:new()
|
bsw@193
|
6
|
bsw@263
|
7 if not area.unit_id then
|
bsw@263
|
8 area.unit_id = param.get("unit_id", atom.integer)
|
bsw@263
|
9 end
|
bsw@263
|
10
|
bsw@1045
|
11 ui.titleAdmin(_"area")
|
bsw/jbe@0
|
12
|
bsw/jbe@0
|
13 ui.form{
|
bsw@1045
|
14 attr = { class = "vertical section" },
|
bsw/jbe@0
|
15 record = area,
|
bsw/jbe@5
|
16 module = "admin",
|
bsw/jbe@5
|
17 action = "area_update",
|
bsw/jbe@0
|
18 routing = {
|
bsw@1045
|
19 ok = {
|
bsw/jbe@0
|
20 mode = "redirect",
|
bsw/jbe@0
|
21 module = "admin",
|
bsw@1045
|
22 view = "index",
|
bsw@263
|
23 params = { unit_id = area.unit_id }
|
bsw@1045
|
24 },
|
bsw/jbe@0
|
25 },
|
bsw@193
|
26 id = id,
|
bsw/jbe@0
|
27 content = function()
|
bsw@193
|
28 policies = Policy:build_selector{ active = true }:exec()
|
poelzi@126
|
29 local def_policy = {
|
poelzi@126
|
30 {
|
poelzi@126
|
31 id = "-1",
|
poelzi@126
|
32 name = _"No default"
|
poelzi@126
|
33 }
|
poelzi@126
|
34 }
|
poelzi@126
|
35 for i, record in ipairs(policies) do
|
poelzi@126
|
36 def_policy[#def_policy+1] = record
|
poelzi@126
|
37 end
|
poelzi@126
|
38
|
bsw@1045
|
39
|
bsw@1045
|
40 ui.section( function()
|
bsw@1045
|
41 ui.sectionHead( function()
|
bsw@1045
|
42 ui.heading { level = 1, content = area.name or _"New area" }
|
bsw@1045
|
43 end )
|
bsw@1045
|
44
|
bsw@1045
|
45 ui.sectionRow( function()
|
bsw@1045
|
46
|
bsw@1045
|
47 ui.field.hidden{ name = "unit_id", value = area.unit_id }
|
bsw@1045
|
48 ui.field.text{ label = _"Unit", value = area.unit.name, readonly = true }
|
bsw@1045
|
49 ui.field.text{ label = _"Name", name = "name" }
|
bsw@1045
|
50 ui.field.text{ label = _"Description", name = "description", multiline = true }
|
bsw@1045
|
51 ui.field.select{ label = _"Default Policy", name = "default_policy",
|
bsw@1045
|
52 value=area.default_policy and area.default_policy.id or "-1",
|
bsw@1045
|
53 foreign_records = def_policy,
|
bsw@1045
|
54 foreign_id = "id",
|
bsw@1045
|
55 foreign_name = "name"
|
bsw@1045
|
56 }
|
bsw@1045
|
57 ui.heading { level = 3, content = _"Allowed policies" }
|
bsw@1045
|
58 ui.multiselect{ name = "allowed_policies[]",
|
bsw@1045
|
59 foreign_records = policies,
|
bsw@1045
|
60 foreign_id = "id",
|
bsw@1045
|
61 foreign_name = "name",
|
bsw@1045
|
62 connecting_records = area.allowed_policies or {},
|
bsw@1045
|
63 foreign_reference = "id",
|
bsw@1045
|
64 }
|
bsw@1045
|
65 slot.put("<br /><br />")
|
bsw@1045
|
66 ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil }
|
bsw@1045
|
67 ui.submit{ text = _"update area" }
|
bsw@1045
|
68 slot.put(" ")
|
bsw@1045
|
69 ui.link{ module = "admin", view = "index", content = _"cancel" }
|
bsw@1045
|
70 end )
|
bsw@1045
|
71 end )
|
bsw/jbe@0
|
72 end
|
bsw/jbe@0
|
73 }
|