liquid_feedback_frontend
view app/main/delegation/show.lua @ 527:4cee33ad5e16
Completed support for config.public_access = "full"
| author | bsw | 
|---|---|
| date | Fri May 18 19:44:41 2012 +0200 (2012-05-18) | 
| parents | 63d6549cc00b | 
| children | 5ca9de94cb13 | 
 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 initiative and "initiative" or issue and "issue" or "unit",
    79       view = "show",
    80       id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
    81     }
    82   },
    83   content = function()
    84     local records
    86     if issue then
    87       local delegate_name = ""
    88       local scope = "no delegation set"
    89       local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
    90       if area_delegation then
    91         delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
    92         scope = _"area"
    93       else
    94         local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
    95         if unit_delegation then
    96           delegate_name = unit_delegation.trustee.name
    97           scope = config.single_unit_id and _"global" or _"unit"
    98         end
    99       end
   100       local text_apply
   101       local text_abandon
   102       if config.single_unit_id then
   103         text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   104         text_abandon = _"Abandon unit and area delegations for this issue"
   105       else
   106         text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   107         text_abandon = _"Abandon unit and area delegations for this issue"
   108       end
   109       records = {
   110         { id = -1, name = text_apply },
   111         { id = 0,  name = text_abandon }
   112       }
   113     elseif area then
   114       local delegate_name = ""
   115       local scope = "no delegation set"
   116       local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
   117       if unit_delegation then
   118         delegate_name = unit_delegation.trustee.name
   119         scope = config.single_unit_id and _"global" or _"unit"
   120       end
   121       local text_apply
   122       local text_abandon
   123       if config.single_unit_id then
   124         text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   125         text_abandon = _"Abandon global delegation for this area"
   126       else
   127         text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   128         text_abandon = _"Abandon unit delegation for this area"
   129       end
   130       records = {
   131         {
   132           id = -1,
   133           name = text_apply
   134         },
   135         {
   136           id = 0,
   137           name = text_abandon
   138         }
   139       }
   141     else
   142       records = {
   143         {
   144           id = -1,
   145           name = _"No delegation"
   146         }
   147       }
   149     end
   150     -- add saved members
   151     records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   152     for i, record in ipairs(contact_members) do
   153       records[#records+1] = record
   154     end
   155     -- add initiative authors
   156     if initiative then
   157       records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   158       for i,record in ipairs(initiative.initiators) do
   159         records[#records+1] = record.member
   160       end
   161     end
   163     disabled_records = {}
   164     disabled_records["_"] = true
   165     disabled_records[app.session.member_id] = 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 }
   182 -- ------------------------
   187 local delegation
   188 local unit_id
   189 local area_id
   190 local issue_id
   191 local initiative_id
   193 local scope = "unit"
   195 unit_id = param.get("unit_id", atom.integer)
   197 local inline = param.get("inline", atom.boolean)
   199 if param.get("initiative_id", atom.integer) then
   200   initiative_id = param.get("initiative_id", atom.integer)
   201   issue_id = Initiative:by_id(initiative_id).issue_id
   202   scope = "issue"
   203 end
   205 if param.get("issue_id", atom.integer) then
   206   issue_id = param.get("issue_id", atom.integer)
   207   scope = "issue"
   208 end
   210 if param.get("area_id", atom.integer) then
   211   area_id = param.get("area_id", atom.integer)
   212   scope = "area"
   213 end
   217 local delegation
   218 local issue
   220 if issue_id then
   221   issue = Issue:by_id(issue_id)
   222   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   223   if not delegation then
   224     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   225   end
   226   if not delegation then
   227     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   228   end
   229 elseif area_id then
   230   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   231   if not delegation then
   232     local area = Area:by_id(area_id)
   233     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   234   end
   235 end
   237 if not delegation then
   238   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   239 end
   241 local slot_name = "actions"
   243 if inline then
   244   slot_name = "default"
   245 end
   247 if delegation then
   249   if not delegation.trustee_id then
   250     ui.image{
   251       static = "icons/16/table_go_crossed.png"
   252     }
   253     if delegation.issue_id then
   254       slot.put(_"Delegation turned off for issue")
   255     elseif delegation.area_id then
   256       slot.put(_"Delegation turned off for area")
   257     end
   258   end
   260   local delegation_chain = Member:new_selector()
   261     :add_field("delegation_chain.*")
   262     :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(unit_id or "NULL") .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
   263     :add_order_by("index")
   264     :exec()
   266   for i, record in ipairs(delegation_chain) do
   267     local style
   268     local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   269     if record.scope_in then
   270       if not overridden then
   271         ui.image{
   272           attr = { class = "delegation_arrow" },
   273           static = "delegation_arrow_24_vertical.png"
   274         }
   275       else
   276         ui.image{
   277           attr = { class = "delegation_arrow delegation_arrow_overridden" },
   278           static = "delegation_arrow_24_vertical.png"
   279         }
   280       end
   281       ui.tag{
   282         attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   283         content = function()
   284           if record.scope_in == "unit" then
   285             slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   286           elseif record.scope_in == "area" then
   287             slot.put(_"Area delegation")
   288           elseif record.scope_in == "issue" then
   289             slot.put(_"Issue delegation")
   290           end
   291         end
   292       }
   293     end
   294     ui.container{
   295       attr = { class = overridden and "delegation_overridden" or "" },
   296       content = function()
   297         execute.view{
   298           module = "member",
   299           view = "_show_thumb",
   300           params = { member = record }
   301         }
   302       end
   303     }
   304     if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   305       ui.container{
   306         attr = { class = "delegation_participation" },
   307         content = function()
   308           slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   309         end
   310       }
   311     end
   312     slot.put("<br style='clear: left'/>")
   313   end
   314 end
