liquid_feedback_frontend
view app/main/index/_member_home.lua @ 909:3341081a69e0
Translations files updated for new phrases
| author | bsw | 
|---|---|
| date | Sun Sep 23 16:42:33 2012 +0200 (2012-09-23) | 
| parents | 9c714f697e4e | 
| children | 8d5b214889c3 | 
 line source
     1 local member = param.get("member", "table")
     2 local for_member = param.get("for_member", atom.boolean)
     3 local filter_unit = param.get_all_cgi()["filter_unit"] or "my_areas"
     5 if not for_member then
     7   ui.container{ attr = { class = "ui_filter" }, content = function()
     8     ui.container{ attr = { class = "ui_filter_head" }, content = function()
    10       ui.link{
    11         attr = { class = filter_unit == "my_areas" and "ui_tabs_link active" or nil },
    12         text = _"My areas",
    13         module = "index", view = "index", params = { filter_unit = "my_areas" }
    14       }
    16       slot.put(" ")
    18       ui.link{
    19         attr = { class = filter_unit == "my_units" and "ui_tabs_link active" or nil },
    20         text = _"All areas in my units",
    21         module = "index", view = "index", params = { filter_unit = "my_units" }
    22       }
    24       slot.put(" ")
    26       ui.link{
    27         attr = { class = filter_unit == "global" and "active" or nil },
    28         text = _"All units",
    29         module = "index", view = "index", params = { filter_unit = "global" }
    30       }
    31     end }
    32   end }
    33 end
    35 if not for_member then
    36   if filter_unit == "global" then
    37     execute.view{ module = "unit", view = "_list" }
    38     return
    39   end
    41 end
    43 local units = Unit:new_selector():add_where("active"):add_order_by("name"):exec()
    45 if member then
    46   units:load_delegation_info_once_for_member_id(member.id)
    47 end
    49 for i, unit in ipairs(units) do
    50   if member:has_voting_right_for_unit_id(unit.id) then
    52     local areas_selector = Area:new_selector()
    53       :reset_fields()
    54       :add_field("area.id", nil, { "grouped" })
    55       :add_field("area.unit_id", nil, { "grouped" })
    56       :add_field("area.name", nil, { "grouped" })
    57       :add_field("member_weight", nil, { "grouped" })
    58       :add_field("direct_member_count", nil, { "grouped" })
    59       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.accepted ISNULL AND issue.closed ISNULL)", "issues_new_count")
    60       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.accepted NOTNULL AND issue.half_frozen ISNULL AND issue.closed ISNULL)", "issues_discussion_count")
    61       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.half_frozen NOTNULL AND issue.fully_frozen ISNULL AND issue.closed ISNULL)", "issues_frozen_count")
    62       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed ISNULL)", "issues_voting_count")
    63       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed NOTNULL)", "issues_finished_count")
    64       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen ISNULL AND issue.closed NOTNULL)", "issues_cancelled_count")
    65       :add_where{ "area.unit_id = ?", unit.id }
    66       :add_where{ "area.active" }
    67       :add_order_by("area.name")
    69     if filter_unit == "my_areas" then
    70       areas_selector:join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
    71     else
    72       areas_selector:join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", member.id })
    73     end
    75     local area_count = areas_selector:count()
    77     local max_area_count = Area:new_selector()
    78       :add_where{ "area.unit_id = ?", unit.id }
    79       :add_where{ "area.active" }
    80       :count()
    81     local more_area_count = max_area_count - area_count
    82     local delegated_count = Area:new_selector()
    83       :add_where{ "area.unit_id = ?", unit.id }
    84       :add_where{ "area.active" }
    85       :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
    86       :add_where{ "membership.member_id ISNULL" }
    87       :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
    88       :add_where{ "delegation.trustee_id NOTNULL" }
    89       :count()
    91     local more_area_text
    92     if area_count == 0 and more_area_count == 1 then
    93       if app.session.member_id == member.id then
    94         more_area_text = _("You are not participating in the only area of the unit")
    95       else
    96         more_area_text = _("Member is not participating in the only area of the unit")
    97       end
    98     elseif area_count == 0 and more_area_count > 0 then
    99       if app.session.member_id == member.id then
   100         more_area_text = _("You are not participating in any of the #{count} areas in this unit", { count = more_area_count })
   101       else
   102         more_area_text = _("Member is not participating in any of the #{count} areas in this unit", { count = more_area_count })
   103       end
   104     elseif area_count > 0 and more_area_count == 1 then
   105       more_area_text = _("One more area in this unit")
   106     elseif area_count > 0 and more_area_count > 0 then
   107       more_area_text = _("#{count} more areas in this unit", { count = more_area_count })
   108     end
   109     local delegated_text
   110     if delegated_count == 1 then
   111       delegated_text = _("One of them have an area delegation set", { count = delegated_count })
   112     elseif delegated_count > 0 then
   113       delegated_text = _("#{count} of them have an area delegation set", { count = delegated_count })
   114     end
   116     ui.container{ attr = { class = "area_list" }, content = function()
   117       execute.view{ module = "unit", view = "_head", params = { unit = unit, show_content = true, member = member } }
   119       if area_count > 0 then
   120         local areas = areas_selector:exec()
   122         areas:load_delegation_info_once_for_member_id(member.id)
   124         for i, area in ipairs(areas) do
   125           execute.view{
   126             module = "area", view = "_list_entry", params = {
   127               area = area, member = member
   128             }
   129           }
   130         end
   131       end 
   133       if area_count == 0 and member:has_voting_right_for_unit_id(unit.id) or
   134          more_area_count > 0 then
   136       end
   137     end }
   138     ui.container{ attr = { class = "area", style="margin-top: 1ex; margin-left: 10px;" }, content = function()
   139       ui.container{ attr = { class = "title" }, content = function()
   140         if more_area_text then
   141           ui.link{ module = "unit", view = "show", id = unit.id, text = more_area_text }
   142         end
   143         if delegated_text then
   144           slot.put(" · ")
   145           ui.tag{ content = delegated_text }
   146         end
   147       end }
   148     end }
   149     slot.put("<br />")
   150   end
   151 end
