| rev | 
   line source | 
| 
bsw/jbe@0
 | 
     1 local id = param.get_id()
 | 
| 
bsw/jbe@0
 | 
     2 
 | 
| 
bsw@193
 | 
     3 local area = Area:by_id(id) or Area:new()
 | 
| 
bsw@193
 | 
     4 
 | 
| 
bsw@263
 | 
     5 if not area.unit_id then
 | 
| 
bsw@263
 | 
     6   area.unit_id = param.get("unit_id", atom.integer)
 | 
| 
bsw@263
 | 
     7 end
 | 
| 
bsw@263
 | 
     8 
 | 
| 
bsw@603
 | 
     9 ui.title(_"Create / edit area")
 | 
| 
bsw/jbe@0
 | 
    10 
 | 
| 
bsw/jbe@0
 | 
    11 ui.form{
 | 
| 
bsw/jbe@0
 | 
    12   attr = { class = "vertical" },
 | 
| 
bsw/jbe@0
 | 
    13   record = area,
 | 
| 
bsw/jbe@5
 | 
    14   module = "admin",
 | 
| 
bsw/jbe@5
 | 
    15   action = "area_update",
 | 
| 
bsw/jbe@0
 | 
    16   routing = {
 | 
| 
bsw/jbe@0
 | 
    17     default = {
 | 
| 
bsw/jbe@0
 | 
    18       mode = "redirect",
 | 
| 
bsw/jbe@0
 | 
    19       module = "admin",
 | 
| 
bsw@263
 | 
    20       view = "area_list",
 | 
| 
bsw@263
 | 
    21       params = { unit_id = area.unit_id }
 | 
| 
bsw/jbe@0
 | 
    22     }
 | 
| 
bsw/jbe@0
 | 
    23   },
 | 
| 
bsw@193
 | 
    24   id = id,
 | 
| 
bsw/jbe@0
 | 
    25   content = function()
 | 
| 
bsw@193
 | 
    26     policies = Policy:build_selector{ active = true }:exec()
 | 
| 
poelzi@126
 | 
    27     local def_policy = {
 | 
| 
poelzi@126
 | 
    28       {
 | 
| 
poelzi@126
 | 
    29         id = "-1",
 | 
| 
poelzi@126
 | 
    30         name = _"No default"
 | 
| 
poelzi@126
 | 
    31       }
 | 
| 
poelzi@126
 | 
    32     }
 | 
| 
poelzi@126
 | 
    33     for i, record in ipairs(policies) do
 | 
| 
poelzi@126
 | 
    34       def_policy[#def_policy+1] = record
 | 
| 
poelzi@126
 | 
    35     end
 | 
| 
poelzi@126
 | 
    36 
 | 
| 
bsw@263
 | 
    37     ui.field.hidden{ name = "unit_id", value = area.unit_id }
 | 
| 
bsw@263
 | 
    38     ui.field.text{    label = _"Unit", value = area.unit.name, readonly = true }
 | 
| 
bsw/jbe@0
 | 
    39     ui.field.text{    label = _"Name",        name = "name" }
 | 
| 
bsw/jbe@0
 | 
    40     ui.field.text{    label = _"Description", name = "description", multiline = true }
 | 
| 
bsw@193
 | 
    41     ui.field.select{  label = _"Default Policy",   name = "default_policy",
 | 
| 
poelzi@126
 | 
    42                  value=area.default_policy and area.default_policy.id or "-1",
 | 
| 
poelzi@126
 | 
    43                  foreign_records = def_policy,
 | 
| 
poelzi@126
 | 
    44                  foreign_id      = "id",
 | 
| 
poelzi@126
 | 
    45                  foreign_name    = "name"
 | 
| 
poelzi@126
 | 
    46     }
 | 
| 
poelzi@119
 | 
    47     ui.multiselect{   label = _"Policies",    name = "allowed_policies[]",
 | 
| 
poelzi@126
 | 
    48                       foreign_records = policies,
 | 
| 
poelzi@119
 | 
    49                       foreign_id      = "id",
 | 
| 
poelzi@119
 | 
    50                       foreign_name    = "name",
 | 
| 
bsw@193
 | 
    51                       connecting_records = area.allowed_policies or {},
 | 
| 
bsw@193
 | 
    52                       foreign_reference  = "id",
 | 
| 
bsw@193
 | 
    53     }
 | 
| 
bsw@263
 | 
    54     slot.put("<br /><br />")
 | 
| 
bsw@263
 | 
    55     ui.field.boolean{ label = _"Active?",     name = "active" }
 | 
| 
bsw/jbe@0
 | 
    56     ui.submit{ text = _"Save" }
 | 
| 
bsw/jbe@0
 | 
    57   end
 | 
| 
bsw/jbe@0
 | 
    58 }
 |