bsw@395: local member = param.get("member", "table") bsw@472: local for_member = param.get("for_member", atom.boolean) bsw@472: bsw@394: local units = member.units_with_voting_right 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@375: ui.container{ attr = { class = "unit_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@375: else 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