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