bsw@1045: local member = param.get ( "member", "table" ) bsw@1045: local units bsw@1045: if member then bsw@1045: units = member.units 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: if member then bsw@1045: areas_selector:left_join ( bsw@1045: "membership", nil, bsw@1045: { "membership.area_id = area.id AND membership.member_id = ?", member.id } bsw@1045: ) bsw@1045: areas_selector:add_field("membership.member_id NOTNULL", "subscribed", { "grouped" }) bsw@1045: end 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: local any_subscribed = false bsw@1045: local subscribed_count = 0 bsw@1045: for i, area in ipairs(areas) do bsw@1045: bsw@1045: local class = "sidebarRow" bsw@1045: class = class .. (not area.subscribed and " disabled" or "") bsw@1045: bsw@1045: ui.tag { tag = "div", attr = { class = class }, content = function () bsw@1045: bsw@1045: if area.subscribed then bsw@1045: local text = _"subscribed" bsw@1045: ui.image { attr = { class = "icon24 star", alt = text, title = text }, static = "icons/48/star.png" } bsw@1045: any_subscribed = true bsw@1045: subscribed_count = subscribed_count +1 bsw@1045: end 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: if subscribed_count < #areas then bsw@1045: local text bsw@1045: if any_subscribed then bsw@1045: text = _"show other subject areas" bsw@1045: else bsw@1045: text = _"show subject areas" bsw@1045: end bsw@1045: ui.script{ script = "$('.areas-" .. unit.id .. "').addClass('folded');" } bsw@1045: ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenfolded" }, content = function () bsw@1045: ui.link { bsw@1045: attr = { bsw@1045: onclick = "$('.areas-" .. unit.id .. "').removeClass('folded'); return false;" bsw@1045: }, bsw@1045: text = text bsw@1045: } bsw@1045: end } bsw@1045: ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenunfolded" }, content = function () bsw@1045: ui.link { bsw@1045: attr = { bsw@1045: onclick = "$('.areas-" .. unit.id .. "').addClass('folded'); return false;" bsw@1045: }, bsw@1045: text = _"collapse subject areas" bsw@1045: } bsw@1045: end } bsw@1045: end bsw@1045: end } bsw@1045: end bsw@1045: end ) bsw@1045: end bsw@1045: bsw@1045: