Safe Haskell | None |
---|
There are two components to the Alerts
module.
- Heist splices for rendering the alerts
- Alert redirection helpers which pass the alert type and message via the HTTP GET query string.
First the Heist splices can be added with the addAlertSplices
function which takes the Heist Snaplet as an argument.
initApp :: SnapletInit App App initApp = makeSnaplet "app" "An snaplet example application." Nothing $ do h <- nestSnaplet "heist" heist $ heistInit "templates" addAlertSplices h return $ App h
Second, generate an alert in a handler.
import Snap.Utils.Alert (alertSuccess) actionSuccess :: Handler App App () actionSuccess reg = alertSuccess msg url where msg = "Successfully completed an action!" url = "/"
Third, ensure the Heist template has a place to bind alerts.
<alerts> <div class="alerts"> <div class="fade in alert alert-${alert-type} alert-dismissable"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><alert-text/></strong> </div> </div> </alerts>
Snap.Utils.Alert
is different from similar modules because it relies
on more traditional HTTP-based methods of stateless control flow like
GET queries instead of relying on cookies and server state
continuations. Snap.Extras.FlashNotice,
for example, uses cookies to store alert state.
- data AlertType
- addAlertSplices :: HasHeist b => Snaplet (Heist b) -> Initializer b v ()
- alertRedirect :: MonadSnap m => AlertType -> Text -> URL -> m a
- alertRedirect' :: MonadSnap m => AlertType -> Text -> URL -> SimpleQuery -> m a
- alertSuccess :: MonadSnap m => Text -> URL -> m a
- alertInfo :: MonadSnap m => Text -> URL -> m a
- alertWarning :: MonadSnap m => Text -> URL -> m a
- alertDanger :: MonadSnap m => Text -> URL -> m a
- alertUrl :: AlertType -> Text -> URL -> SimpleQuery -> URL
Documentation
addAlertSplices :: HasHeist b => Snaplet (Heist b) -> Initializer b v ()Source
Add the compiled and interpreted alert splices to the
<alerts>
tag with nested tags of <alert-text>
and
<alert-type>
which will be bound to an AlertType
.
alertRedirect :: MonadSnap m => AlertType -> Text -> URL -> m aSource
302 redirect to the target page URL with the specified
AlertType
and message.
alertRedirect' :: MonadSnap m => AlertType -> Text -> URL -> SimpleQuery -> m aSource
Same as alertRedirect
but accepts additional query parameters.
alertSuccess :: MonadSnap m => Text -> URL -> m aSource
alertRedirect
with Success
alertWarning :: MonadSnap m => Text -> URL -> m aSource
alertRedirect
with Warning
alertDanger :: MonadSnap m => Text -> URL -> m aSource
alertRedirect
with Danger
alertUrl :: AlertType -> Text -> URL -> SimpleQuery -> URLSource
Generate a URL with an alert query string without redirecting to the URL.