{-# LANGUAGE FlexibleContexts, TypeFamilies #-} {-# OPTIONS_GHC -F -pgmFtrhsx #-} module Pages.Board where import ConfigT import Control.Applicative import Control.Applicative.Error import Control.Monad import Control.Monad.Trans import Data.Text (Text) import qualified Data.Text as Text import Data.Time import Data.Acid hiding (update, query) import Data.Maybe (fromMaybe, mapMaybe) import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy.Char8 as C import Data.List import Happstack.Data.IxSet ((@=)) import qualified Happstack.Data.IxSet as IxSet import Happstack.Server import HJScript.DOM (Node, alert, document, window) import HJScript.Utils () import HJScript hiding ((<|>)) import HJScript.Objects.JQuery hiding (submit) import HSP import qualified HSX.XMLGenerator as HSX import Pages.AppTemplate import Server import State import System.Locale import Text.Formlets (Form, File(fileName, content), Rect(..), check, checkM, plug, xml) import HSP.Formlets (checkboxes, input, label, submit, file, password, submit, textarea) import Happstack.Server.Formlets (formletPart, handleFailure) import Types import URL import Web.Routes boardPage :: WebURL -> BoardName -> (Maybe Int) -> Server Response boardPage here boardName mPage = do res <- query (GetThreads (fromMaybe 0 mPage) boardName) case res of (Left e) -> error (show e) (Right (threads, maxPageNum)) -> do let media = mapMaybe medium (concatMap posts threads) mediaJS <- imageToggles media let script = embedScript (ready' mediaJS) toResponse <$> (unXMLGenT $ boardTemplate here (Right (boardName, maxPageNum)) (Text.unpack (unBoardName boardName)) script <% mapM threadHTML threads %>) boardTemplate :: ( EmbedAsChild Server headers , EmbedAsChild Server body ) => WebURL -> (Either ThreadId (BoardName, Int)) -> String -- ^ title -> headers -- ^ extra tags to include in \
-> body -- ^ contents to put inside \ -> XMLGenT Server XML boardTemplate here@(W_Board _ mPage) postType title headers body = do config <- askConfig login <- case role config of User -> do loginURL <- showURL (W_Login here) login Moderator -> do moderatorURL <- showURL W_Moderator moderator Admin -> do adminURL <- showURL W_Admin admin hereURL <- showURL here bds <- query AskBoards appTemplate title headersGoto page:
The thread you are trying to reply to does not exist.
(Right post) -> do seeOtherURL here handleFailure' errs frmXML = handleFailure (\t b -> appTemplate t () b) errs frmXML validateNewThread :: (MonadIO m) => Config -> (String, String, String, File, String) -> m (Failing (Maybe Text, Maybe String, Maybe Text, Maybe Medium, Text)) validateNewThread config (name, tripCode, subject, file, msg) = if (B.null (content file) || null msg) then return $ Failure ["You must supply and image and a comment to start a new thread."] else do medium <- saveImage (acid config) (storageDir config) (fileName file) (C.unpack $ content file) return $ Success $ (maybeText name, maybeString tripCode, maybeText subject, Just medium, Text.pack msg) where maybeString :: String -> Maybe String maybeString [] = Nothing maybeString str = Just str maybeText :: String -> Maybe Text maybeText = fmap Text.pack . maybeString threadHTML :: (XMLGenerator m, ShowURL m, URL m ~ WebURL, EmbedAsChild m ()) => Thread -> XMLGenT m (HSX.XML m) threadHTML thread = do replyURL <- showURL (W_Reply (threadId thread))Odd. This thread does not contain any posts.
(h:t) ->[ Reply ]
<% maybe "Anonymous" Text.unpack (poster post) %> <% maybe "" Text.unpack (subject post) %> <% formatTime defaultTimeLocale rfc822DateFormat (posted post) %> No.<% show $ unPostId $ postId post %>
<% case medium post of Nothing -> <% () %> (Just medium) -> <%<% Text.unpack (msg post) %>