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