| 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 local areas = areas_selector:exec()
 | 
| 
bsw@1045
 | 
    15 if member then
 | 
| 
bsw@1045
 | 
    16   unit:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@1045
 | 
    17   areas:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@1045
 | 
    18 end
 | 
| 
bsw@1045
 | 
    19 
 | 
| 
bsw@1045
 | 
    20   
 | 
| 
bsw@1045
 | 
    21 ui.sidebar ( "tab-whatcanido", function ()
 | 
| 
bsw@1045
 | 
    22 
 | 
| 
bsw@1045
 | 
    23   ui.sidebarHead( function ()
 | 
| 
bsw@1045
 | 
    24     ui.heading {
 | 
| 
bsw@1045
 | 
    25       level = 2, content = _"Subject areas"
 | 
| 
bsw@1045
 | 
    26     }
 | 
| 
bsw@1045
 | 
    27   end )
 | 
| 
bsw@1045
 | 
    28   
 | 
| 
bsw@1045
 | 
    29   if #areas > 0 then
 | 
| 
bsw@1045
 | 
    30     
 | 
| 
bsw@1045
 | 
    31     ui.container { class = "areas", content = function ()
 | 
| 
bsw@1045
 | 
    32       
 | 
| 
bsw@1045
 | 
    33       for i, area in ipairs ( areas ) do
 | 
| 
bsw@1045
 | 
    34         
 | 
| 
bsw@1045
 | 
    35         ui.container { attr = { class = "sidebarRow" }, content = function ()
 | 
| 
bsw@1045
 | 
    36         
 | 
| 
bsw@1045
 | 
    37           if member then
 | 
| 
bsw@1045
 | 
    38             local delegation = Delegation:by_pk(member.id, nil, area.id, nil)
 | 
| 
bsw@1045
 | 
    39       
 | 
| 
bsw@1045
 | 
    40             if delegation then
 | 
| 
bsw@1045
 | 
    41               ui.link { 
 | 
| 
bsw@1045
 | 
    42                 module = "delegation", view = "show", params = {
 | 
| 
bsw@1045
 | 
    43                   area_id = area.id
 | 
| 
bsw@1045
 | 
    44                 },
 | 
| 
bsw@1045
 | 
    45                 attr = { class = "delegation_info" }, 
 | 
| 
bsw@1045
 | 
    46                 content = function ()
 | 
| 
bsw@1045
 | 
    47                   ui.delegation(delegation.trustee_id, delegation.trustee_id and delegation.trustee.name)
 | 
| 
bsw@1045
 | 
    48                 end
 | 
| 
bsw@1045
 | 
    49               }
 | 
| 
bsw@1045
 | 
    50             end
 | 
| 
bsw@1045
 | 
    51           end
 | 
| 
bsw@1045
 | 
    52         
 | 
| 
bsw@1045
 | 
    53           if area.subscribed then
 | 
| 
bsw@1058
 | 
    54             ui.image { attr = { class = "icon16 star" }, static = "icons/48/star.png" }
 | 
| 
bsw@1045
 | 
    55           end
 | 
| 
bsw@1045
 | 
    56           
 | 
| 
bsw@1045
 | 
    57           ui.link {
 | 
| 
bsw@1045
 | 
    58             attr = { class = "area" },
 | 
| 
bsw@1045
 | 
    59             module = "area", view = "show", id = area.id,
 | 
| 
bsw@1045
 | 
    60             content = area.name
 | 
| 
bsw@1045
 | 
    61           }
 | 
| 
bsw@1045
 | 
    62           
 | 
| 
bsw@1045
 | 
    63         end } -- ui.tag "li"
 | 
| 
bsw@1045
 | 
    64         
 | 
| 
bsw@1045
 | 
    65       end -- for i, area
 | 
| 
bsw@1045
 | 
    66       
 | 
| 
bsw@1045
 | 
    67     end } -- ui.tag "ul"
 | 
| 
bsw@1045
 | 
    68     
 | 
| 
bsw@1045
 | 
    69   end -- if #areas > 0
 | 
| 
bsw@1045
 | 
    70 
 | 
| 
bsw/jbe@1309
 | 
    71 end ) -- ui.sidebar
 |