bsw@395: local member = param.get("member", "table") bsw@472: local for_member = param.get("for_member", atom.boolean) bsw@525: local filter_unit = param.get_all_cgi()["filter_unit"] or "personal" bsw@472: bsw@525: ui.container{ attr = { class = "ui_filter_head" }, content = function() bsw@525: bsw@525: ui.link{ bsw@525: attr = { class = filter_unit == "personal" and "ui_tabs_link active" or nil }, bsw@525: text = _"With voting right", bsw@525: module = "index", view = "index", params = { filter_unit = "personal" } bsw@525: } bsw@525: bsw@525: slot.put(" ") bsw@525: bsw@525: ui.link{ bsw@525: attr = { class = filter_unit == "global" and "active" or nil }, bsw@525: text = _"All units", bsw@525: module = "index", view = "index", params = { filter_unit = "global" } bsw@525: } bsw@525: end } bsw@525: bsw@525: slot.put("
") bsw@525: bsw@525: bsw@525: if filter_unit == "global" then bsw@525: execute.view{ module = "unit", view = "_list" } bsw@525: return bsw@525: end bsw@525: bsw@525: local units = Unit:new_selector():exec() bsw@395: bsw@273: for i, unit in ipairs(units) do bsw@375: local trustee_member = Member:new_selector() bsw@417: :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: :optional_object_mode() bsw@375: :exec() bsw@375: bsw@273: local areas_selector = Area:new_selector() bsw@273: :join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id }) bsw@273: :add_where{ "area.unit_id = ?", unit.id } bsw@424: :add_where{ "area.active" } bsw@273: :add_order_by("area.member_weight DESC") bsw@273: bsw@280: local area_count = areas_selector:count() bsw@375: bsw@375: ui.container{ attr = { class = "member_area_list" }, content = function() bsw@525: ui.container{ attr = { class = "xunit_head" }, content = function() bsw@375: ui.link{ bsw@375: text = unit.name, bsw@375: module = "unit", view = "show", id = unit.id bsw@375: } bsw@280: bsw@375: if trustee_member then bsw@375: local text = _("Unit delegated to '#{name}'", { name = trustee_member.name }) bsw@375: ui.image{ bsw@375: attr = { class = "delegation_arrow", alt = text, title = text }, bsw@375: static = "delegation_arrow_24_horizontal.png" bsw@375: } bsw@375: execute.view{ bsw@375: module = "member_image", bsw@375: view = "_show", bsw@375: params = { bsw@375: member = trustee_member, bsw@375: image_type = "avatar", bsw@375: show_dummy = true, bsw@375: class = "micro_avatar", bsw@375: popup_text = text bsw@375: } bsw@375: } bsw@375: end bsw@375: end } bsw@375: bsw@375: if area_count > 0 then bsw@375: execute.view{ bsw@375: module = "area", view = "_list", bsw@375: params = { areas_selector = areas_selector, hide_membership = true } bsw@375: } bsw@525: elseif member:has_voting_right_for_unit_id(unit.id) then bsw@472: if for_member then bsw@472: 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: else bsw@472: 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: end bsw@375: end bsw@424: local max_area_count = Area:new_selector() bsw@424: :add_where{ "area.unit_id = ?", unit.id } bsw@424: :add_where{ "area.active" } bsw@424: :count() bsw@424: local more_area_count = max_area_count - area_count bsw@424: local delegated_count = Area:new_selector() bsw@424: :add_where{ "area.unit_id = ?", unit.id } bsw@424: :add_where{ "area.active" } bsw@424: :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } ) bsw@424: :add_where{ "membership.member_id ISNULL" } bsw@424: :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } ) bsw@424: :count() bsw@424: if more_area_count > 0 then bsw@424: slot.put("
") bsw@447: ui.container{ attr = { class = "more_areas" }, content = function() bsw@472: 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: end } bsw@424: end bsw@375: end } bsw@414: bsw@273: end bsw@525: bsw@525: