liquid_feedback_frontend
view app/main/delegation/new.lua @ 293:a72a389399fc
Fixed to issues with modified delegation code
| author | bsw | 
|---|---|
| date | Sat Feb 25 20:36:31 2012 +0100 (2012-02-25) | 
| parents | 7196685f9dd7 | 
| children | c4dd225578d4 | 
 line source
     1 local unit = Unit:by_id(param.get("unit_id", atom.integer))
     2 if unit then
     3   slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
     4   util.help("delegation.new.unit")
     5 end
     7 local area = Area:by_id(param.get("area_id", atom.integer))
     8 if area then
     9   slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
    10   util.help("delegation.new.area")
    11 end
    13 local issue = Issue:by_id(param.get("issue_id", atom.integer))
    14 if issue then
    15   slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name)))
    16   util.help("delegation.new.issue")
    17 end
    19 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
    21 slot.select("actions", function()
    22   if issue then
    23     ui.link{
    24       module = "issue",
    25       view = "show",
    26       id = issue.id,
    27       content = function()
    28           ui.image{ static = "icons/16/cancel.png" }
    29           slot.put(_"Cancel")
    30       end,
    31     }
    32   elseif area then
    33     ui.link{
    34       module = "area",
    35       view = "show",
    36       id = area.id,
    37       content = function()
    38           ui.image{ static = "icons/16/cancel.png" }
    39           slot.put(_"Cancel")
    40       end,
    41     }
    42   else
    43     ui.link{
    44       module = "index",
    45       view = "index",
    46       content = function()
    47           ui.image{ static = "icons/16/cancel.png" }
    48           slot.put(_"Cancel")
    49       end,
    50     }
    51   end
    52 end)
    55 local contact_members = Member:build_selector{
    56   is_contact_of_member_id = app.session.member_id,
    57   order = "name"
    58 }:exec()
    60 ui.form{
    61   attr = { class = "vertical" },
    62   module = "delegation",
    63   action = "update",
    64   params = {
    65     unit_id = unit and unit.id or nil,
    66     area_id = area and area.id or nil,
    67     issue_id = issue and issue.id or nil,
    68   },
    69   routing = {
    70     default = {
    71       mode = "redirect",
    72       module = area and "area" or issue and "issue" or "area",
    73       view = (area or issue) and "show" or "list",
    74       id = area and area.id or issue and issue.id or nil,
    75       params = { unit_id = unit and unit.id or nil }
    76     }
    77   },
    78   content = function()
    79     local records
    81     if issue then
    82       local delegate_name = ""
    83       local scope = "no delegation set"
    84       local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
    85       if area_delegation then
    86         delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
    87         scope = _"area"
    88       else
    89         local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
    90         if unit_delegation then
    91           delegate_name = unit_delegation.trustee.name
    92           scope = config.single_unit_id and _"global" or _"unit"
    93         end
    94       end
    95       local text_apply
    96       local text_abandon
    97       if config.single_unit_id then
    98         text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    99         text_abandon = _"Abandon unit and area delegations for this issue"
   100       else
   101         text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   102         text_abandon = _"Abandon unit and area delegations for this issue"
   103       end
   104       records = {
   105         { id = -1, name = text_apply },
   106         { id = 0,  name = text_abandon }
   107       }
   108     elseif area then
   109       local delegate_name = ""
   110       local scope = "no delegation set"
   111       local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
   112       if unit_delegation then
   113         delegate_name = unit_delegation.trustee.name
   114         scope = config.single_unit_id and _"global" or _"unit"
   115       end
   116       local text_apply
   117       local text_abandon
   118       if config.single_unit_id then
   119         text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   120         text_abandon = _"Abandon global delegation for this area"
   121       else
   122         text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   123         text_abandon = _"Abandon unit delegation for this area"
   124       end
   125       records = {
   126         {
   127           id = -1,
   128           name = text_apply
   129         },
   130         {
   131           id = 0,
   132           name = text_abandon
   133         }
   134       }
   136     else
   137       records = {
   138         {
   139           id = -1,
   140           name = _"No delegation"
   141         }
   142       }
   144     end
   145     -- add saved members
   146     records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   147     for i, record in ipairs(contact_members) do
   148       records[#records+1] = record
   149     end
   150     -- add initiative authors
   151     if initiative then
   152       records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   153       for i,record in ipairs(initiative.initiators) do
   154         records[#records+1] = record.member
   155       end
   156     end
   158     disabled_records = {}
   159     disabled_records["_"] = true
   161     ui.field.select{
   162       label = _"Trustee",
   163       name = "trustee_id",
   164       foreign_records = records,
   165       foreign_id = "id",
   166       foreign_name = "name",
   167       disabled_records = disabled_records
   168     }
   170     ui.submit{ text = _"Save" }
   171   end
   172 }
