liquid_feedback_frontend
view app/main/delegation/new.lua @ 272:65a1f7a01e7b
More optical enhancements and repositioning of elements
| author | bsw | 
|---|---|
| date | Wed Feb 08 00:55:17 2012 +0100 (2012-02-08) | 
| parents | 1b8d51e21614 | 
| children | 7196685f9dd7 | 
 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 "index",
    73       view = (area or issue) and "show" or "index",
    74       id = area and area.id or issue and issue.id or nil,
    75     }
    76   },
    77   content = function()
    78     local records
    80     if issue then
    81       local delegate_name = ""
    82       local scope = "no delegation set"
    83       local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
    84       if area_delegation then
    85         delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
    86         scope = _"area"
    87       else
    88         local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
    89         if unit_delegation then
    90           delegate_name = unit_delegation.trustee.name
    91           scope = config.single_unit_id and _"global" or _"unit"
    92         end
    93       end
    94       local text_apply
    95       local text_abandon
    96       if config.single_unit_id then
    97         text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    98         text_abandon = _"Abandon unit and area delegations for this issue"
    99       else
   100         text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   101         text_abandon = _"Abandon unit and area delegations for this issue"
   102       end
   103       records = {
   104         { id = -1, name = text_apply },
   105         { id = 0,  name = text_abandom }
   106       }
   107     elseif area then
   108       local delegate_name = ""
   109       local scope = "no delegation set"
   110       local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
   111       if unit_delegation then
   112         delegate_name = unit_delegation.trustee.name
   113         scope = config.single_unit_id and _"global" or _"unit"
   114       end
   115       local text_apply
   116       local text_abandon
   117       if config.single_unit_id then
   118         text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   119         text_abandon = _"Abandon global delegation for this area"
   120       else
   121         text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   122         text_abandon = _"Abandon unit delegation for this area"
   123       end
   124       records = {
   125         {
   126           id = -1,
   127           name = text_apply
   128         },
   129         {
   130           id = 0,
   131           name = text_abandon
   132         }
   133       }
   135     else
   136       records = {
   137         {
   138           id = -1,
   139           name = _"No delegation"
   140         }
   141       }
   143     end
   144     -- add saved members
   145     records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   146     for i, record in ipairs(contact_members) do
   147       records[#records+1] = record
   148     end
   149     -- add initiative authors
   150     if initiative then
   151       records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   152       for i,record in ipairs(initiative.initiators) do
   153         records[#records+1] = record.member
   154       end
   155     end
   157     disabled_records = {}
   158     disabled_records["_"] = true
   160     ui.field.select{
   161       label = _"Trustee",
   162       name = "trustee_id",
   163       foreign_records = records,
   164       foreign_id = "id",
   165       foreign_name = "name",
   166       disabled_records = disabled_records
   167     }
   169     ui.submit{ text = _"Save" }
   170   end
   171 }
