| rev | 
   line source | 
| 
bsw/jbe@0
 | 
     1 local id = param.get_id()
 | 
| 
bsw/jbe@0
 | 
     2 
 | 
| 
bsw@1045
 | 
     3 local hint = not id
 | 
| 
bsw@1045
 | 
     4 
 | 
| 
bsw@193
 | 
     5 local area = Area:by_id(id) or Area:new()
 | 
| 
bsw@193
 | 
     6 
 | 
| 
bsw@263
 | 
     7 if not area.unit_id then
 | 
| 
bsw@263
 | 
     8   area.unit_id = param.get("unit_id", atom.integer)
 | 
| 
bsw@263
 | 
     9 end
 | 
| 
bsw@263
 | 
    10 
 | 
| 
bsw@1045
 | 
    11 ui.titleAdmin(_"area")
 | 
| 
bsw/jbe@0
 | 
    12 
 | 
| 
bsw@1468
 | 
    13 ui.grid{ content = function()
 | 
| 
bsw@1468
 | 
    14 
 | 
| 
bsw@1468
 | 
    15   ui.cell_main{ content = function()
 | 
| 
bsw@1468
 | 
    16     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
 | 
| 
bsw@1468
 | 
    17       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
 | 
| 
bsw@1469
 | 
    18         ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = area.name or _"New area" }
 | 
| 
bsw@1468
 | 
    19       end }
 | 
