rev |
line source |
bsw@1045
|
1 local member = param.get ( "member", "table" ) or app.session.member
|
bsw@1045
|
2
|
bsw@1045
|
3 local unit = param.get ( "unit", "table" )
|
bsw@1045
|
4
|
bsw@1045
|
5 local areas_selector = Area:new_selector()
|
bsw@1045
|
6 :reset_fields()
|
bsw@1045
|
7 :add_field("area.id", nil, { "grouped" })
|
bsw@1045
|
8 :add_field("area.unit_id", nil, { "grouped" })
|
bsw@1045
|
9 :add_field("area.name", nil, { "grouped" })
|
bsw@1045
|
10 :add_where{ "area.unit_id = ?", unit.id }
|
bsw@1045
|
11 :add_where{ "area.active" }
|
bsw@1045
|
12 :add_order_by("area.name")
|
bsw@1045
|
13
|
bsw@1045
|
14 if member then
|
bsw@1045
|
15 areas_selector:left_join (
|
bsw@1045
|
16 "membership", nil,
|
bsw@1045
|
17 { "membership.area_id = area.id AND membership.member_id = ?", member.id }
|
bsw@1045
|
18 )
|
bsw@1045
|
19 areas_selector:add_field("membership.member_id NOTNULL", "subscribed", { "grouped" })
|
bsw@1045
|
20 end
|
bsw@1045
|
21
|
bsw@1045
|
22
|
bsw@1045
|
23 local areas = areas_selector:exec()
|
bsw@1045
|
24 if member then
|
bsw@1045
|
25 unit:load_delegation_info_once_for_member_id(member.id)
|
bsw@1045
|
26 areas:load_delegation_info_once_for_member_id(member.id)
|
bsw@1045
|
27 end
|
bsw@1045
|
28
|
bsw@1045
|
29
|
bsw@1045
|
30 ui.sidebar ( "tab-whatcanido", function ()
|
bsw@1045
|
31
|
bsw@1045
|
32 ui.sidebarHead( function ()
|
bsw@1045
|
33 ui.heading {
|
bsw@1045
|
34 level = 2, content = _"Subject areas"
|
bsw@1045
|
35 }
|
bsw@1045
|
36 end )
|
bsw@1045
|
37
|
bsw@1045
|
38 if #areas > 0 then
|
bsw@1045
|
39
|
bsw@1045
|
40 ui.container { class = "areas", content = function ()
|
bsw@1045
|
41
|
bsw@1045
|
42 for i, area in ipairs ( areas ) do
|
bsw@1045
|
43
|
bsw@1045
|
44 ui.container { attr = { class = "sidebarRow" }, content = function ()
|
bsw@1045
|
45
|
bsw@1045
|
46 if member then
|
bsw@1045
|
47 local delegation = Delegation:by_pk(member.id, nil, area.id, nil)
|
bsw@1045
|
48
|
bsw@1045
|
49 if delegation then
|
bsw@1045
|
50 ui.link {
|
bsw@1045
|
51 module = "delegation", view = "show", params = {
|
bsw@1045
|
52 area_id = area.id
|
bsw@1045
|
53 },
|
bsw@1045
|
54 attr = { class = "delegation_info" },
|
bsw@1045
|
55 content = function ()
|
bsw@1045
|
56 ui.delegation(delegation.trustee_id, delegation.trustee_id and delegation.trustee.name)
|
bsw@1045
|
57 end
|
bsw@1045
|
58 }
|
bsw@1045
|
59 end
|
bsw@1045
|
60 end
|
bsw@1045
|
61
|
bsw@1045
|
62 if area.subscribed then
|
bsw@1045
|
63 ui.image { attr = { class = "icon24 star" }, static = "icons/48/star.png" }
|
bsw@1045
|
64 end
|
bsw@1045
|
65
|
bsw@1045
|
66 ui.link {
|
bsw@1045
|
67 attr = { class = "area" },
|
bsw@1045
|
68 module = "area", view = "show", id = area.id,
|
bsw@1045
|
69 content = area.name
|
bsw@1045
|
70 }
|
bsw@1045
|
71
|
bsw@1045
|
72 end } -- ui.tag "li"
|
bsw@1045
|
73
|
bsw@1045
|
74 end -- for i, area
|
bsw@1045
|
75
|
bsw@1045
|
76 end } -- ui.tag "ul"
|
bsw@1045
|
77
|
bsw@1045
|
78 end -- if #areas > 0
|
bsw@1045
|
79
|
bsw@1045
|
80 end ) -- ui.sidebar |