annotate remotePager.urs @ 18:16447dc6a68c

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