comparison remotePager.urs @ 16:2e397d373289

Add RemotePager.
author Karn Kallio <kkallio@eka>
date Thu, 18 Aug 2011 12:53:17 -0430
parents
children 4362b15220e4
comparison
equal deleted inserted replaced
15:8300d5f0dc19 16:2e397d373289
1 (* How to format the control section. *)
2 type formatCtl = {Width : int,
3 (* Maximum number of page options to show. *)
4 RangeCtl : $(mapU (transaction {} -> xbody) [First, Back, Next, Last]),
5 (* A group of four functions taking transactions which will be used to return
6 * an element having that transaction as onclick. Used to format the buttons
7 * controlling the selection of page options. First starts the options at the
8 * first page, Back starts the options one page lower, Next one page higher
9 * and Last has them finish at the final page. *)
10 PageCtl : $(mapU (int -> transaction {} -> xbody) [Unsel, Sel]),
11 (* Used to generate the xml bearing the page selection onclick action. Sel
12 * is used for the currently shown page and Unsel for the others. *)
13 WrapPageCtl : xbody -> xbody,
14 (* The sequence of page selection controls will be wrapped by this. *)
15 Wrap : $(mapU xbody [First, Back, Pages, Next, Last]) -> xbody
16 (* Draws the control by placing the individual controls in the holes. *)}
17
18 style firstCtl
19 style backCtl
20 style nextCtl
21 style lastCtl
22 style curPage
23 style rangeCtl
24 (* Default styles. *)
25
26 val defaultFormat : formatCtl
27 (* A reasonable default format. *)
28
29 val defaultFormatLbl : $(mapU string [First, Back, Next, Last]) -> formatCtl
30 (* A default format with configurable labels on the page range controls. *)
31
32 type pageData = {Content : xbody, Available : int}
33 (* Content and page count needed from the RPC. *)
34
35 datatype response err = Good of pageData | Bad of err
36 (* The RPC gives us either page information or an error code. *)
37
38 functor Make(M : sig
39 type errorMarker
40 (* Classifies the possible error conditions returned by the rpc call. *)
41
42 type pageGroup
43 (* Classifies families of pages. *)
44
45 val initPage : pageGroup -> transaction pageData
46 (* Used once to initialize the first page and page count.
47 * The RPC mechanism is not used and no error is possible. *)
48
49 val getPage : pageGroup -> int -> transaction (response errorMarker)
50 (* RPC giving the content of a requested page as well as the count
51 * of how many pages are available. The first page should be given
52 * an index of 0. *)
53 end) : sig
54
55 type t
56 (* The type of remote pagers. A remote pager is a
57 * widget which shows a list of available "pages" of
58 * information. The user can click on a page they want
59 * displayed, which is then fetched from the server via
60 * a RPC. *)
61
62 val createFmt : formatCtl -> M.pageGroup -> transaction t
63 (* Get a remote pager widget with a custom format showing pages from the selected group. *)
64
65 val create : M.pageGroup -> transaction t
66 (* Get a remote pager widget with the default format (partly customizable via CSS). *)
67
68 val onError : t -> (M.errorMarker -> transaction {}) -> transaction {}
69 (* Allows setting an error handler. In case of an rpc error code return, this will
70 * be called with the received error marker. If not set, the default error handler
71 * does nothing. *)
72
73 val panelXml : t -> xbody
74 (* Returns a piece of xml holding the contents of the current page. *)
75
76 val ctlXml : t -> xbody
77 (* Returns a xml widget representing the clickable page selection controls. *)
78 end