Commit 0fa08cdc98b813be559cd37fed46ca65c2ade216

Authored by David RENÉ
1 parent dad598c9

add management of pager

Showing 1 changed file with 64 additions and 0 deletions   Show diff stats
web/widgets/pager.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 03/02/2019
  5 + * Time: 19:32
  6 + * © David RENÉ
  7 + */
  8 +
  9 +read calexium_lib/web/CXM_making_a_web_site.anubis
  10 +read calexium_lib/web/CXM_web_session.anubis
  11 +
  12 +public define HTML_Partial_Content
  13 + control_panel_pager
  14 + (
  15 + String pager_id,
  16 + String previous,
  17 + String next
  18 + )
  19 + =
  20 + partial_content([js(js_file("js/cxm/cxm_pager.js"))],
  21 + div(id(pager_id), [
  22 + text(class("o_pager_current_page"),"0"),
  23 + text("/"),
  24 + text(class("o_pager_total_page"),"0"),
  25 + text(" "),
  26 + text(class("o_pager_total_items"),"0"),
  27 + span(class("btn-group btn-group-sm"), [
  28 + button([class("fa fa-chevron-left btn btn-icon o_pager_previous"), attr("type","button"), accesskey('p'), event(onclick, previous)]),
  29 + button([class("fa fa-chevron-right btn btn-icon o_pager_next"), attr("type","button"), accesskey('n'), event(onclick, next)])
  30 + ])
  31 + ]))
  32 +.
  33 +
  34 +public define HTML_Head_Tag
  35 + update_pager_script
  36 + (
  37 + String pager_id,
  38 + Int current_page,
  39 + Int total_pages,
  40 + Int total_items
  41 + )=
  42 + js_script("update_pager('"+pager_id+"', "+current_page+", "+total_pages+", "+total_items+");")
  43 +.
  44 +
  45 +public define One
  46 + get_current_page
  47 + (
  48 + WEB_Session _session
  49 + )=
  50 + with lwa = *_session.web_request.lwa,
  51 + //check if we clicked on next or previous pager
  52 + next_page = get_Bool(lwa, "next_page", false),
  53 + previous_page = get_Bool(lwa, "previous_page", false),
  54 +
  55 + //get the current page stored in session
  56 + _page = get_Int(_session.fields, "pager_current_page", 1),
  57 +
  58 + //if clicked on pager change page number else set to 1 (means change on query or tag. In that case reset the page)
  59 + current_page = if next_page then _page+1 else if previous_page then _page-1 else 1,
  60 +
  61 + //store current page in web session for the next call
  62 + replace_Int(_session.fields, "pager_current_page", current_page)
  63 +.
  64 +
... ...