liquid_feedback_frontend
view app/main/lf2/delegation.lua @ 214:7e3acb2f6284
Disable current member as delegation target through initiatorship
| author | bsw | 
|---|---|
| date | Thu Mar 03 23:47:35 2011 +0100 (2011-03-03) | 
| parents | acf92c2d33f4 | 
| children | 1dab81353eb1 | 
 line source
     1 slot.set_layout("lf2")
     3 local area = Area:by_id(param.get("area_id", atom.integer))
     4 local issue = Issue:by_id(param.get("issue_id", atom.integer))
     5 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
     7 local contact_members = Member:build_selector{
     8   is_contact_of_member_id = app.session.member_id,
     9   order = "name"
    10 }:exec()
    12 if area then
    13   title = _"Set delegation for Area '#{name}'":gsub("#{name}", area.name)
    14 end
    16 if issue then
    17   title = _"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name)
    18 end
    20 if not area and not issue then
    21   title = _"Set unit delegation"
    22 end
    24 ui.box{ content = function()
    26   ui.box_row{ class = "head", content = function() ui.box_col{ class = "head", content = title } end }
    28   ui.form{
    29     attr = { class = "vertical" },
    30     module = "delegation",
    31     action = "update",
    32     params = {
    33       area_id = area and area.id or nil,
    34       issue_id = issue and issue.id or nil,
    35     },
    36     routing = {
    37       default = {
    38         mode = "redirect",
    39         module = "lf2",
    40         view = area and "area" or initiative and "initiative" or issue and "issue" or "index",
    41         id = area and area.id or initiative and initiative.id or issue and issue.id or nil,
    42       }
    43     },
    44     content = function()
    45       local records
    47       if issue then
    48         local delegate_name = ""
    49         local scope = "no delegation set"
    50         local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id)
    51         if area_delegation then
    52           delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
    53           scope = _"area"
    54         else
    55         local unit_delegation = Delegation:by_pk(app.session.member_id)
    56         if unit_delegation then
    57           delegate_name = unit_delegation.trustee.name
    58           scope = _"unit"
    59         end
    60       end
    61         records = {
    62           {
    63             id = -1,
    64             name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    65           },
    66           {
    67             id = 0,
    68             name = _"Abandon unit and area delegations for this issue"
    69           },
    71         }
    72       elseif area then
    73         local delegate_name = ""
    74         local scope = "no delegation set"
    75         local unit_delegation = Delegation:by_pk(app.session.member_id)
    76         if unit_delegation then
    77           delegate_name = unit_delegation.trustee.name
    78           scope = _"unit"
    79         end
    80         records = {
    81           {
    82             id = -1,
    83             name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    84           },
    85           {
    86             id = 0,
    87             name = _"Abandon unit delegation for this area"
    88           }
    89         }
    91       else
    92         records = {
    93           {
    94             id = -1,
    95             name = _"No delegation"
    96           }
    97         }
    99       end
   100       disabled_records = {}
   101       disabled_records["_"] = true
   103       -- add saved members
   104       records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   105       for i, record in ipairs(contact_members) do
   106         records[#records+1] = record
   107       end
   109       -- add initiative authors
   110       if initiative then
   111         records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   112         for i,record in ipairs(initiative.initiators) do
   113           records[#records+1] = record.member
   114           if record.member.id == app.session.member_id then
   115             disabled_records[record.member.id] = true
   116           end
   117         end
   118       end
   122       ui.box_row{ content = function() ui.box_col{ content = function()
   123         ui.field.select{
   124           label = _"Trustee",
   125           name = "trustee_id",
   126           foreign_records = records,
   127           foreign_id = "id",
   128           foreign_name = "name",
   129           disabled_records = disabled_records
   130         }
   131       end } end }
   133       ui.box_row{ content = function() ui.box_col{ content = function()
   134         ui.submit{ text = _"Save" }
   135       end } end }
   136     end
   137   }
   139 end }
