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