| 
bsw@1468
 | 
    20       ui.container{ attr = { class = "mdl-card__content" }, content = function()
 | 
| 
bsw@1468
 | 
    21         ui.form{
 | 
| 
bsw@1468
 | 
    22           attr = { class = "vertical section" },
 | 
| 
bsw@1468
 | 
    23           record = area,
 | 
| 
bsw@1468
 | 
    24           module = "admin",
 | 
| 
bsw@1468
 | 
    25           action = "area_update",
 | 
| 
bsw@1468
 | 
    26           routing = {
 | 
| 
bsw@1468
 | 
    27             ok = {
 | 
| 
bsw@1468
 | 
    28               mode = "redirect",
 | 
| 
bsw@1468
 | 
    29               module = "admin",
 | 
| 
bsw@1468
 | 
    30               view = "index",
 | 
| 
bsw@1468
 | 
    31               params = { unit_id = area.unit_id }
 | 
| 
bsw@1468
 | 
    32             },
 | 
| 
bsw@1468
 | 
    33           },
 | 
| 
bsw@1468
 | 
    34           id = id,
 | 
| 
bsw@1468
 | 
    35           content = function()
 | 
| 
bsw@1468
 | 
    36             local policies = Policy:build_selector{ active = true }:exec()
 | 
| 
bsw@1468
 | 
    37             local def_policy = {
 | 
| 
bsw@1468
 | 
    38               {
 | 
| 
bsw@1468
 | 
    39                 id = "-1",
 | 
| 
bsw@1468
 | 
    40                 name = _"No default"
 | 
| 
bsw@1468
 | 
    41               }
 | 
| 
bsw@1468
 | 
    42             }
 | 
| 
bsw@1468
 | 
    43             for i, record in ipairs(policies) do
 | 
| 
bsw@1468
 | 
    44               def_policy[#def_policy+1] = record
 | 
| 
bsw@1468
 | 
    45             end
 | 
| 
poelzi@126
 | 
    46 
 | 
| 
bsw@1468
 | 
    47             
 | 
| 
bsw@1468
 | 
    48             ui.section( function()
 | 
| 
bsw@1468
 | 
    49               ui.sectionRow( function()
 | 
| 
bsw@1468
 | 
    50                 
 | 
| 
bsw@1468
 | 
    51                 ui.field.hidden{ name = "unit_id", value = area.unit_id }
 | 
| 
bsw@1468
 | 
    52                 ui.field.text{    label = _"Unit", value = area.unit.name, readonly = true }
 | 
| 
bsw@1468
 | 
    53                 ui.field.text{    label = _"Name",        name = "name" }
 | 
| 
bsw@1468
 | 
    54                 ui.field.text{    label = _"Description", name = "description", multiline = true }
 | 
| 
bsw@1468
 | 
    55                 ui.field.text{    label = _"External reference", name = "external_reference" }
 | 
| 
bsw@1468
 | 
    56                 ui.field.select{  label = _"Default Policy",   name = "default_policy",
 | 
| 
bsw@1468
 | 
    57                             value=area.default_policy and area.default_policy.id or "-1",
 | 
| 
bsw@1468
 | 
    58                             foreign_records = def_policy,
 | 
| 
bsw@1468
 | 
    59                             foreign_id      = "id",
 | 
| 
bsw@1468
 | 
    60                             foreign_name    = "name"
 | 
| 
bsw@1468
 | 
    61                 }
 | 
| 
bsw@1468
 | 
    62                 ui.heading { level = 3, content = _"Allowed policies" }
 | 
| 
bsw@1468
 | 
    63                 ui.multiselect{   name = "allowed_policies[]",
 | 
| 
bsw@1468
 | 
    64                                   foreign_records = policies,
 | 
| 
bsw@1468
 | 
    65                                   foreign_id      = "id",
 | 
| 
bsw@1468
 | 
    66                                   foreign_name    = "name",
 | 
| 
bsw@1468
 | 
    67                                   connecting_records = area.allowed_policies or {},
 | 
| 
bsw@1468
 | 
    68                                   foreign_reference  = "id",
 | 
| 
bsw@1468
 | 
    69                 }
 | 
| 
bsw@1471
 | 
    70                 slot.put("<br /><br />")
 | 
| 
bsw@1468
 | 
    71                 ui.field.text{    label = _"Admission quorum standard", name = "quorum_standard", value = hint and 10 or nil }
 | 
| 
bsw@1468
 | 
    72                 ui.field.text{    label = _"Admission quorum issues", name = "quorum_issues", value = hint and 10 or nil }
 | 
| 
bsw@1468
 | 
    73                 ui.field.text{    label = _"Admission quorum time", name = "quorum_time", value = hint and "60 days" or nil }
 | 
| 
bsw@1468
 | 
    74                 ui.field.text{    label = _"Admission quorum exponent", name = "quorum_exponent", value = hint and 0.5 or nil }
 | 
| 
bsw@1468
 | 
    75                 ui.field.text{    label = _"Admission qourum factor", name = "quorum_factor", value = hint and 2 or nil }
 | 
| 
bsw@1468
 | 
    76                 slot.put("<br /><br />")
 | 
| 
bsw@1468
 | 
    77                 ui.field.boolean{ label = _"Active?",     name = "active", value = hint and true or nil }
 | 
| 
bsw@1470
 | 
    78                 ui.submit{
 | 
| 
bsw@1470
 | 
    79                   attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" },
 | 
| 
bsw@1470
 | 
    80                   text = _"update area"
 | 
| 
bsw@1470
 | 
    81                 }
 | 
| 
bsw@1468
 | 
    82                 slot.put(" ")
 | 
| 
bsw@1470
 | 
    83                 ui.link{
 | 
| 
bsw@1470
 | 
    84                   attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" },
 | 
| 
bsw@1470
 | 
    85                   module = "admin", view = "index", content = _"cancel"
 | 
| 
bsw@1470
 | 
    86                 }
 | 
| 
bsw@1468
 | 
    87               end )
 | 
| 
bsw@1468
 | 
    88             end )
 | 
| 
bsw@1468
 | 
    89           end
 | 
| 
bsw@1045
 | 
    90         }
 | 
| 
bsw@1468
 | 
    91       end }
 | 
| 
bsw@1468
 | 
    92     end }
 | 
| 
bsw@1468
 | 
    93   end }
 | 
| 
bsw@1468
 | 
    94 end }
 |