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@1832
|
14 local name = ""
|
bsw@1832
|
15 for j = 2, unit.depth do
|
bsw@1832
|
16 name = name .. utf8.char(160).. utf8.char(160).. utf8.char(160).. utf8.char(160)
|
bsw@1832
|
17 end
|
bsw@1832
|
18 local name = name .. unit.name
|
bsw@1832
|
19 units[#units+1] = { id = unit.id, name = name }
|
bsw@525
|
20 end
|
bsw@525
|
21
|
bsw@1468
|
22 ui.grid{ content = function()
|
bsw@525
|
23
|
bsw@1468
|
24 ui.cell_main{ content = function()
|
bsw@1468
|
25 ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
|
bsw@1468
|
26 ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
|
bsw@1469
|
27 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = unit and unit.name or _"New organizational unit" }
|
bsw@1468
|
28 end }
|
bsw@1468
|
29 ui.container{ attr = { class = "mdl-card__content" }, content = function()
|
bsw@1468
|
30 ui.form{
|
bsw@1468
|
31 attr = { class = "vertical section" },
|
bsw@1468
|
32 module = "admin",
|
bsw@1468
|
33 action = "unit_update",
|
bsw@1468
|
34 id = unit and unit.id,
|
bsw@1468
|
35 record = unit,
|
bsw@1468
|
36 routing = {
|
bsw@1468
|
37 default = {
|
bsw@1468
|
38 mode = "redirect",
|
bsw@1468
|
39 modules = "admin",
|
bsw@1468
|
40 view = "index"
|
bsw@1468
|
41 }
|
bsw@1468
|
42 },
|
bsw@1468
|
43 content = function()
|
bsw@1468
|
44 ui.sectionRow( function()
|
bsw@1468
|
45 ui.field.select{
|
bsw@1468
|
46 label = _"Parent unit",
|
bsw@1468
|
47 name = "parent_id",
|
bsw@1468
|
48 foreign_records = units,
|
bsw@1468
|
49 foreign_id = "id",
|
bsw@1468
|
50 foreign_name = "name"
|
bsw@1468
|
51 }
|
bsw@1468
|
52 ui.field.text{ label = _"Name", name = "name" }
|
bsw@1468
|
53 ui.field.text{ label = _"Description", name = "description", multiline = true }
|
bsw@1468
|
54 ui.field.text{ label = _"External reference", name = "external_reference" }
|
bsw@1555
|
55 ui.field.text{ label = _"Attr", name = "attr", value = unit and unit.attr or '{}' }
|
bsw@1468
|
56 ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil }
|
bsw@1468
|
57
|
bsw@1468
|
58 slot.put("<br />")
|
bsw@1470
|
59 ui.submit{
|
bsw@1470
|
60 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" },
|
bsw@1470
|
61 text = _"update unit"
|
bsw@1470
|
62 }
|
bsw@1468
|
63 slot.put(" ")
|
bsw@1470
|
64 ui.link{
|
bsw@1470
|
65 attr = { class = "mdl-button mdl-js-button" },
|
bsw@1470
|
66 module = "admin", view = "index", content = _"cancel"
|
bsw@1470
|
67 }
|
bsw@1468
|
68 end )
|
bsw@1468
|
69 end
|
bsw@1468
|
70 }
|
bsw@1468
|
71 end }
|
bsw@1468
|
72 end }
|
bsw@1468
|
73 end }
|
bsw@1468
|
74 end }
|