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