bsw/jbe@0: local id = param.get_id() bsw/jbe@0: bsw@1045: local hint = not id bsw@1045: bsw@193: local area = Area:by_id(id) or Area:new() bsw@193: bsw@263: if not area.unit_id then bsw@263: area.unit_id = param.get("unit_id", atom.integer) bsw@263: end bsw@263: bsw@1045: ui.titleAdmin(_"area") bsw/jbe@0: bsw/jbe@0: ui.form{ bsw@1045: attr = { class = "vertical section" }, bsw/jbe@0: record = area, bsw/jbe@5: module = "admin", bsw/jbe@5: action = "area_update", bsw/jbe@0: routing = { bsw@1045: ok = { bsw/jbe@0: mode = "redirect", bsw/jbe@0: module = "admin", bsw@1045: view = "index", bsw@263: params = { unit_id = area.unit_id } bsw@1045: }, bsw/jbe@0: }, bsw@193: id = id, bsw/jbe@0: content = function() bsw@193: policies = Policy:build_selector{ active = true }:exec() poelzi@126: local def_policy = { poelzi@126: { poelzi@126: id = "-1", poelzi@126: name = _"No default" poelzi@126: } poelzi@126: } poelzi@126: for i, record in ipairs(policies) do poelzi@126: def_policy[#def_policy+1] = record poelzi@126: end poelzi@126: bsw@1045: bsw@1045: ui.section( function() bsw@1045: ui.sectionHead( function() bsw@1045: ui.heading { level = 1, content = area.name or _"New area" } bsw@1045: end ) bsw@1045: bsw@1045: ui.sectionRow( function() bsw@1045: bsw@1045: ui.field.hidden{ name = "unit_id", value = area.unit_id } bsw@1045: ui.field.text{ label = _"Unit", value = area.unit.name, readonly = true } bsw@1045: ui.field.text{ label = _"Name", name = "name" } bsw@1045: ui.field.text{ label = _"Description", name = "description", multiline = true } bsw@1045: ui.field.select{ label = _"Default Policy", name = "default_policy", bsw@1045: value=area.default_policy and area.default_policy.id or "-1", bsw@1045: foreign_records = def_policy, bsw@1045: foreign_id = "id", bsw@1045: foreign_name = "name" bsw@1045: } bsw@1045: ui.heading { level = 3, content = _"Allowed policies" } bsw@1045: ui.multiselect{ name = "allowed_policies[]", bsw@1045: foreign_records = policies, bsw@1045: foreign_id = "id", bsw@1045: foreign_name = "name", bsw@1045: connecting_records = area.allowed_policies or {}, bsw@1045: foreign_reference = "id", bsw@1045: } bsw@1045: slot.put("

") bsw@1045: ui.field.boolean{ label = _"Active?", name = "active", value = hint and true or nil } bsw@1045: ui.submit{ text = _"update area" } bsw@1045: slot.put(" ") bsw@1045: ui.link{ module = "admin", view = "index", content = _"cancel" } bsw@1045: end ) bsw@1045: end ) bsw/jbe@0: end bsw/jbe@0: }