-- |
-- Module:     Yesod.TableView.Widget
-- Copyright:  (c) 2010 Ertugrul Soeylemez
-- License:    BSD3
-- Maintainer: Ertugrul Soeylemez <es@ertes.de>
-- Stability:  experimental
--
-- Class for datatypes displayable in a table view as widgets.

{-# LANGUAGE TypeFamilies #-}

module Yesod.TableView.Widget
    ( -- * Table view widgets.
      TableViewWidget(..),

      -- * Convenient type aliases
      GTableHandler,
      GTableWidget,
      TableHandler,
      TableWidget
    )
    where

import Yesod


-- | This class defines how types will be rendered in the table view.

class TableViewWidget val where
    -- | Site associated with this table view widget.
    type TableSite val

    -- | Subsite associated with this table view widget.
    type TableSubsite val

    -- | Table header (wrapped in a @thead@ element).  This function
    -- will be called once per table.
    tableHeader :: val -> TableWidget val ()

    -- | Table row.  This function will be called once for each entry in
    -- the table.  All rows will be rendered inside of a @tbody@
    -- element.
    tableRecord :: Int -> Key val -> val -> TableWidget val ()


type GTableHandler val = GGHandler (TableSubsite val) (TableSite val)
type GTableWidget val = GGWidget (TableSubsite val) (TableSite val)
type TableHandler val = GHandler (TableSubsite val) (TableSite val)
type TableWidget val = GWidget (TableSubsite val) (TableSite val)