bsw/jbe@1309: if true then return end bsw/jbe@1309: bsw@1045: local member = param.get ( "member", "table" ) bsw@1045: local units bsw@1045: if member then bsw@1218: units = member:get_reference_selector("units"):add_order_by("name"):exec() bsw@1045: units:load_delegation_info_once_for_member_id(member.id) bsw@1045: else bsw@1045: units = Unit:new_selector():add_where("active"):add_order_by("name"):exec() bsw@1045: ui.sidebar( "tab-whatcanido", function() bsw@1045: ui.sidebarHead( function() bsw@1045: ui.heading { level = 2, content = _"Organizational units" } bsw@1045: end ) bsw@1045: ui.sidebarSection( function() bsw@1045: execute.view { module = "unit", view = "_list" } bsw@1045: end ) bsw@1045: end ) bsw@1045: return bsw@1045: end bsw@1045: bsw@1045: bsw@1045: for i, unit in ipairs(units) do bsw@1045: bsw@1045: ui.sidebar ( "tab-whatcanido units", function () bsw@1045: bsw@1045: local areas_selector = Area:new_selector() bsw@1045: :reset_fields() bsw@1045: :add_field("area.id", nil, { "grouped" }) bsw@1045: :add_field("area.unit_id", nil, { "grouped" }) bsw@1045: :add_field("area.name", nil, { "grouped" }) bsw@1045: :add_where{ "area.unit_id = ?", unit.id } bsw@1045: :add_where{ "area.active" } bsw@1045: :add_order_by("area.name") bsw@1045: bsw@1045: local areas = areas_selector:exec() bsw@1045: if member then bsw@1045: areas:load_delegation_info_once_for_member_id(member.id) bsw@1045: end bsw@1045: bsw@1045: if #areas > 0 then bsw@1045: bsw@1045: ui.container { bsw@1045: attr = { class = "sidebarHead" }, bsw@1045: content = function () bsw@1045: ui.heading { level = 2, content = function () bsw@1045: ui.link { bsw@1045: attr = { class = "unit" }, bsw@1045: module = "unit", view = "show", id = unit.id, bsw@1045: content = unit.name bsw@1045: } bsw@1045: bsw@1045: if member then bsw@1045: local delegation = Delegation:by_pk(member.id, unit.id, nil, nil) bsw@1045: bsw@1045: if delegation then bsw@1045: ui.link { bsw@1045: module = "delegation", view = "show", params = { bsw@1045: unit_id = unit.id bsw@1045: }, bsw@1045: attr = { class = "delegation_info" }, bsw@1045: content = function () bsw@1045: ui.delegation(delegation.trustee_id, delegation.trustee.name) bsw@1045: end bsw@1045: } bsw@1045: end bsw@1045: end bsw@1045: end } bsw@1045: bsw@1045: end bsw@1045: } bsw@1045: bsw@1045: bsw@1045: ui.tag { tag = "div", attr = { class = "areas areas-" .. unit.id }, content = function () bsw@1045: bsw@1045: for i, area in ipairs(areas) do bsw@1045: bsw/jbe@1309: ui.tag { tag = "div", attr = { class = "sidebarRow" }, content = function () bsw@1045: bsw@1045: if member then bsw@1045: local delegation = Delegation:by_pk(member.id, nil, area.id, nil) bsw@1045: bsw@1045: if delegation then bsw@1045: ui.link { bsw@1045: module = "delegation", view = "show", params = { bsw@1045: area_id = area.id bsw@1045: }, bsw@1045: attr = { class = "delegation_info" }, bsw@1045: content = function () bsw@1045: ui.delegation(delegation.trustee_id, delegation.trustee_id and delegation.trustee.name) bsw@1045: end bsw@1045: } bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: slot.put ( " " ) bsw@1045: bsw@1045: ui.link { bsw@1045: attr = { class = "area" }, bsw@1045: module = "area", view = "show", id = area.id, bsw@1045: content = area.name bsw@1045: } bsw@1045: bsw@1045: bsw@1045: end } bsw@1045: end bsw@1045: end } bsw@1045: end bsw@1045: end ) bsw@1045: end bsw@1045: bsw@1045: