liquid_feedback_frontend
view app/main/delegation/show.lua @ 552:3344717939f0
Improved interest and support filters for issues
| author | bsw | 
|---|---|
| date | Fri Jun 15 20:46:25 2012 +0200 (2012-06-15) | 
| parents | c1dc3b14a4f3 | 
| children | 774d8804ce65 | 
 line source
     1 local voting_right_unit_id
     2 local current_trustee_id
     3 local current_trustee_name
     5 local unit = Unit:by_id(param.get("unit_id", atom.integer))
     6 if unit then
     7   unit:load_delegation_info_once_for_member_id(app.session.member_id)
     8   voting_right_unit_id = unit.id
     9   if unit.delegation_info.own_delegation_scope == 'unit' then
    10     current_trustee_id = unit.delegation_info.first_trustee_id
    11     current_trustee_name = unit.delegation_info.first_trustee_name
    12   end
    13   slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
    14   util.help("delegation.new.unit")
    15 end
    17 local area = Area:by_id(param.get("area_id", atom.integer))
    18 if area then
    19   area:load_delegation_info_once_for_member_id(app.session.member_id)
    20   voting_right_unit_id = area.unit_id
    21   slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
    22   util.help("delegation.new.area")
    23 end
    25 local issue = Issue:by_id(param.get("issue_id", atom.integer))
    26 if issue then
    27   issue:load("member_info", { member_id = app.session.member_id })
    28   voting_right_unit_id = issue.area.unit_id
    29   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)))
    30   util.help("delegation.new.issue")
    31 end
    33 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
    35 local contact_members = Member:build_selector{
    36   is_contact_of_member_id = app.session.member_id,
    37   voting_right_for_unit_id = voting_right_unit_id,
    38   active = true,
    39   order = "name"
    40 }:exec()
    42 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
    44 ui.script{ static = "js/update_delegation_info.js" }
    46 slot.select("actions", function()
    47   if issue then
    48     ui.link{
    49       module = "issue",
    50       view = "show",
    51       id = issue.id,
    52       content = function()
    53           ui.image{ static = "icons/16/cancel.png" }
    54           slot.put(_"Cancel")
    55       end,
    56     }
    57   elseif area then
    58     ui.link{
    59       module = "area",
    60       view = "show",
    61       id = area.id,
    62       content = function()
    63           ui.image{ static = "icons/16/cancel.png" }
    64           slot.put(_"Cancel")
    65       end,
    66     }
    67   else
    68     ui.link{
    69       module = "index",
    70       view = "index",
    71       content = function()
    72           ui.image{ static = "icons/16/cancel.png" }
    73           slot.put(_"Cancel")
    74       end,
    75     }
    76   end
    77 end)
    80 ui.form{
    81   attr = { class = "vertical", id = "delegationForm" },
    82   module = "delegation",
    83   action = "update",
    84   params = {
    85     unit_id = unit and unit.id or nil,
    86     area_id = area and area.id or nil,
    87     issue_id = issue and issue.id or nil,
    88   },
    89   routing = {
    90     default = {
    91       mode = "redirect",
    92       module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
    93       view = "show",
    94       id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
    95     }
    96   },
    97   content = function()
    98     local records
   100     if issue then
   101       local delegate_name = ""
   102       local scope = "no delegation set"
   103       local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
   104       if area_delegation then
   105         delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
   106         scope = _"area"
   107       else
   108         local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
   109         if unit_delegation then
   110           delegate_name = unit_delegation.trustee.name
   111           scope = config.single_unit_id and _"global" or _"unit"
   112         end
   113       end
   114       local text_apply
   115       local text_abandon
   116       if config.single_unit_id then
   117         text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   118         text_abandon = _"Abandon unit and area delegations for this issue"
   119       else
   120         text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   121         text_abandon = _"Abandon unit and area delegations for this issue"
   122       end
   123       records = {
   124         { id = -1, name = text_apply },
   125         { id = 0,  name = text_abandon }
   126       }
   127     elseif area then
   128       local delegate_name = ""
   129       local scope = "no delegation set"
   130       local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
   131       if unit_delegation then
   132         delegate_name = unit_delegation.trustee.name
   133         scope = config.single_unit_id and _"global" or _"unit"
   134       end
   135       local text_apply
   136       local text_abandon
   137       if config.single_unit_id then
   138         text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   139         text_abandon = _"Abandon global delegation for this area"
   140       else
   141         text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   142         text_abandon = _"Abandon unit delegation for this area"
   143       end
   144       records = {
   145         {
   146           id = -1,
   147           name = text_apply
   148         },
   149         {
   150           id = 0,
   151           name = text_abandon
   152         }
   153       }
   155     else
   156       records = {
   157         {
   158           id = -1,
   159           name = _"No delegation"
   160         }
   161       }
   163     end
   164     -- add saved members
   165     if current_trustee_id then
   166       records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"}
   167       records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
   168     end
   169     -- add saved members
   170     records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   171     for i, record in ipairs(contact_members) do
   172       records[#records+1] = record
   173     end
   174     -- add initiative authors
   175     if initiative then
   176       records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   177       for i,record in ipairs(initiative.initiators) do
   178         records[#records+1] = record.member
   179       end
   180     end
   182     disabled_records = {}
   183     disabled_records["_"] = true
   184     disabled_records[app.session.member_id] = true
   186     ui.field.select{
   187       attr = { onchange = "updateDelegationInfo();" },
   188       label = _"Trustee",
   189       name = "trustee_id",
   190       foreign_records = records,
   191       foreign_id = "id",
   192       foreign_name = "name",
   193       disabled_records = disabled_records,
   194       value = preview_trustee_id or current_trustee_id
   195     }
   197     ui.field.hidden{ name = "preview" }
   199     ui.submit{ text = _"Save" }
   201   end
   202 }
   206 -- ------------------------
   211 local delegation
   212 local unit_id
   213 local area_id
   214 local issue_id
   215 local initiative_id
   217 local scope = "unit"
   219 unit_id = param.get("unit_id", atom.integer)
   221 local inline = param.get("inline", atom.boolean)
   223 if param.get("initiative_id", atom.integer) then
   224   initiative_id = param.get("initiative_id", atom.integer)
   225   issue_id = Initiative:by_id(initiative_id).issue_id
   226   scope = "issue"
   227 end
   229 if param.get("issue_id", atom.integer) then
   230   issue_id = param.get("issue_id", atom.integer)
   231   scope = "issue"
   232 end
   234 if param.get("area_id", atom.integer) then
   235   area_id = param.get("area_id", atom.integer)
   236   scope = "area"
   237 end
   241 local delegation
   242 local issue
   244 if issue_id then
   245   issue = Issue:by_id(issue_id)
   246   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   247   if not delegation then
   248     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   249   end
   250   if not delegation then
   251     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   252   end
   253 elseif area_id then
   254   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   255   if not delegation then
   256     local area = Area:by_id(area_id)
   257     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   258   end
   259 end
   261 if not delegation then
   262   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   263 end
   265 local slot_name = "actions"
   267 if inline then
   268   slot_name = "default"
   269 end
   271   if delegation and not delegation.trustee_id then
   272     ui.image{
   273       static = "icons/16/table_go_crossed.png"
   274     }
   275     if delegation.issue_id then
   276       slot.put(_"Delegation turned off for issue")
   277     elseif delegation.area_id then
   278       slot.put(_"Delegation turned off for area")
   279     end
   280   end
   282   local delegation_chain = Member:new_selector()
   283     :add_field("delegation_chain.*")
   284     :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
   285     :add_order_by("index")
   286     :exec()
   288   for i, record in ipairs(delegation_chain) do
   289     local style
   290     local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   291     if record.scope_in then
   292       if not overridden then
   293         ui.image{
   294           attr = { class = "delegation_arrow" },
   295           static = "delegation_arrow_24_vertical.png"
   296         }
   297       else
   298         ui.image{
   299           attr = { class = "delegation_arrow delegation_arrow_overridden" },
   300           static = "delegation_arrow_24_vertical.png"
   301         }
   302       end
   303       ui.tag{
   304         attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   305         content = function()
   306           if record.scope_in == "unit" then
   307             slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   308           elseif record.scope_in == "area" then
   309             slot.put(_"Area delegation")
   310           elseif record.scope_in == "issue" then
   311             slot.put(_"Issue delegation")
   312           end
   313         end
   314       }
   315     end
   316     ui.container{
   317       attr = { class = overridden and "delegation_overridden" or "" },
   318       content = function()
   319         execute.view{
   320           module = "member",
   321           view = "_show_thumb",
   322           params = { member = record }
   323         }
   324       end
   325     }
   326     if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   327       ui.container{
   328         attr = { class = "delegation_participation" },
   329         content = function()
   330           slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   331         end
   332       }
   333     end
   334     slot.put("<br style='clear: left'/>")
   335   end
