bsw/jbe@0: local id = param.get_id()
bsw/jbe@0: 
bsw@193: local member = Member:by_id(id)
bsw@193: 
bsw@1088: local deactivated = member and member.locked and member.login == nil and member.authority_login == nil
bsw@1088: 
bsw@1184: ui.titleAdmin(_"Member")
bsw/jbe@0: 
bsw@513: local units_selector = Unit:new_selector()
bsw@512:   
bsw@513: if member then
bsw@513:   units_selector
bsw@513:     :left_join("privilege", nil, { "privilege.member_id = ? AND privilege.unit_id = unit.id", member.id })
bsw@513:     :add_field("privilege.voting_right", "voting_right")
bsw@1438:     :add_order_by("unit.name")
bsw@513: end
bsw@513: 
bsw@513: local units = units_selector:exec()
bsw@512:   
bsw@1455: ui.grid{ content = function()
bsw@310: 
bsw@1455:   ui.cell_main{ content = function()
bsw@1455:     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
bsw@1455:       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
bsw@1455:         ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Member" }
bsw@1455:       end }
bsw@1455:       ui.container{ attr = { class = "mdl-card__content" }, content = function()
bsw@1455:         ui.form{
bsw@1455:           attr = { class = "vertical section" },
bsw@1455:           module = "admin",
bsw@1455:           action = "member_update",
bsw@1455:           id = member and member.id,
bsw@1455:           record = member,
bsw@1455:           readonly = not app.session.member.admin,
bsw@1455:           routing = {
bsw@1455:             default = {
bsw@1455:               mode = "redirect",
bsw@1455:               modules = "admin",
bsw@1455:               view = "index"
bsw@1455:             }
bsw@1455:           },
bsw@1455:           content = function()
bsw@1455: 
bsw@1456:             ui.field.text{     label = _"Identification", name = "identification" }
bsw@1456:             ui.field.text{     label = _"Notification email (confirmed)", name = "notify_email" }
bsw@1456:             ui.field.text{     label = _"Notification email (unconfirmed)", name = "notify_email_unconfirmed" }
bsw@1458:             
bsw@1456:             if member and member.activated then
bsw@1456:               ui.field.text{     label = _"Screen name",        name = "name" }
bsw@1456:             end
bsw@1456:             
bsw@1456:             if member and member.activated and not deactivated then
bsw@1456:               ui.field.text{     label = _"Login name",        name = "login" }
bsw@1456:             end
bsw@1088: 
bsw@1456:             for i, unit in ipairs(units) do
bsw@1456:               ui.field.boolean{
bsw@1459:                 name = "unit_" .. unit.id,
bsw@1459:                 label = unit.name,
bsw@1459:                 value = unit.voting_right
bsw@1459:               }
bsw@1458:             end
bsw@1455:             slot.put("
")
bsw@1045: 
bsw@1455:             if member then
bsw@1455:               ui.field.text{  label = _"Activated",       name = "activated", readonly = true }
bsw@1455:             end
bsw@1455:               
bsw@1455:             if not member or not member.activated then
bsw@1455:               ui.field.boolean{  label = _"Send invite?",       name = "invite_member" }
bsw@1455:             end
bsw@1455:             
bsw@1455:             if member then
bsw@1455:               ui.field.boolean{ 
bsw@1455:                 label = _"Member inactive?", name = "deactivate",
bsw@1455:                 readonly = true, 
bsw@1455:                 value = member and member.active == false
bsw@1455:               }
bsw@1455:             end
bsw@1455:             
bsw@1455:             if member then
bsw@1455:               ui.field.boolean{
bsw@1455:                 label = _"Lock member?", name = "locked",
bsw@1455:               }
bsw@1455:             end
bsw@1455:             
bsw@1455:             slot.put("
")
bsw@1455:             ui.field.boolean{  label = _"Admin?", name = "admin" }
bsw@1455:             slot.put("
")
bsw@1461:             ui.submit{
bsw@1461:               attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" },
bsw@1461:               text  = _"update member"
bsw@1461:             }
bsw@1455:             slot.put(" ")
bsw@1455:             if member then
bsw@1461:               ui.link { 
bsw@1461:                 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
bsw@1461:                 module = "admin", view = "member_deactivate", content = _"Deactivate member", id = member.id 
bsw@1461:               }
bsw@1455:               slot.put(" ")
bsw@1455:             end
bsw@1461:             ui.link {
bsw@1461:                 attr = { class = "mdl-button mdl-js-button" },
bsw@1461:                 module = "admin", view = "index", content = _"cancel"
bsw@1461:             }
bsw@1456: 
bsw@1457:           end
bsw@1457:         }
bsw@1457:       end }
bsw@1455:     end }
bsw@1455:   end }
bsw@1455: end }