| rev | 
   line source | 
| 
bsw@395
 | 
     1 local member = param.get("member", "table")
 | 
| 
bsw@394
 | 
     2 local units = member.units_with_voting_right
 | 
| 
bsw@395
 | 
     3 
 | 
| 
bsw@273
 | 
     4 for i, unit in ipairs(units) do
 | 
| 
bsw@375
 | 
     5   local trustee_member = Member:new_selector()
 | 
| 
bsw@417
 | 
     6     :join("delegation", nil, { "delegation.scope = 'unit' AND delegation.unit_id = ? AND delegation.trustee_id = member.id AND delegation.truster_id = ?", unit.id, member.id })
 | 
| 
bsw@375
 | 
     7     :optional_object_mode()
 | 
| 
bsw@375
 | 
     8     :exec()
 | 
| 
bsw@375
 | 
     9   
 | 
| 
bsw@273
 | 
    10   local areas_selector = Area:new_selector()
 | 
| 
bsw@273
 | 
    11     :join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
 | 
| 
bsw@273
 | 
    12     :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@424
 | 
    13     :add_where{ "area.active" }
 | 
| 
bsw@273
 | 
    14     :add_order_by("area.member_weight DESC")
 | 
| 
bsw@273
 | 
    15   
 | 
| 
bsw@280
 | 
    16   local area_count = areas_selector:count()
 | 
| 
bsw@375
 | 
    17   
 | 
| 
bsw@375
 | 
    18   ui.container{ attr = { class = "member_area_list" }, content = function()
 | 
| 
bsw@375
 | 
    19     ui.container{ attr = { class = "unit_head" }, content = function()
 | 
| 
bsw@375
 | 
    20       ui.link{
 | 
| 
bsw@375
 | 
    21         text = unit.name,
 | 
| 
bsw@375
 | 
    22         module = "unit", view = "show", id = unit.id
 | 
| 
bsw@375
 | 
    23       }
 | 
| 
bsw@280
 | 
    24 
 | 
| 
bsw@375
 | 
    25       if trustee_member then
 | 
| 
bsw@375
 | 
    26         local text = _("Unit delegated to '#{name}'", { name = trustee_member.name })
 | 
| 
bsw@375
 | 
    27         ui.image{
 | 
| 
bsw@375
 | 
    28           attr = { class = "delegation_arrow", alt = text, title = text },
 | 
| 
bsw@375
 | 
    29           static = "delegation_arrow_24_horizontal.png"
 | 
| 
bsw@375
 | 
    30         }
 | 
| 
bsw@375
 | 
    31         execute.view{
 | 
| 
bsw@375
 | 
    32           module = "member_image",
 | 
| 
bsw@375
 | 
    33           view = "_show",
 | 
| 
bsw@375
 | 
    34           params = {
 | 
| 
bsw@375
 | 
    35             member = trustee_member,
 | 
| 
bsw@375
 | 
    36             image_type = "avatar",
 | 
| 
bsw@375
 | 
    37             show_dummy = true,
 | 
| 
bsw@375
 | 
    38             class = "micro_avatar",
 | 
| 
bsw@375
 | 
    39             popup_text = text
 | 
| 
bsw@375
 | 
    40           }
 | 
| 
bsw@375
 | 
    41         }
 | 
| 
bsw@375
 | 
    42       end
 | 
| 
bsw@375
 | 
    43     end }
 | 
| 
bsw@375
 | 
    44 
 | 
| 
bsw@375
 | 
    45     if area_count > 0 then
 | 
| 
bsw@375
 | 
    46       execute.view{
 | 
| 
bsw@375
 | 
    47         module = "area", view = "_list",
 | 
| 
bsw@375
 | 
    48         params = { areas_selector = areas_selector, hide_membership = true }
 | 
| 
bsw@375
 | 
    49       }
 | 
| 
bsw@375
 | 
    50     else
 | 
| 
bsw@383
 | 
    51       ui.container{ attr = { class = "voting_priv_info" }, content = _"You have voting privileges for this unit, but you are not member of any of its areas." }
 | 
| 
bsw@375
 | 
    52     end
 | 
| 
bsw@424
 | 
    53     local max_area_count = Area:new_selector()
 | 
| 
bsw@424
 | 
    54       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@424
 | 
    55       :add_where{ "area.active" }
 | 
| 
bsw@424
 | 
    56       :count()
 | 
| 
bsw@424
 | 
    57     local more_area_count = max_area_count - area_count
 | 
| 
bsw@424
 | 
    58     local delegated_count = Area:new_selector()
 | 
| 
bsw@424
 | 
    59       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@424
 | 
    60       :add_where{ "area.active" }
 | 
| 
bsw@424
 | 
    61       :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
 | 
| 
bsw@424
 | 
    62       :add_where{ "membership.member_id ISNULL" }
 | 
| 
bsw@424
 | 
    63       :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
 | 
| 
bsw@424
 | 
    64       :count()
 | 
| 
bsw@424
 | 
    65     if more_area_count > 0 then
 | 
| 
bsw@424
 | 
    66       slot.put("<br />")
 | 
| 
bsw@447
 | 
    67       ui.container{ attr = { class = "more_areas" }, content = function()
 | 
| 
bsw@424
 | 
    68         ui.link{ content = _("#{count} more areas in this unit, #{delegated_count} of them delegated", { count = more_area_count, delegated_count = delegated_count }), module = "unit", view = "show", id = unit.id }
 | 
| 
bsw@424
 | 
    69       end }
 | 
| 
bsw@424
 | 
    70     end
 | 
| 
bsw@375
 | 
    71   end }
 | 
| 
bsw@414
 | 
    72 
 | 
| 
bsw@273
 | 
    73 end
 |