bsw@525: local id = param.get_id() bsw@525: bsw/jbe@1309: local hint = not id bsw/jbe@1309: bsw@525: local unit = Unit:by_id(id) bsw@525: bsw@1184: ui.titleAdmin(_"Organizational unit") bsw@525: bsw@595: local units = { bsw@595: { id = nil, name = "" } bsw@595: } bsw@595: bsw@595: for i, unit in ipairs(Unit:get_flattened_tree()) do bsw@595: units[#units+1] = { id = unit.id, name = unit.name } bsw@525: end bsw@525: bsw@525: ui.form{ bsw@1045: attr = { class = "vertical section" }, bsw@525: module = "admin", bsw@595: action = "unit_update", bsw@595: id = unit and unit.id, bsw@595: record = unit, bsw@525: routing = { bsw@525: default = { bsw@525: mode = "redirect", bsw@525: modules = "admin", bsw@1045: view = "index" bsw@525: } bsw@525: }, bsw@525: content = function() bsw@1045: ui.sectionHead( function() bsw@1045: ui.heading { level = 1, content = unit and unit.name or _"New organizational unit" } bsw@1045: end ) bsw@1045: ui.sectionRow( function() bsw@1045: ui.field.select{ bsw@1045: label = _"Parent unit", bsw@1045: name = "parent_id", bsw@1045: foreign_records = units, bsw@1045: foreign_id = "id", bsw@1045: foreign_name = "name" bsw@1045: } bsw@1045: ui.field.text{ label = _"Name", name = "name" } bsw@1045: ui.field.text{ label = _"Description", name = "description", multiline = true } bsw@1209: ui.field.text{ label = _"External reference", name = "external_reference" } bsw/jbe@1309: ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil } bsw@525: bsw@1045: slot.put("
") bsw@1045: ui.submit{ text = _"update unit" } bsw@1045: slot.put(" ") bsw@1045: ui.link{ module = "admin", view = "index", content = _"cancel" } bsw@1045: end ) bsw@525: end bsw@525: }