annotate env/ui/tabs.lua @ 664:a846889adc37
Added tag v2.beta12 for changeset 2fe57fa90c7a
 | author | 
 bsw | 
 | date | 
 Tue Jun 26 15:18:46 2012 +0200 (2012-06-26) | 
 | parents | 
 44f9a09ea51c  | 
 | children | 
 904f6807f7fa  | 
 
 | rev | 
   line source | 
| 
bsw@278
 | 
     1 function ui.tabs(tabs)
 | 
| 
bsw@286
 | 
     2   local attr = tabs.attr or {}
 | 
| 
bsw@286
 | 
     3   attr.class = (attr.class and attr.class .. " " or "") .. "ui_tabs"
 | 
| 
bsw@278
 | 
     4   ui.container{
 | 
| 
bsw@286
 | 
     5     attr = attr,
 | 
| 
bsw@278
 | 
     6     content = function()
 | 
| 
bsw/jbe@0
 | 
     7       local params = param.get_all_cgi()
 | 
| 
bsw@278
 | 
     8       local current_tab = params["tab"]
 | 
| 
bsw@278
 | 
     9       ui.container{
 | 
| 
bsw@278
 | 
    10         attr = { class = "ui_tabs_links" },
 | 
| 
bsw/jbe@0
 | 
    11         content = function()
 | 
| 
bsw@278
 | 
    12           for i, tab in ipairs(tabs) do
 | 
| 
bsw@292
 | 
    13             local params = param.get_all_cgi()
 | 
| 
bsw@292
 | 
    14             if tab.link_params then
 | 
| 
bsw@292
 | 
    15               for key, value in pairs(tab.link_params) do
 | 
| 
bsw@292
 | 
    16                 params[key] = value
 | 
| 
bsw@292
 | 
    17               end
 | 
| 
bsw@292
 | 
    18             end
 | 
| 
bsw@278
 | 
    19             params["tab"] = i > 1 and tab.name or nil
 | 
| 
bsw@278
 | 
    20             ui.link{
 | 
| 
bsw@278
 | 
    21               attr = { 
 | 
| 
bsw@278
 | 
    22                 class = (
 | 
| 
bsw@278
 | 
    23                   tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or
 | 
| 
bsw@278
 | 
    24                   not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or
 | 
| 
bsw@278
 | 
    25                   "" .. (tab.class and (" " .. tab.class) or "")
 | 
| 
bsw@278
 | 
    26                 )
 | 
| 
bsw@278
 | 
    27               },
 | 
| 
bsw@278
 | 
    28               module  = request.get_module(),
 | 
| 
bsw@278
 | 
    29               view    = request.get_view(),
 | 
| 
bsw@278
 | 
    30               id      = param.get_id_cgi(),
 | 
| 
bsw@278
 | 
    31               content = tab.label,
 | 
| 
bsw@278
 | 
    32               params  = params
 | 
| 
bsw/jbe@0
 | 
    33             }
 | 
| 
bsw@278
 | 
    34             slot.put(" ")
 | 
| 
bsw/jbe@0
 | 
    35           end
 | 
| 
bsw/jbe@0
 | 
    36         end
 | 
| 
bsw/jbe@0
 | 
    37       }
 | 
| 
bsw@278
 | 
    38       for i, tab in ipairs(tabs) do
 | 
| 
bsw@278
 | 
    39         if tab.name == current_tab and i > 1 then
 | 
| 
bsw@278
 | 
    40                                               app.html_title.prefix = tab.label
 | 
| 
bsw/jbe@19
 | 
    41               end
 | 
| 
bsw@278
 | 
    42         if tab.name == current_tab or not current_tab and i == 1 then
 | 
| 
bsw@278
 | 
    43           ui.container{
 | 
| 
bsw@278
 | 
    44             attr = { class = "ui_tabs_content" },
 | 
| 
bsw@278
 | 
    45             content = function()
 | 
| 
bsw@278
 | 
    46               if tab.content then
 | 
| 
bsw@278
 | 
    47                 tab.content()
 | 
| 
bsw@278
 | 
    48               else
 | 
| 
bsw@278
 | 
    49                 execute.view{
 | 
| 
bsw@278
 | 
    50                   module = tab.module,
 | 
| 
bsw@278
 | 
    51                   view   = tab.view,
 | 
| 
bsw@278
 | 
    52                   id     = tab.id,
 | 
| 
bsw@278
 | 
    53                   params = tab.params,
 | 
| 
bsw@278
 | 
    54                 }
 | 
| 
bsw@278
 | 
    55               end
 | 
| 
bsw@278
 | 
    56             end
 | 
| 
bsw@278
 | 
    57           }
 | 
| 
bsw/jbe@19
 | 
    58         end
 | 
| 
bsw/jbe@19
 | 
    59       end
 | 
| 
bsw/jbe@0
 | 
    60     end
 | 
| 
bsw@278
 | 
    61   }
 | 
| 
jorges@102
 | 
    62 end
 |