liquid_feedback_frontend

diff app/main/index/_sidebar_units.lua @ 1045:701a5cf6b067

Imported LiquidFeedback Frontend 3.0 branch
author bsw
date Thu Jul 10 01:19:48 2014 +0200 (2014-07-10)
parents
children bd2509e7f627
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/app/main/index/_sidebar_units.lua	Thu Jul 10 01:19:48 2014 +0200
     1.3 @@ -0,0 +1,154 @@
     1.4 +local member = param.get ( "member", "table" )
     1.5 +local units
     1.6 +if member then
     1.7 +  units = member.units
     1.8 +  units:load_delegation_info_once_for_member_id(member.id)
     1.9 +else
    1.10 +  units = Unit:new_selector():add_where("active"):add_order_by("name"):exec()
    1.11 +  ui.sidebar( "tab-whatcanido", function()
    1.12 +    ui.sidebarHead( function()
    1.13 +      ui.heading { level = 2, content = _"Organizational units" }
    1.14 +    end )
    1.15 +    ui.sidebarSection( function()
    1.16 +      execute.view { module = "unit", view = "_list" }
    1.17 +    end )
    1.18 +  end )
    1.19 +  return
    1.20 +end
    1.21 +
    1.22 +
    1.23 +for i, unit in ipairs(units) do
    1.24 +  
    1.25 +  ui.sidebar ( "tab-whatcanido units", function ()
    1.26 +
    1.27 +    local areas_selector = Area:new_selector()
    1.28 +      :reset_fields()
    1.29 +      :add_field("area.id", nil, { "grouped" })
    1.30 +      :add_field("area.unit_id", nil, { "grouped" })
    1.31 +      :add_field("area.name", nil, { "grouped" })
    1.32 +      :add_where{ "area.unit_id = ?", unit.id }
    1.33 +      :add_where{ "area.active" }
    1.34 +      :add_order_by("area.name")
    1.35 +
    1.36 +    if member then
    1.37 +      areas_selector:left_join ( 
    1.38 +        "membership", nil, 
    1.39 +        { "membership.area_id = area.id AND membership.member_id = ?", member.id } 
    1.40 +      )
    1.41 +      areas_selector:add_field("membership.member_id NOTNULL", "subscribed", { "grouped" })
    1.42 +    end
    1.43 +
    1.44 +    local areas = areas_selector:exec()
    1.45 +    if member then
    1.46 +      areas:load_delegation_info_once_for_member_id(member.id)
    1.47 +    end
    1.48 +    
    1.49 +    if #areas > 0 then
    1.50 +
    1.51 +      ui.container {
    1.52 +        attr = { class = "sidebarHead" },
    1.53 +        content = function ()
    1.54 +          ui.heading { level = 2, content = function ()
    1.55 +            ui.link {
    1.56 +              attr = { class = "unit" },
    1.57 +              module = "unit", view = "show", id = unit.id,
    1.58 +              content = unit.name
    1.59 +            }
    1.60 +          
    1.61 +            if member then
    1.62 +              local delegation = Delegation:by_pk(member.id, unit.id, nil, nil)
    1.63 +              
    1.64 +              if delegation then
    1.65 +                ui.link { 
    1.66 +                  module = "delegation", view = "show", params = {
    1.67 +                    unit_id = unit.id
    1.68 +                  },
    1.69 +                  attr = { class = "delegation_info" }, 
    1.70 +                  content = function ()
    1.71 +                    ui.delegation(delegation.trustee_id, delegation.trustee.name)
    1.72 +                  end
    1.73 +                }
    1.74 +              end
    1.75 +            end
    1.76 +          end }
    1.77 +          
    1.78 +        end
    1.79 +      }
    1.80 +      
    1.81 +      
    1.82 +      ui.tag { tag = "div", attr = { class = "areas areas-" .. unit.id }, content = function ()
    1.83 +      
    1.84 +        local any_subscribed = false
    1.85 +        local subscribed_count = 0
    1.86 +        for i, area in ipairs(areas) do
    1.87 +
    1.88 +          local class = "sidebarRow"
    1.89 +          class = class .. (not area.subscribed and " disabled" or "")
    1.90 +          
    1.91 +          ui.tag { tag = "div", attr = { class = class }, content = function ()
    1.92 +            
    1.93 +            if area.subscribed then
    1.94 +              local text = _"subscribed"
    1.95 +              ui.image { attr = { class = "icon24 star", alt = text, title = text }, static = "icons/48/star.png" }
    1.96 +              any_subscribed = true
    1.97 +              subscribed_count = subscribed_count +1
    1.98 +            end
    1.99 +            
   1.100 +            if member then
   1.101 +              local delegation = Delegation:by_pk(member.id, nil, area.id, nil)
   1.102 +        
   1.103 +              if delegation then
   1.104 +                ui.link { 
   1.105 +                  module = "delegation", view = "show", params = {
   1.106 +                    area_id = area.id
   1.107 +                  },
   1.108 +                  attr = { class = "delegation_info" }, 
   1.109 +                  content = function ()
   1.110 +                    ui.delegation(delegation.trustee_id, delegation.trustee_id and delegation.trustee.name)
   1.111 +                  end
   1.112 +                }
   1.113 +              end
   1.114 +            end
   1.115 +      
   1.116 +            slot.put ( " " )
   1.117 +            
   1.118 +            ui.link {
   1.119 +              attr = { class = "area" },
   1.120 +              module = "area", view = "show", id = area.id,
   1.121 +              content = area.name
   1.122 +            }
   1.123 +            
   1.124 +            
   1.125 +          end }
   1.126 +        end
   1.127 +        if subscribed_count < #areas then
   1.128 +          local text 
   1.129 +          if any_subscribed then
   1.130 +            text = _"show other subject areas"
   1.131 +          else
   1.132 +            text = _"show subject areas"
   1.133 +          end
   1.134 +          ui.script{ script = "$('.areas-" .. unit.id .. "').addClass('folded');" }
   1.135 +          ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenfolded" }, content = function ()
   1.136 +            ui.link {
   1.137 +              attr = { 
   1.138 +                onclick = "$('.areas-" .. unit.id .. "').removeClass('folded'); return false;"
   1.139 +              },
   1.140 +              text = text
   1.141 +            }
   1.142 +          end }
   1.143 +          ui.tag { tag = "div", attr = { class = "sidebarRow moreLink whenunfolded" }, content = function ()
   1.144 +            ui.link {
   1.145 +              attr = { 
   1.146 +                onclick = "$('.areas-" .. unit.id .. "').addClass('folded'); return false;"
   1.147 +              },
   1.148 +              text = _"collapse subject areas"
   1.149 +            }
   1.150 +          end }
   1.151 +        end
   1.152 +      end }
   1.153 +    end 
   1.154 +  end )
   1.155 +end
   1.156 +
   1.157 +

Impressum / About Us