| rev | 
   line source | 
| 
bsw@1045
 | 
     1 local member = param.get ( "member", "table" )
 | 
| 
bsw@1045
 | 
     2 local units
 | 
| 
bsw@1045
 | 
     3 if member then
 | 
| 
bsw@1218
 | 
     4   units = member:get_reference_selector("units"):add_order_by("name"):exec()
 | 
| 
bsw@1045
 | 
     5   units:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@1045
 | 
     6 else
 | 
| 
bsw@1045
 | 
     7   units = Unit:new_selector():add_where("active"):add_order_by("name"):exec()
 | 
| 
bsw@1045
 | 
     8   ui.sidebar( "tab-whatcanido", function()
 | 
| 
bsw@1045
 | 
     9     ui.sidebarHead( function()
 | 
| 
bsw@1045
 | 
    10       ui.heading { level = 2, content = _"Organizational units" }
 | 
| 
bsw@1045
 | 
    11     end )
 | 
| 
bsw@1045
 | 
    12     ui.sidebarSection( function()
 | 
| 
bsw@1045
 | 
    13       execute.view { module = "unit", view = "_list" }
 | 
| 
bsw@1045
 | 
    14     end )
 | 
| 
bsw@1045
 | 
    15   end )
 | 
| 
bsw@1045
 | 
    16   return
 | 
| 
bsw@1045
 | 
    17 end
 | 
| 
bsw@1045
 | 
    18 
 | 
| 
bsw@1045
 | 
    19 
 | 
| 
bsw@1045
 | 
    20 for i, unit in ipairs(units) do
 | 
| 
bsw@1045
 | 
    21   
 | 
