{-# LANGUAGE EmptyDataDecls, FlexibleContexts, FlexibleInstances, GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverlappingInstances, PackageImports, RankNTypes, ScopedTypeVariables, TypeSynonymInstances, UndecidableInstances, TypeFamilies #-} {-# OPTIONS -F -pgmFtrhsx -Wwarn -fno-warn-orphans -fno-warn-name-shadowing -fno-warn-unused-matches #-} module Scaffolding.HSP.Widget where import Control.Applicative ((<$>)) import Control.Monad ({-liftM-}) import Control.Monad.RWS (RWS, runRWS, mapRWS) import Control.Monad.State (MonadState (get, put)) import Control.Monad.Writer (tell) import "mtl" Control.Monad.Identity (Identity) import Data.Maybe (fromMaybe) --import Data.Maybe (fromMaybe) import Data.Text (Text) import HSP.Identity import HSP hiding (onClick) import HJScript -- (Array(Array), Args, Exp(..), HJScript, IsClass, JBool, JObject, JString, JType, ( # ), call, callProc, callMethod, callVoidMethod, evalHJScript, false, function, functionDecl, inVar, new, push, string, this) import HJScript.DOM ({-alert, document, window-}) import HJScript.DOM hiding (Object, Form) --import HJScript.Lang (doIf) import HJScript.Objects.JQuery (JQuery, append, jSetText, jVal, selectExpr, runExp) import qualified HSX.XMLGenerator as HSX import Happstack.Server (ServerPartT) import HSP.ServerPartT () import HSP.Identity ({-evalIdentity-}) import Scaffolding.HJScriptExtra import Scaffolding.MonadStack.Headers (MonadHeaders, tellHeaders) import Text.JSON (JSON, Result(Ok, Error), decode {-, encode-}) import Text.Digestive (Form, transform, transformEither, mapView) import Text.Digestive.Forms (FormInput, inputString) class (XMLGenerator x, HSX.XMLGen x, HSX.SetAttr x (HSX.XML x), HSX.AppendChild x (HSX.XML x), HSX.EmbedAsChild x String, HSX.EmbedAsChild x Text, HSX.EmbedAsChild x Char, HSX.EmbedAsAttr x (HSX.Attr String String), HSX.EmbedAsAttr x (HSX.Attr String Int), HSX.EmbedAsAttr x (HSX.Attr String Bool), HSX.EmbedAsChild x XML, MonadHeaders IO x, EmbedAsAttr x (Attr String Text), Widgets x) => WidgetGenerator x -- this is pretty wacky flattenForm :: (Functor m, Monad m, MonadHeaders IO x) => Form m i e ([HJScript ()], [XMLGenT x (HSX.XML x)]) a -> Form m i e [XMLGenT x (HSX.XML x)] a flattenForm = mapView $ \(js, h:hs) -> (tellHeaders [onReadyXML' js] >> h) : hs {- We currently do not use any output/input queues. Events are sent one at a time and processed immediately. However, this can cause events to get lost. For example, if a widget sends events as part of initialization, the listener may not be connected yet and those events will be lost. We could instead have a queue that holds the events until someone listens. Then we run the problem of a space leak if no one ever listens. Really Quick Summary: A widget is a bundle of HTML and javascript code. The html is rendered in-place. The javascript code is added to the $(document).onready() -- | helper function which turns javascript into a