| rev | 
   line source | 
| 
bsw@558
 | 
     1 local member = param.get("member", "table")
 | 
| 
bsw@558
 | 
     2 local for_member = param.get("for_member", atom.boolean)
 | 
| 
bsw@558
 | 
     3 local filter_unit = param.get_all_cgi()["filter_unit"] or "personal"
 | 
| 
bsw@558
 | 
     4 
 | 
| 
bsw@558
 | 
     5 
 | 
| 
bsw@558
 | 
     6 execute.view{
 | 
| 
bsw@558
 | 
     7   module = "index", view = "_notifications"
 | 
| 
bsw@558
 | 
     8 }
 | 
| 
bsw@558
 | 
     9 
 | 
| 
bsw@558
 | 
    10     
 | 
| 
bsw@558
 | 
    11 ui.container{ attr = { class = "ui_filter_head" }, content = function()
 | 
| 
bsw@558
 | 
    12 
 | 
| 
bsw@558
 | 
    13   ui.link{
 | 
| 
bsw@558
 | 
    14     attr = { class = filter_unit == "personal" and "ui_tabs_link active" or nil },
 | 
| 
bsw@558
 | 
    15     text = _"My units and areas",
 | 
| 
bsw@558
 | 
    16     module = "index", view = "index", params = { filter_unit = "personal" }
 | 
| 
bsw@558
 | 
    17   }
 | 
| 
bsw@558
 | 
    18   
 | 
| 
bsw@558
 | 
    19   slot.put(" ")
 | 
| 
bsw@558
 | 
    20 
 | 
| 
bsw@558
 | 
    21   ui.link{
 | 
| 
bsw@558
 | 
    22     attr = { class = filter_unit == "global" and "active" or nil },
 | 
| 
bsw@558
 | 
    23     text = _"All units",
 | 
| 
bsw@558
 | 
    24     module = "index", view = "index", params = { filter_unit = "global" }
 | 
| 
bsw@558
 | 
    25   }
 | 
| 
bsw@558
 | 
    26 end }
 | 
| 
bsw@558
 | 
    27 
 | 
| 
bsw@558
 | 
    28 slot.put("<br />")
 | 
| 
bsw@558
 | 
    29 
 | 
| 
bsw@558
 | 
    30 
 | 
| 
bsw@558
 | 
    31 if filter_unit == "global" then
 | 
| 
bsw@558
 | 
    32   execute.view{ module = "unit", view = "_list" }
 | 
| 
bsw@558
 | 
    33   return
 | 
| 
bsw@558
 | 
    34 end
 | 
| 
bsw@558
 | 
    35 
 | 
| 
bsw@558
 | 
    36 local units = Unit:new_selector():exec()
 | 
| 
bsw@558
 | 
    37 
 | 
| 
bsw@558
 | 
    38 for i, unit in ipairs(units) do
 | 
| 
bsw@558
 | 
    39   local trustee_member = Member:new_selector()
 | 
| 
bsw@558
 | 
    40     :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@558
 | 
    41     :optional_object_mode()
 | 
| 
bsw@558
 | 
    42     :exec()
 | 
| 
bsw@558
 | 
    43   
 | 
| 
bsw@558
 | 
    44   local areas_selector = Area:new_selector()
 | 
| 
bsw@558
 | 
    45     :join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
 | 
| 
bsw@558
 | 
    46     :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@558
 | 
    47     :add_where{ "area.active" }
 | 
| 
bsw@558
 | 
    48     :add_order_by("area.member_weight DESC")
 | 
| 
bsw@558
 | 
    49   
 | 
| 
bsw@558
 | 
    50   local area_count = areas_selector:count()
 | 
| 
bsw@558
 | 
    51   
 | 
