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