| 
bsw@1045
 | 
    22   ui.sidebar ( "tab-whatcanido units", function ()
 | 
| 
bsw@1045
 | 
    23 
 | 
| 
bsw@1045
 | 
    24     local areas_selector = Area:new_selector()
 | 
| 
bsw@1045
 | 
    25       :reset_fields()
 | 
| 
bsw@1045
 | 
    26       :add_field("area.id", nil, { "grouped" })
 | 
| 
bsw@1045
 | 
    27       :add_field("area.unit_id", nil, { "grouped" })
 | 
| 
bsw@1045
 | 
    28       :add_field("area.name", nil, { "grouped" })
 | 
| 
bsw@1045
 | 
    29       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@1045
 | 
    30       :add_where{ "area.active" }
 | 
| 
bsw@1045
 | 
    31       :add_order_by("area.name")
 | 
| 
bsw@1045
 | 
    32 
 | 
| 
bsw@1045
 | 
    33     if member then
 | 
| 
bsw@1045
 | 
    34       areas_selector:left_join ( 
 | 
| 
bsw@1045
 | 
    35         "membership", nil, 
 | 
| 
bsw@1045
 | 
    36         { "membership.area_id = area.id AND membership.member_id = ?", member.id } 
 | 
| 
bsw@1045
 | 
    37       )
 | 
| 
bsw@1045
 | 
    38       areas_selector:add_field("membership.member_id NOTNULL", "subscribed", { "grouped" })
 | 
| 
bsw@1045
 | 
    39     end
 | 
| 
bsw@1045
 | 
    40 
 | 
| 
bsw@1045
 | 
    41     local areas = areas_selector:exec()
 | 
| 
bsw@1045
 | 
    42     if member then
 | 
| 
bsw@1045
 | 
    43       areas:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@1045
 | 
    44     end
 | 
| 
bsw@1045
 | 
    45     
 | 
| 
bsw@1045
 | 
    46     if #areas > 0 then
 | 
| 
bsw@1045
 | 
    47 
 | 
| 
bsw@1045
 | 
    48       ui.container {
 | 
| 
bsw@1045
 | 
    49         attr = { class = "sidebarHead" },
 | 
| 
bsw@1045
 | 
    50         content = function ()
 | 
| 
bsw@1045
 | 
    51           ui.heading { level = 2, content = function ()
 | 
| 
bsw@1045
 | 
    52             ui.link {
 | 
| 
bsw@1045
 | 
    53               attr = { class = "unit" },
 | 
| 
bsw@1045
 | 
    54               module = "unit", view = "show", id = unit.id,
 | 
| 
bsw@1045
 | 
    55               content = unit.name
 | 
| 
bsw@1045
 | 
    56             }
 | 
| 
bsw@1045
 | 
    57           
 | 
| 
bsw@1045
 | 
    58             if member then
 | 
| 
bsw@1045
 | 
    59               local delegation = Delegation:by_pk(member.id, unit.id, nil, nil)
 | 
| 
bsw@1045
 | 
    60               
 | 
| 
bsw@1045
 | 
    61               if delegation then
 | 
| 
bsw@1045
 | 
    62                 ui.link { 
 | 
| 
bsw@1045
 | 
    63                   module = "delegation", view = "show", params = {
 | 
| 
bsw@1045
 | 
    64                     unit_id = unit.id
 | 
| 
bsw@1045
 | 
    65                   },
 | 
| 
bsw@1045
 | 
    66                   attr = { class = "delegation_info" }, 
 | 
| 
bsw@1045
 | 
    67                   content = function ()
 | 
| 
bsw@1045
 | 
    68                     ui.delegation(delegation.trustee_id, delegation.trustee.name)
 | 
| 
bsw@1045
 | 
    69                   end
 | 
| 
bsw@1045
 | 
    70                 }
 | 
| 
bsw@1045
 | 
    71               end
 | 
| 
bsw@1045
 | 
    72             end
 | 
| 
bsw@1045
 | 
    73           end }
 | 
| 
bsw@1045
 | 
    74           
 | 
| 
bsw@1045
 | 
    75         end
 | 
| 
bsw@1045
 | 
    76       }
 | 
| 
bsw@1045
 | 
    77       
 | 
| 
bsw@1045
 | 
    78       
 | 
| 
bsw@1045
 | 
    79       ui.tag { tag = "div", attr = { class = "areas areas-" .. unit.id }, content = function ()
 | 
| 
bsw@1045
 | 
    80       
 | 
| 
bsw@1045
 | 
    81         local any_subscribed = false
 | 
| 
bsw@1045
 | 
    82         local subscribed_count = 0
 | 
| 
bsw@1045
 | 
    83         for i, area in ipairs(areas) do
 | 
| 
bsw@1045
 | 
    84 
 | 
| 
bsw@1045
 | 
    85           local class = "sidebarRow"
 | 
| 
bsw@1045
 | 
    86           class = class .. (not area.subscribed and " disabled" or "")
 | 
| 
bsw@1045
 | 
    87           
 | 
| 
bsw@1045
 | 
    88           ui.tag { tag = "div", attr = { class = class }, content = function ()
 | 
| 
bsw@1045
 | 
    89             
 | 
| 
bsw@1045
 | 
    90             if area.subscribed then
 | 
| 
bsw@1045
 | 
    91               local text = _"subscribed"
 | 
| 
bsw@1058
 | 
    92               ui.image { attr = { class = "icon16 star", alt = text, title = text }, static = "icons/48/star.png" }
 | 
| 
bsw@1045
 | 
    93               any_subscribed = true
 | 
| 
bsw@1045
 | 
    94               subscribed_count = subscribed_count +1
 | 
| 
bsw@1045
 | 
    95             end
 | 
| 
bsw@1045
 | 
    96             
 | 
| 
bsw@1045
 | 
    97             if member then
 | 
| 
bsw@1045
 | 
    98               local delegation = Delegation:by_pk(member.id, nil, area.id, nil)
 | 
| 
bsw@1045
 | 
    99         
 | 
| 
bsw@1045
 | 
   100               if delegation then
 | 
| 
bsw@1045
 | 
   101                 ui.link { 
 | 
| 
bsw@1045
 | 
   102                   module = "delegation", view = "show", params = {
 | 
| 
bsw@1045
 | 
   103                     area_id = area.id
 | 
| 
bsw@1045
 | 
   104                   },
 | 
| 
bsw@1045
 | 
   105                   attr = { class = "delegation_info" }, 
 | 
| 
bsw@1045
 | 
   106                   content = function ()
 | 
| 
bsw@1045
 | 
   107                     ui.delegation(delegation.trustee_id, delegation.trustee_id and delegation.trustee.name)
 | 
| 
bsw@1045
 | 
   108                   end
 | 
| 
bsw@1045
 | 
   109                 }
 | 
| 
bsw@1045
 | 
   110               end
 | 
| 
bsw@1045
 | 
   111             end
 | 
| 
bsw@1045
 | 
   112       
 | 
| 
bsw@1045
 | 
   113             slot.put ( " " )
 | 
| 
bsw@1045
 | 
   114             
 | 
| 
bsw@1045
 | 
   115             ui.link {
 | 
| 
bsw@1045
 | 
   116               attr = { class = "area" },
 | 
| 
bsw@1045
 | 
   117               module = "area", view = "show", id = area.id,
 | 
| 
bsw@1045
 | 
   118               content = area.name
 | 
| 
bsw@1045
 | 
   119             }
 | 
| 
bsw@1045
 | 
   120             
 | 
| 
bsw@1045
 | 
   121             
 | 
| 
bsw@1045
 | 
   122           end }
 | 
| 
bsw@1045
 | 
   123         end
 | 
| 
bsw@1045
 | 
   124         if subscribed_count < #areas then
 | 
| 
bsw@1045
 | 
   125           local text 
 | 
| 
bsw@1045
 | 
   126           if any_subscribed then
 | 
| 
bsw@1045
 | 
   127             text = _"show other subject areas"
 | 
| 
bsw@1045
 | 
   128           else
 | 
| 
bsw@1045
 | 
   129             text = _"show subject areas"
 | 
| 
bsw@1045
 | 
   130           end
 | 
| 
bsw@1045
 | 
   131           ui.script{ script = "$('.areas-" .. unit.id .. "').addClass('folded');" }
 | 
| 
bsw@1045
 | 
   132           ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenfolded" }, content = function ()
 | 
| 
bsw@1045
 | 
   133             ui.link {
 | 
| 
bsw@1045
 | 
   134               attr = { 
 | 
| 
bsw@1045
 | 
   135                 onclick = "$('.areas-" .. unit.id .. "').removeClass('folded'); return false;"
 | 
| 
bsw@1045
 | 
   136               },
 | 
| 
bsw@1045
 | 
   137               text = text
 | 
| 
bsw@1045
 | 
   138             }
 | 
| 
bsw@1045
 | 
   139           end }
 | 
| 
bsw@1045
 | 
   140           ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenunfolded" }, content = function ()
 | 
| 
bsw@1045
 | 
   141             ui.link {
 | 
| 
bsw@1045
 | 
   142               attr = { 
 | 
| 
bsw@1045
 | 
   143                 onclick = "$('.areas-" .. unit.id .. "').addClass('folded'); return false;"
 | 
| 
bsw@1045
 | 
   144               },
 | 
| 
bsw@1045
 | 
   145               text = _"collapse subject areas"
 | 
| 
bsw@1045
 | 
   146             }
 | 
| 
bsw@1045
 | 
   147           end }
 | 
| 
bsw@1045
 | 
   148         end
 | 
| 
bsw@1045
 | 
   149       end }
 | 
| 
bsw@1045
 | 
   150     end 
 | 
| 
bsw@1045
 | 
   151   end )
 | 
| 
bsw@1045
 | 
   152 end
 | 
| 
bsw@1045
 | 
   153 
 | 
| 
bsw@1045
 | 
   154 
 |