| 
bsw@558
 | 
    52   ui.container{ attr = { class = "member_area_list" }, content = function()
 | 
| 
bsw@558
 | 
    53     ui.container{ attr = { class = "xunit_head" }, content = function()
 | 
| 
bsw@558
 | 
    54       ui.link{
 | 
| 
bsw@558
 | 
    55         text = unit.name,
 | 
| 
bsw@558
 | 
    56         module = "unit", view = "show", id = unit.id
 | 
| 
bsw@558
 | 
    57       }
 | 
| 
bsw@558
 | 
    58 
 | 
| 
bsw@558
 | 
    59       if trustee_member then
 | 
| 
bsw@558
 | 
    60         local text = _("Unit delegated to '#{name}'", { name = trustee_member.name })
 | 
| 
bsw@558
 | 
    61         ui.image{
 | 
| 
bsw@558
 | 
    62           attr = { class = "delegation_arrow", alt = text, title = text },
 | 
| 
bsw@558
 | 
    63           static = "delegation_arrow_24_horizontal.png"
 | 
| 
bsw@558
 | 
    64         }
 | 
| 
bsw@558
 | 
    65         execute.view{
 | 
| 
bsw@558
 | 
    66           module = "member_image",
 | 
| 
bsw@558
 | 
    67           view = "_show",
 | 
| 
bsw@558
 | 
    68           params = {
 | 
| 
bsw@558
 | 
    69             member = trustee_member,
 | 
| 
bsw@558
 | 
    70             image_type = "avatar",
 | 
| 
bsw@558
 | 
    71             show_dummy = true,
 | 
| 
bsw@558
 | 
    72             class = "micro_avatar",
 | 
| 
bsw@558
 | 
    73             popup_text = text
 | 
| 
bsw@558
 | 
    74           }
 | 
| 
bsw@558
 | 
    75         }
 | 
| 
bsw@558
 | 
    76       end
 | 
| 
bsw@558
 | 
    77     end }
 | 
| 
bsw@558
 | 
    78 
 | 
| 
bsw@558
 | 
    79     if area_count > 0 then
 | 
| 
bsw@558
 | 
    80       execute.view{
 | 
| 
bsw@558
 | 
    81         module = "area", view = "_list",
 | 
| 
bsw@558
 | 
    82         params = { areas_selector = areas_selector, hide_membership = true }
 | 
| 
bsw@558
 | 
    83       }
 | 
| 
bsw@558
 | 
    84     elseif member:has_voting_right_for_unit_id(unit.id) then
 | 
| 
bsw@558
 | 
    85       if for_member then
 | 
| 
bsw@558
 | 
    86         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@558
 | 
    87       else
 | 
| 
bsw@558
 | 
    88         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@558
 | 
    89       end
 | 
| 
bsw@558
 | 
    90     end
 | 
| 
bsw@558
 | 
    91     local max_area_count = Area:new_selector()
 | 
| 
bsw@558
 | 
    92       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@558
 | 
    93       :add_where{ "area.active" }
 | 
| 
bsw@558
 | 
    94       :count()
 | 
| 
bsw@558
 | 
    95     local more_area_count = max_area_count - area_count
 | 
| 
bsw@558
 | 
    96     local delegated_count = Area:new_selector()
 | 
| 
bsw@558
 | 
    97       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@558
 | 
    98       :add_where{ "area.active" }
 | 
| 
bsw@558
 | 
    99       :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
 | 
| 
bsw@558
 | 
   100       :add_where{ "membership.member_id ISNULL" }
 | 
| 
bsw@558
 | 
   101       :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
 | 
| 
bsw@558
 | 
   102       :count()
 | 
| 
bsw@558
 | 
   103     if more_area_count > 0 then
 | 
| 
bsw@558
 | 
   104       slot.put("<br />")
 | 
| 
bsw@558
 | 
   105       ui.container{ attr = { class = "more_areas" }, content = function()
 | 
| 
bsw@558
 | 
   106         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@558
 | 
   107       end }
 | 
| 
bsw@558
 | 
   108     end
 | 
| 
bsw@558
 | 
   109   end }
 | 
| 
bsw@558
 | 
   110 
 | 
| 
bsw@558
 | 
   111 end
 | 
| 
bsw@558
 | 
   112 
 | 
| 
bsw@558
 | 
   113 
 |