kkallio@16: (* How to format the control section. *) kkallio@16: type formatCtl = {Width : int, kkallio@16: (* Maximum number of page options to show. *) kkallio@16: RangeCtl : $(mapU (transaction {} -> xbody) [First, Back, Next, Last]), kkallio@16: (* A group of four functions taking transactions which will be used to return kkallio@16: * an element having that transaction as onclick. Used to format the buttons kkallio@16: * controlling the selection of page options. First starts the options at the kkallio@16: * first page, Back starts the options one page lower, Next one page higher kkallio@16: * and Last has them finish at the final page. *) kkallio@16: PageCtl : $(mapU (int -> transaction {} -> xbody) [Unsel, Sel]), kkallio@16: (* Used to generate the xml bearing the page selection onclick action. Sel kkallio@16: * is used for the currently shown page and Unsel for the others. *) kkallio@16: WrapPageCtl : xbody -> xbody, kkallio@16: (* The sequence of page selection controls will be wrapped by this. *) kkallio@16: Wrap : $(mapU xbody [First, Back, Pages, Next, Last]) -> xbody kkallio@16: (* Draws the control by placing the individual controls in the holes. *)} kkallio@16: kkallio@16: style firstCtl kkallio@16: style backCtl kkallio@16: style nextCtl kkallio@16: style lastCtl kkallio@16: style curPage kkallio@16: style rangeCtl kkallio@16: (* Default styles. *) kkallio@16: kkallio@16: val defaultFormat : formatCtl kkallio@16: (* A reasonable default format. *) kkallio@16: kkallio@16: val defaultFormatLbl : $(mapU string [First, Back, Next, Last]) -> formatCtl kkallio@16: (* A default format with configurable labels on the page range controls. *) kkallio@16: kkallio@16: type pageData = {Content : xbody, Available : int} kkallio@16: (* Content and page count needed from the RPC. *) kkallio@16: kkallio@16: datatype response err = Good of pageData | Bad of err kkallio@16: (* The RPC gives us either page information or an error code. *) kkallio@16: kkallio@16: functor Make(M : sig kkallio@16: type errorMarker kkallio@22: (* Classifies the possible error conditions returned by the rpc. *) kkallio@16: kkallio@16: type pageGroup kkallio@16: (* Classifies families of pages. *) kkallio@16: kkallio@16: val initPage : pageGroup -> transaction pageData kkallio@16: (* Used once to initialize the first page and page count. kkallio@16: * The RPC mechanism is not used and no error is possible. *) kkallio@16: kkallio@16: val getPage : pageGroup -> int -> transaction (response errorMarker) kkallio@16: (* RPC giving the content of a requested page as well as the count kkallio@16: * of how many pages are available. The first page should be given kkallio@16: * an index of 0. *) kkallio@16: end) : sig kkallio@16: kkallio@16: type t kkallio@16: (* The type of remote pagers. A remote pager is a kkallio@16: * widget which shows a list of available "pages" of kkallio@16: * information. The user can click on a page they want kkallio@16: * displayed, which is then fetched from the server via kkallio@16: * a RPC. *) kkallio@16: kkallio@16: val createFmt : formatCtl -> M.pageGroup -> transaction t kkallio@16: (* Get a remote pager widget with a custom format showing pages from the selected group. *) kkallio@16: kkallio@16: val create : M.pageGroup -> transaction t kkallio@16: (* Get a remote pager widget with the default format (partly customizable via CSS). *) kkallio@16: kkallio@16: val onError : t -> (M.errorMarker -> transaction {}) -> transaction {} kkallio@16: (* Allows setting an error handler. In case of an rpc error code return, this will kkallio@16: * be called with the received error marker. If not set, the default error handler kkallio@16: * does nothing. *) kkallio@16: kkallio@16: val panelXml : t -> xbody kkallio@16: (* Returns a piece of xml holding the contents of the current page. *) kkallio@16: kkallio@16: val ctlXml : t -> xbody kkallio@16: (* Returns a xml widget representing the clickable page selection controls. *) kkallio@16: end