liquid_feedback_frontend
view env/ui/tabs.lua @ 75:733f65c0c0a0
Bugfixes, feature enhancements, code-cleanup, and major work on API
Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
| author | bsw | 
|---|---|
| date | Thu Jul 08 18:44:02 2010 +0200 (2010-07-08) | 
| parents | 4f39f0a0d5b5 | 
| children | d4b4adb9a4df | 
 line source
     1 if config.user_tab_mode == "accordeon" or config.user_tab_mode == "accordeon_first_expanded" or config.user_tab_mode == "accordeon_all_expanded" then
     3   function ui.tabs(tabs)
     4     local params = param.get_all_cgi()
     5     local current_tabs_string = params["tab"]
     6     local current_tabs = {}
     7     if current_tabs_string then
     8       for current_tab in current_tabs_string:gmatch("([^%|]+)") do
     9         current_tabs[current_tab] = current_tab
    10       end
    11     end
    13     local unique_string = param.get("tab_id") or multirand.string(16, '0123456789abcdef')
    15     function render_tab(tab, first)
    16       local params = param.get_all_cgi()
    17       local active = false
    18       for current_tab in pairs(current_tabs) do
    19         if tab.name == current_tab then
    20           active = true
    21         end
    22       end
    23       if config.user_tab_mode == "accordeon_first_expanded" then
    24         if first and current_tabs_string == nil then
    25           active = true
    26         end
    27       end
    28       local link_tabs = {}
    29       if config.user_tab_mode == "accordeon" 
    30         or config.user_tab_mode == "accordeon_first_expanded"
    31         or config.user_tab_mode == "accordeon_all_expanded" and current_tabs_string
    32       then
    33         if not current_tabs_string and not first then
    34           link_tabs[tabs[1].name] = true
    35         end
    36         for current_tab in pairs(current_tabs) do
    37           if current_tab ~= tab.name then
    38             link_tabs[current_tab] = true
    39           end
    40         end
    41       elseif config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string then
    42         for i, current_tab in ipairs(tabs) do
    43           if current_tab.name ~= tab.name then
    44             link_tabs[current_tab.name] = true
    45           end
    46         end
    47       end
    48       if not active then
    49         link_tabs[tab.name] = true
    50       end
    51       local link_tab_string = ""
    52       for link_tab in pairs(link_tabs) do
    53         if #link_tab_string > 0 then
    54           link_tab_string = link_tab_string .. "|"
    55         end
    56         link_tab_string = link_tab_string .. link_tab
    57       end
    58       params["tab"] = link_tab_string
    59       local onclick
    60       if not tab.content then
    61         onclick =
    62           'if (ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]) {' ..
    63             'el=document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '");' ..
    64             'el.innerHTML="";' ..
    65             'el.style.display="none";' ..
    66             'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=false' ..
    67           '} else {' ..
    68             'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=true;' ..
    69             'document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '").style.display="block"; ' ..
    70             ui._partial_load_js{
    71               params = { tab = tab.name }
    72             } ..
    73           '};' ..
    74           'return(false);'
    75       end
    76       ui.link{
    77         attr = {
    78           name = "tab_" .. tab.name,
    79           class = (
    80             tab.name == current_tab and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or
    81             not current_tab and i == 1 and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "")  or
    82             "ui_tabs_accordeon_head" .. (tab.class and (" " .. tab.class) or "") 
    83           ),
    84           id = "tab" .. unique_string .. "_head_" .. tab.name,
    85           onclick = onclick,
    86         },
    87         module  = request.get_module(),
    88         view    = request.get_view(),
    89         id      = param.get_id_cgi(),
    90         params  = params,
    91         anchor  = "tab" .. unique_string .. "_" .. tab.name,
    92         content = function()
    93           if tab.icon then
    94             if not tab.icon.attr then
    95               tab.icon.attr = {}
    96             end
    97             tab.icon.attr.id = "tab" .. unique_string .. "_icon_" .. tab.name
    98             tab.icon.attr.width = 16
    99             tab.icon.attr.height = 16
   100             ui.image(tab.icon)
   101           end
   102           slot.put(tab.label)
   103         end
   104       }
   105       local expanded = active or not request.get_json_request_slots() and config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string
   106       ui.container{
   107         attr = {
   108           class = "ui_tabs_accordeon_content" .. (tab.class and (" " .. tab.class) or ""),
   109           style = not expanded and "display: none;" or nil,
   110           id = "tab" .. unique_string .. "_content_" .. tab.name
   111         },
   112         content = function()
   113           if expanded then
   114             ui.script{ script = 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"] = true;' }
   115             execute.view{
   116               module = tab.module,
   117               view = tab.view,
   118               id = tab.id,
   119               params = tab.params
   120             }
   121           else
   122             slot.put(" ")
   123           end
   124         end
   125       }
   126     end
   128     if not request.get_json_request_slots() or not current_tabs_string then
   129       ui.script{ script = "ui_tabs_active['" .. unique_string .. "'] = {};" }
   130       ui.container{
   131         attr = { class = "ui_tabs" },
   132         content = function()
   133           for i, tab in ipairs(tabs) do
   134             local static_params = tabs.static_params or {}
   135             static_params.tab = tab.name
   136             static_params.tab_id = unique_string
   137             ui.partial{
   138               module           = tabs.module,
   139               view             = tabs.view,
   140               id               = tabs.id,
   141               params           = static_params,
   142               param_names      = { "page" },
   143               hourglass_target = "tab" .. unique_string .. "_icon_" .. tab.name,
   144               target           = "tab" .. unique_string .. "_content_" .. tab.name,
   145               content = function()
   146                 render_tab(tab, i == 1)
   147               end
   148             }
   149           end
   150         end
   151       }
   152     else
   153       local dyntab
   154       for i, tab in ipairs(tabs) do
   155         if tab.name == current_tabs_string then
   156           dyntab = tab
   157         end
   158       end
   159       if dyntab then
   160         local static_params = tabs.static_params or {}
   161         static_params.tab = dyntab.name
   162         static_params.tab_id = unique_string
   163         dyntab.params.tab_id = unique_string
   164         ui.partial{
   165           module           = tabs.module,
   166           view             = tabs.view,
   167           id               = tabs.id,
   168           params           = static_params,
   169           param_names      = { "page" },
   170           hourglass_target = "tab" .. unique_string .. "_icon_" .. dyntab.name,
   171           target           = "tab" .. unique_string .. "_content_" .. dyntab.name,
   172           content = function()
   173             execute.view{
   174               module = dyntab.module,
   175               view   = dyntab.view,
   176               id     = dyntab.id,
   177               params = dyntab.params,
   178             }
   179           end
   180         }
   181       end
   182     end
   183   end
   185 else -- 'classic tab'
   187   function ui.tabs(tabs)
   188     ui.container{
   189       attr = { class = "ui_tabs" },
   190       content = function()
   191         local params = param.get_all_cgi()
   192         local current_tab = params["tab"]
   193         ui.container{
   194           attr = { class = "ui_tabs_links" },
   195           content = function()
   196             for i, tab in ipairs(tabs) do
   197               params["tab"] = i > 1 and tab.name or nil
   198               ui.link{
   199                 attr = { 
   200                   class = (
   201                     tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or
   202                     not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or
   203                     "" .. (tab.class and (" " .. tab.class) or "")
   204                   )
   205                 },
   206                 module  = request.get_module(),
   207                 view    = request.get_view(),
   208                 id      = param.get_id_cgi(),
   209                 content = tab.label,
   210                 params  = params
   211               }
   212               slot.put(" ")
   213             end
   214           end
   215         }
   216         for i, tab in ipairs(tabs) do
   217           if tab.name == current_tab or not current_tab and i == 1 then
   218             ui.container{
   219               attr = { class = "ui_tabs_content" },
   220               content = function()
   221                 if tab.content then
   222                   tab.content()
   223                 else
   224                   execute.view{
   225                     module = tab.module,
   226                     view   = tab.view,
   227                     id     = tab.id,
   228                     params = tab.params,
   229                   }
   230                 end
   231               end
   232             }
   233           end
   234         end
   235       end
   236     }
   237   end
   239 end
