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