# HG changeset patch # User jbe # Date 1634136514 -7200 # Node ID c43f251262d87427447e900e2fd6ad16884ff559 # Parent 5e3ebe9fd0ce4880c8a4827fda74b2f619bbb12c More layout options for ui.paginate{...} and removed doc of non-implemented option diff -r 5e3ebe9fd0ce -r c43f251262d8 framework/env/ui/paginate.lua --- a/framework/env/ui/paginate.lua Wed Apr 28 13:07:52 2021 +0200 +++ b/framework/env/ui/paginate.lua Wed Oct 13 16:48:34 2021 +0200 @@ -4,8 +4,9 @@ anchor = anchor, -- optional name of anchor in document to jump to per_page = per_page, -- items per page, defaults to 10 container_attr = container_attr, -- html attr for the container element + link_attr = link_attr, -- html attr for each page link name = name, -- name of the CGI get variable, defaults to "page" - page = page, -- directly specify a page, and ignore 'name' parameter + position = position, -- position of page links relative to content: "before", "after", or "both" (default) content = function() ... -- code block which should be encapsulated with page selection links end @@ -16,10 +17,14 @@ --]]-- function ui.paginate(args) - local selector = args.selector - local per_page = args.per_page or 10 - local name = args.name or 'page' - local content = args.content + local selector = args.selector + local anchor = args.anchor + local per_page = args.per_page or 10 + local container_attr = args.container_attr or { class = 'ui_paginate' } + local link_attr = args.link_attr or {} + local name = args.name or 'page' + local position = args.position or 'both' + local content = args.content local count_selector = selector:get_db_conn():new_selector() count_selector:add_field('count(1)') count_selector:add_from(selector) @@ -44,9 +49,13 @@ slot.put(" ") end params[name] = page - local attr = {} + local attr = table.new(link_attr) if current_page == page then - attr.class = "active" + if attr.class then + attr.class = attr.class .. " active" + else + attr.class = "active" + end end ui.link{ attr = attr, @@ -54,27 +63,31 @@ view = request.get_view(), id = id, params = params, - anchor = args.anchor, + anchor = anchor, text = tostring(page) } end end end ui.container{ - attr = args.container_attr or { class = 'ui_paginate' }, + attr = container_attr, content = function() - ui.container{ - attr = { class = 'ui_paginate_head ui_paginate_select' }, - content = pagination_elements - } + if position == 'before' or position == 'both' then + ui.container{ + attr = { class = 'ui_paginate_head ui_paginate_select' }, + content = pagination_elements + } + end ui.container{ attr = { class = 'ui_paginate_content' }, content = content } - ui.container{ - attr = { class = 'ui_paginate_foot ui_paginate_select' }, - content = pagination_elements - } + if position == 'after' or position == 'both' then + ui.container{ + attr = { class = 'ui_paginate_foot ui_paginate_select' }, + content = pagination_elements + } + end end } end