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