liquid_feedback_frontend
view app/main/admin/area_show.lua @ 1201:ccc357ccb68c
Going to version 3.0.7
| author | bsw | 
|---|---|
| date | Tue Jun 23 19:58:17 2015 +0200 (2015-06-23) | 
| parents | d83ecd35458c | 
| children | fede09736f2b | 
 line source
     1 local id = param.get_id()
     3 local hint = not id
     5 local area = Area:by_id(id) or Area:new()
     7 if not area.unit_id then
     8   area.unit_id = param.get("unit_id", atom.integer)
     9 end
    11 ui.titleAdmin(_"area")
    13 ui.form{
    14   attr = { class = "vertical section" },
    15   record = area,
    16   module = "admin",
    17   action = "area_update",
    18   routing = {
    19     ok = {
    20       mode = "redirect",
    21       module = "admin",
    22       view = "index",
    23       params = { unit_id = area.unit_id }
    24     },
    25   },
    26   id = id,
    27   content = function()
    28     local policies = Policy:build_selector{ active = true }:exec()
    29     local def_policy = {
    30       {
    31         id = "-1",
    32         name = _"No default"
    33       }
    34     }
    35     for i, record in ipairs(policies) do
    36       def_policy[#def_policy+1] = record
    37     end
    40     ui.section( function()
    41       ui.sectionHead( function()
    42         ui.heading { level = 1, content = area.name or _"New area" }
    43       end )
    45       ui.sectionRow( function()
    47         ui.field.hidden{ name = "unit_id", value = area.unit_id }
    48         ui.field.text{    label = _"Unit", value = area.unit.name, readonly = true }
    49         ui.field.text{    label = _"Name",        name = "name" }
    50         ui.field.text{    label = _"Description", name = "description", multiline = true }
    51         ui.field.select{  label = _"Default Policy",   name = "default_policy",
    52                     value=area.default_policy and area.default_policy.id or "-1",
    53                     foreign_records = def_policy,
    54                     foreign_id      = "id",
    55                     foreign_name    = "name"
    56         }
    57         ui.heading { level = 3, content = _"Allowed policies" }
    58         ui.multiselect{   name = "allowed_policies[]",
    59                           foreign_records = policies,
    60                           foreign_id      = "id",
    61                           foreign_name    = "name",
    62                           connecting_records = area.allowed_policies or {},
    63                           foreign_reference  = "id",
    64         }
    65         slot.put("<br /><br />")
    66         ui.field.boolean{ label = _"Active?",     name = "active", value = hint and true or nil }
    67         ui.submit{ text = _"update area" }
    68         slot.put(" ")
    69         ui.link{ module = "admin", view = "index", content = _"cancel" }
    70       end )
    71     end )
    72   end
    73 }
