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