webmcp
changeset 568:c43f251262d8
More layout options for ui.paginate{...} and removed doc of non-implemented option
author | jbe |
---|---|
date | Wed Oct 13 16:48:34 2021 +0200 (2021-10-13) |
parents | 5e3ebe9fd0ce |
children | 5b19007574de |
files | framework/env/ui/paginate.lua |
line diff
1.1 --- a/framework/env/ui/paginate.lua Wed Apr 28 13:07:52 2021 +0200 1.2 +++ b/framework/env/ui/paginate.lua Wed Oct 13 16:48:34 2021 +0200 1.3 @@ -4,8 +4,9 @@ 1.4 anchor = anchor, -- optional name of anchor in document to jump to 1.5 per_page = per_page, -- items per page, defaults to 10 1.6 container_attr = container_attr, -- html attr for the container element 1.7 + link_attr = link_attr, -- html attr for each page link 1.8 name = name, -- name of the CGI get variable, defaults to "page" 1.9 - page = page, -- directly specify a page, and ignore 'name' parameter 1.10 + position = position, -- position of page links relative to content: "before", "after", or "both" (default) 1.11 content = function() 1.12 ... -- code block which should be encapsulated with page selection links 1.13 end 1.14 @@ -16,10 +17,14 @@ 1.15 --]]-- 1.16 1.17 function ui.paginate(args) 1.18 - local selector = args.selector 1.19 - local per_page = args.per_page or 10 1.20 - local name = args.name or 'page' 1.21 - local content = args.content 1.22 + local selector = args.selector 1.23 + local anchor = args.anchor 1.24 + local per_page = args.per_page or 10 1.25 + local container_attr = args.container_attr or { class = 'ui_paginate' } 1.26 + local link_attr = args.link_attr or {} 1.27 + local name = args.name or 'page' 1.28 + local position = args.position or 'both' 1.29 + local content = args.content 1.30 local count_selector = selector:get_db_conn():new_selector() 1.31 count_selector:add_field('count(1)') 1.32 count_selector:add_from(selector) 1.33 @@ -44,9 +49,13 @@ 1.34 slot.put(" ") 1.35 end 1.36 params[name] = page 1.37 - local attr = {} 1.38 + local attr = table.new(link_attr) 1.39 if current_page == page then 1.40 - attr.class = "active" 1.41 + if attr.class then 1.42 + attr.class = attr.class .. " active" 1.43 + else 1.44 + attr.class = "active" 1.45 + end 1.46 end 1.47 ui.link{ 1.48 attr = attr, 1.49 @@ -54,27 +63,31 @@ 1.50 view = request.get_view(), 1.51 id = id, 1.52 params = params, 1.53 - anchor = args.anchor, 1.54 + anchor = anchor, 1.55 text = tostring(page) 1.56 } 1.57 end 1.58 end 1.59 end 1.60 ui.container{ 1.61 - attr = args.container_attr or { class = 'ui_paginate' }, 1.62 + attr = container_attr, 1.63 content = function() 1.64 - ui.container{ 1.65 - attr = { class = 'ui_paginate_head ui_paginate_select' }, 1.66 - content = pagination_elements 1.67 - } 1.68 + if position == 'before' or position == 'both' then 1.69 + ui.container{ 1.70 + attr = { class = 'ui_paginate_head ui_paginate_select' }, 1.71 + content = pagination_elements 1.72 + } 1.73 + end 1.74 ui.container{ 1.75 attr = { class = 'ui_paginate_content' }, 1.76 content = content 1.77 } 1.78 - ui.container{ 1.79 - attr = { class = 'ui_paginate_foot ui_paginate_select' }, 1.80 - content = pagination_elements 1.81 - } 1.82 + if position == 'after' or position == 'both' then 1.83 + ui.container{ 1.84 + attr = { class = 'ui_paginate_foot ui_paginate_select' }, 1.85 + content = pagination_elements 1.86 + } 1.87 + end 1.88 end 1.89 } 1.90 end