module HtmlEdit (htmlEdit) where
import Network.SimpleCGI
import Text.XHtml
import PageTemplate
import Session
import Blob
import Control.Monad
import Data.Maybe
doHtmlEdit :: Database -> Session -> CGI CGIResult
doHtmlEdit db sess =
do
e <- readInput "entryid"
t <- getInput "title"
d <- getInput "text"
case (e,t,d) of
(Just entryid, Just title, Just text) ->
do
eid <- io (modifyEntry db entryid (sessionUser sess) title text)
funRedirect "view" [("entryid", show entryid)]
_ -> htmlEditPage db sess
htmlEditPage :: Database -> Session -> CGI CGIResult
htmlEditPage db sess =
do
mentryid <- readInput "entryid"
let entryid = fromJust mentryid -- FIXME
me <- io (getEntry db entryid)
let e = fromJust me -- FIXME
showPage (Just sess) "Edit entry"
(h1 << "Edit entry" +++ editForm e)
editForm :: Entry -> Html
editForm e =
blobForm << (hidden "entryid" (show (eid e)) +++ hidden "fun" "edit"
+++ formRow "Title" (textfield "title" ! [value (esubject e)])
+++ formRow "Content" (textarea ! [name "text",rows "10",cols "40"] << ebody e)
+++ formRow "" (submit "submit" "Submit"))
htmlEdit :: Database -> CGI CGIResult
htmlEdit db = withLogin db (doHtmlEdit db) (destVars >>= funRedirect "login")