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