rev |
line source |
bsw@525
|
1 local id = param.get_id()
|
bsw@525
|
2
|
bsw/jbe@1309
|
3 local hint = not id
|
bsw/jbe@1309
|
4
|
bsw@525
|
5 local unit = Unit:by_id(id)
|
bsw@525
|
6
|
bsw@1184
|
7 ui.titleAdmin(_"Organizational unit")
|
bsw@525
|
8
|
bsw@595
|
9 local units = {
|
bsw@595
|
10 { id = nil, name = "" }
|
bsw@595
|
11 }
|
bsw@595
|
12
|
bsw@595
|
13 for i, unit in ipairs(Unit:get_flattened_tree()) do
|
bsw@595
|
14 units[#units+1] = { id = unit.id, name = unit.name }
|
bsw@525
|
15 end
|
bsw@525
|
16
|
bsw@1468
|
17 ui.grid{ content = function()
|
bsw@525
|
18
|
bsw@1468
|
19 ui.cell_main{ content = function()
|
bsw@1468
|
20 ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
|
bsw@1468
|
21 ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
|
bsw@1469
|
22 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = unit and unit.name or _"New organizational unit" }
|
bsw@1468
|
23 end }
|
bsw@1468
|
24 ui.container{ attr = { class = "mdl-card__content" }, content = function()
|
bsw@1468
|
25 ui.form{
|
bsw@1468
|
26 attr = { class = "vertical section" },
|
bsw@1468
|
27 module = "admin",
|
bsw@1468
|
28 action = "unit_update",
|
bsw@1468
|
29 id = unit and unit.id,
|
bsw@1468
|
30 record = unit,
|
bsw@1468
|
31 routing = {
|
bsw@1468
|
32 default = {
|
bsw@1468
|
33 mode = "redirect",
|
bsw@1468
|
34 modules = "admin",
|
bsw@1468
|
35 view = "index"
|
bsw@1468
|
36 }
|
bsw@1468
|
37 },
|
bsw@1468
|
38 content = function()
|
bsw@1468
|
39 ui.sectionRow( function()
|
bsw@1468
|
40 ui.field.select{
|
bsw@1468
|
41 label = _"Parent unit",
|
bsw@1468
|
42 name = "parent_id",
|
bsw@1468
|
43 foreign_records = units,
|
bsw@1468
|
44 foreign_id = "id",
|
bsw@1468
|
45 foreign_name = "name"
|
bsw@1468
|
46 }
|
bsw@1468
|
47 ui.field.text{ label = _"Name", name = "name" }
|
bsw@1468
|
48 ui.field.text{ label = _"Description", name = "description", multiline = true }
|
bsw@1468
|
49 ui.field.text{ label = _"External reference", name = "external_reference" }
|
bsw@1468
|
50 ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil }
|
bsw@1468
|
51
|
bsw@1468
|
52 slot.put("<br />")
|
bsw@1468
|
53 ui.submit{ text = _"update unit" }
|
bsw@1468
|
54 slot.put(" ")
|
bsw@1468
|
55 ui.link{ module = "admin", view = "index", content = _"cancel" }
|
bsw@1468
|
56 end )
|
bsw@1468
|
57 end
|
bsw@1468
|
58 }
|
bsw@1468
|
59 end }
|
bsw@1468
|
60 end }
|
bsw@1468
|
61 end }
|
bsw@1468
|
62 end }
|