1 | unit UHTMLControls;
|
---|
2 |
|
---|
3 | {$mode Delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UHTTPServer;
|
---|
9 |
|
---|
10 | type
|
---|
11 | { TPageList }
|
---|
12 |
|
---|
13 | TPageList = class
|
---|
14 | NavigatorVisibleItems: Integer;
|
---|
15 | PageIndexName: string;
|
---|
16 | Page: Integer;
|
---|
17 | TotalCount: Integer;
|
---|
18 | ItemPerPage: Integer;
|
---|
19 | Output: string;
|
---|
20 | HandlerData: THTTPHandlerData;
|
---|
21 | function SQLLimit: string;
|
---|
22 | procedure Process;
|
---|
23 | constructor Create;
|
---|
24 | destructor Destroy; override;
|
---|
25 | end;
|
---|
26 |
|
---|
27 | implementation
|
---|
28 |
|
---|
29 | { TPageList }
|
---|
30 |
|
---|
31 | function TPageList.SQLLimit: string;
|
---|
32 | begin
|
---|
33 | Result := ' LIMIT ' + IntToStr(Page * ItemPerPage) + ', ' + IntToStr(ItemPerPage);
|
---|
34 | end;
|
---|
35 |
|
---|
36 | procedure TPageList.Process;
|
---|
37 | var
|
---|
38 | Count: Integer;
|
---|
39 | PagesMax: Integer;
|
---|
40 | PagesMin: Integer;
|
---|
41 | I: Integer;
|
---|
42 | begin
|
---|
43 | if Assigned(HandlerData) and
|
---|
44 | (HandlerData.Session.IndexOfName(PageIndexName) <> -1) then
|
---|
45 | Page := StrToInt(HandlerData.Session.Values[PageIndexName])
|
---|
46 | else Page := 0;
|
---|
47 | if HandlerData.Request.Query.IndexOfName(PageIndexName) <> -1 then
|
---|
48 | Page := StrToInt(HandlerData.Request.Query.Values[PageIndexName]);
|
---|
49 |
|
---|
50 | Count := Trunc(TotalCount / ItemPerPage) + 1;
|
---|
51 | if Page > Count - 1 then Page := Count - 1;
|
---|
52 |
|
---|
53 | Output := '';
|
---|
54 | if Count > 1 then
|
---|
55 | with HandlerData, Request do begin
|
---|
56 |
|
---|
57 | if Page > 0 then begin
|
---|
58 | Query.Values[PageIndexName] := IntToStr(0);
|
---|
59 | Output := Output + '<a href="?' + Query.Syntetize + '"><<</a>';
|
---|
60 | Query.Values[PageIndexName] := IntToStr(Page - 1);
|
---|
61 | Output := Output + ' <a href="?' + Query.Syntetize + '"><</a>';
|
---|
62 | end;
|
---|
63 |
|
---|
64 | // Get navigator visible range
|
---|
65 | PagesMin := Page - (NavigatorVisibleItems - 1) div 2;
|
---|
66 | if PagesMin < 0 then PagesMin := 0;
|
---|
67 | PagesMax := PagesMin + (NavigatorVisibleItems - 1);
|
---|
68 | if PagesMax > Count - 1 then PagesMax := Count - 1;
|
---|
69 |
|
---|
70 | if PagesMin > 0 then Output := Output + ' .. ';
|
---|
71 | // Show page numbers
|
---|
72 | for I := PagesMin to PagesMax do begin
|
---|
73 | Query.Values[PageIndexName] := IntToStr(I);
|
---|
74 | if I = Page then begin
|
---|
75 | Output := Output + ' <strong>' + IntToStr(I + 1) + '</strong>'
|
---|
76 | end else begin
|
---|
77 | Output := Output + ' <a href="?' + Query.Syntetize + '">' +
|
---|
78 | IntToStr(I + 1) + '</a>';
|
---|
79 | end;
|
---|
80 | end;
|
---|
81 | if PagesMax < (Count - 1) then Output := Output + ' .. ';
|
---|
82 |
|
---|
83 | if Page < (Count - 1) then begin
|
---|
84 | Query.Values[PageIndexName] := IntToStr(Page + 1);
|
---|
85 | Output := Output + ' <a href="?' + Query.Syntetize + '">></a>';
|
---|
86 | Query.Values[PageIndexName] := IntToStr(Count - 1);
|
---|
87 | Output := Output + ' <a href="?' + Query.Syntetize + '">>></a>';
|
---|
88 | end;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | HandlerData.Session.Values[PageIndexName] := IntToStr(Page);
|
---|
92 | end;
|
---|
93 |
|
---|
94 | constructor TPageList.Create;
|
---|
95 | begin
|
---|
96 | PageIndexName := 'Page';
|
---|
97 | ItemPerPage := 40;
|
---|
98 | NavigatorVisibleItems := 30;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | destructor TPageList.Destroy;
|
---|
102 | begin
|
---|
103 | inherited Destroy;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | end.
|
---|
107 |
|
---|