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@1468: ui.grid{ content = function() bsw@525: bsw@1468: ui.cell_main{ content = function() bsw@1468: ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function() bsw@1468: ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function() bsw@1469: ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = unit and unit.name or _"New organizational unit" } bsw@1468: end } bsw@1468: ui.container{ attr = { class = "mdl-card__content" }, content = function() bsw@1468: ui.form{ bsw@1468: attr = { class = "vertical section" }, bsw@1468: module = "admin", bsw@1468: action = "unit_update", bsw@1468: id = unit and unit.id, bsw@1468: record = unit, bsw@1468: routing = { bsw@1468: default = { bsw@1468: mode = "redirect", bsw@1468: modules = "admin", bsw@1468: view = "index" bsw@1468: } bsw@1468: }, bsw@1468: content = function() bsw@1468: ui.sectionRow( function() bsw@1468: ui.field.select{ bsw@1468: label = _"Parent unit", bsw@1468: name = "parent_id", bsw@1468: foreign_records = units, bsw@1468: foreign_id = "id", bsw@1468: foreign_name = "name" bsw@1468: } bsw@1468: ui.field.text{ label = _"Name", name = "name" } bsw@1468: ui.field.text{ label = _"Description", name = "description", multiline = true } bsw@1468: ui.field.text{ label = _"External reference", name = "external_reference" } bsw@1555: ui.field.text{ label = _"Attr", name = "attr", value = unit and unit.attr or '{}' } bsw@1468: ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil } bsw@1468: bsw@1468: slot.put("
") bsw@1470: ui.submit{ bsw@1470: attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" }, bsw@1470: text = _"update unit" bsw@1470: } bsw@1468: slot.put(" ") bsw@1470: ui.link{ bsw@1470: attr = { class = "mdl-button mdl-js-button" }, bsw@1470: module = "admin", view = "index", content = _"cancel" bsw@1470: } bsw@1468: end ) bsw@1468: end bsw@1468: } bsw@1468: end } bsw@1468: end } bsw@1468: end } bsw@1468: end }