| 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@571
 | 
    39   if member:has_voting_right_for_unit_id(unit.id) then
 | 
| 
bsw@571
 | 
    40     local trustee_member = Member:new_selector()
 | 
| 
bsw@571
 | 
    41       :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@571
 | 
    42       :optional_object_mode()
 | 
| 
bsw@571
 | 
    43       :exec()
 | 
| 
bsw@571
 | 
    44     
 | 
| 
bsw@571
 | 
    45     local areas_selector = Area:new_selector()
 | 
| 
bsw@571
 | 
    46       :join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
 | 
| 
bsw@571
 | 
    47       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@571
 | 
    48       :add_where{ "area.active" }
 | 
| 
bsw@571
 | 
    49       :add_order_by("area.member_weight DESC")
 | 
| 
bsw@571
 | 
    50     
 | 
| 
bsw@571
 | 
    51     local area_count = areas_selector:count()
 | 
| 
bsw@571
 | 
    52     
 | 
| 
bsw@571
 | 
    53     ui.container{ attr = { class = "member_area_list" }, content = function()
 | 
| 
bsw@571
 | 
    54       ui.container{ attr = { class = "unit_head" }, content = function()
 | 
| 
bsw@571
 | 
    55         ui.link{
 | 
| 
bsw@571
 | 
    56           text = unit.name,
 | 
| 
bsw@571
 | 
    57           module = "unit", view = "show", id = unit.id
 | 
| 
bsw@571
 | 
    58         }
 | 
| 
bsw@558
 | 
    59 
 | 
| 
bsw@571
 | 
    60         if trustee_member then
 | 
| 
bsw@571
 | 
    61           local text = _("Unit delegated to '#{name}'", { name = trustee_member.name })
 | 
| 
bsw@571
 | 
    62           ui.image{
 | 
| 
bsw@571
 | 
    63             attr = { class = "delegation_arrow", alt = text, title = text },
 | 
| 
bsw@571
 | 
    64             static = "delegation_arrow_24_horizontal.png"
 | 
| 
bsw@571
 | 
    65           }
 | 
| 
bsw@571
 | 
    66           execute.view{
 | 
| 
bsw@571
 | 
    67             module = "member_image",
 | 
| 
bsw@571
 | 
    68             view = "_show",
 | 
| 
bsw@571
 | 
    69             params = {
 | 
| 
bsw@571
 | 
    70               member = trustee_member,
 | 
| 
bsw@571
 | 
    71               image_type = "avatar",
 | 
| 
bsw@571
 | 
    72               show_dummy = true,
 | 
| 
bsw@571
 | 
    73               class = "micro_avatar",
 | 
| 
bsw@571
 | 
    74               popup_text = text
 | 
| 
bsw@571
 | 
    75             }
 | 
| 
bsw@571
 | 
    76           }
 | 
| 
bsw@571
 | 
    77         end
 | 
| 
bsw@571
 | 
    78       end }
 | 
| 
bsw@571
 | 
    79 
 | 
| 
bsw@571
 | 
    80       if area_count > 0 then
 | 
| 
bsw@558
 | 
    81         execute.view{
 | 
| 
bsw@571
 | 
    82           module = "area", view = "_list",
 | 
| 
bsw@571
 | 
    83           params = { areas_selector = areas_selector, hide_membership = true }
 | 
| 
bsw@558
 | 
    84         }
 | 
| 
bsw@571
 | 
    85       elseif member:has_voting_right_for_unit_id(unit.id) then
 | 
| 
bsw@571
 | 
    86         if for_member then
 | 
| 
bsw@571
 | 
    87           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@571
 | 
    88         else
 | 
| 
bsw@571
 | 
    89           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@571
 | 
    90         end
 | 
| 
bsw@571
 | 
    91       end
 | 
| 
bsw@571
 | 
    92       local max_area_count = Area:new_selector()
 | 
| 
bsw@571
 | 
    93         :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@571
 | 
    94         :add_where{ "area.active" }
 | 
| 
bsw@571
 | 
    95         :count()
 | 
| 
bsw@571
 | 
    96       local more_area_count = max_area_count - area_count
 | 
| 
bsw@571
 | 
    97       local delegated_count = Area:new_selector()
 | 
| 
bsw@571
 | 
    98         :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@571
 | 
    99         :add_where{ "area.active" }
 | 
| 
bsw@571
 | 
   100         :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
 | 
| 
bsw@571
 | 
   101         :add_where{ "membership.member_id ISNULL" }
 | 
| 
bsw@571
 | 
   102         :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
 | 
| 
bsw@571
 | 
   103         :count()
 | 
| 
bsw@571
 | 
   104       if more_area_count > 0 then
 | 
| 
bsw@571
 | 
   105         slot.put("<br />")
 | 
| 
bsw@571
 | 
   106         ui.container{ attr = { class = "more_areas" }, content = function()
 | 
| 
bsw@571
 | 
   107           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@571
 | 
   108         end }
 | 
| 
bsw@558
 | 
   109       end
 | 
| 
bsw@558
 | 
   110     end }
 | 
| 
bsw@571
 | 
   111   end
 | 
| 
bsw@558
 | 
   112 end
 | 
| 
bsw@558
 | 
   113 
 | 
| 
bsw@558
 | 
   114 
 |