liquid_feedback_frontend
view app/main/admin/member_edit.lua @ 1641:ab837b075cf7
Fixed mldap_get_named_number_arg to not leave any element on the Lua stack (should not have had any effect anyway but is now consistent to documentation)
| author | jbe | 
|---|---|
| date | Tue Feb 09 17:44:47 2021 +0100 (2021-02-09) | 
| parents | a17ad625ffbc | 
| children | 40a388c07af9 | 
 line source
     1 local function field(name, label, value, tooltip)
     2   ui.field.text{
     3     container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" },
     4     attr = { id = "field_" .. name, class = "mdl-textfield__input" },
     5     label_attr = { class = "mdl-textfield__label", ["for"] = "field_" .. name },
     6     label = label,
     7     name = name,
     8     value = value or nil
     9   }
    10   if tooltip then
    11     ui.container{ attr = { class = "mdl-tooltip", ["for"] = "field_" .. name }, content = tooltip }
    12   end
    13 end
    15 local function field_boolean(id, name, checked, label)
    16   ui.container{ content = function()
    17     ui.tag{ tag = "label", attr = {
    18         class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
    19         ["for"] = id
    20       },
    21       content = function()
    22         ui.tag{
    23           tag = "input",
    24           attr = {
    25             id = id,
    26             class = "mdl-checkbox__input",
    27             type = "checkbox", name = name, value = "true",
    28             checked = checked and "checked" or nil,
    29           }
    30         }
    31         ui.tag{
    32           attr = { class = "mdl-checkbox__label", ['for'] = id },
    33           content = label
    34         } 
    35       end
    36     }
    37   end }
    38 end
    40 local id = param.get_id()
    42 local member = Member:by_id(id)
    44 local deactivated = member and member.locked and member.login == nil and member.authority_login == nil
    46 ui.titleAdmin(_"Member")
    48 local units_selector = Unit:new_selector()
    50 if member then
    51   units_selector
    52     :left_join("privilege", nil, { "privilege.member_id = ? AND privilege.unit_id = unit.id", member.id })
    53     :add_field("privilege.voting_right", "voting_right")
    54     :add_order_by("unit.name")
    55 end
    57 local units = units_selector:exec()
    59 ui.grid{ content = function()
    61   ui.cell_main{ content = function()
    62     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
    63       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
    64         local text = _"Member"
    65         if member then
    66           text = text .. " ID " .. member.id
    67         end
    68         ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = text }
    69       end }
    70       ui.container{ attr = { class = "mdl-card__content" }, content = function()
    71         ui.form{
    72           attr = { class = "vertical section" },
    73           module = "admin",
    74           action = "member_update",
    75           id = member and member.id,
    76           record = member,
    77           readonly = not app.session.member.admin,
    78           routing = {
    79             default = {
    80               mode = "redirect",
    81               modules = "admin",
    82               view = "index"
    83             }
    84           },
    85           content = function()
    87             ui.container{ content = function()
    88               field("identification", _"Identification")
    89               if member and member.activated then
    90                 slot.put("   ")
    91                 field("name", "Screen name")
    92               end
    93             end }
    94             ui.container{ content = function()
    95               field("notify_email", _"Notification email (confirmed)")
    96               slot.put("   ")
    97               field("notify_email_unconfirmed", _"Notification email (unconfirmed)")
    98             end }
    99 --            field("", "")
   102             if member and member.activated and not deactivated then
   103               field("login", "Login name")
   104             end
   106             for i, unit in ipairs(units) do
   107               field_boolean("checkbox_unit_" .. unit.id, "unit_" .. unit.id, unit.voting_right, unit.name)
   109             end
   110             slot.put("<br />")
   112             if member then
   113               ui.field.text{  label = _"Activated",       name = "activated", readonly = true }
   114             end
   116             if not member or not member.activated then
   117               ui.field.boolean{  label = _"Send invite?",       name = "invite_member" }
   118             end
   120             if member then
   121               ui.field.boolean{ 
   122                 label = _"Member inactive?", name = "deactivate",
   123                 readonly = true, 
   124                 value = member and member.active == false
   125               }
   126             end
   128             if member then
   129               ui.field.boolean{
   130                 label = _"Lock member?", name = "locked",
   131               }
   132             end
   134             slot.put("<br />")
   135             ui.field.boolean{  label = _"Admin?", name = "admin" }
   136             slot.put("<br />")
   137             ui.submit{
   138               attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" },
   139               text  = _"update member"
   140             }
   141             slot.put("   ")
   142             if member then
   143               ui.link { 
   144                 attr = { class = "mdl-button mdl-js-button" },
   145                 module = "admin", view = "member_deactivate", content = _"Deactivate member", id = member.id 
   146               }
   147               slot.put("   ")
   148             end
   149             ui.link {
   150                 attr = { class = "mdl-button mdl-js-button" },
   151                 module = "admin", view = "index", content = _"cancel"
   152             }
   154           end
   155         }
   156       end }
   157     end }
   158   end }
   159 end }
