2015-08-02 19:48:36 +00:00
|
|
|
From 1b24ece1a40c9365f719472ca6e342c8c4065c25 Mon Sep 17 00:00:00 2001
|
2014-10-16 04:31:59 +00:00
|
|
|
From: dummy <dummy@example.com>
|
2015-08-02 19:48:36 +00:00
|
|
|
Date: Thu, 16 Oct 2014 02:31:20 +0000
|
2014-10-16 04:31:59 +00:00
|
|
|
Subject: [PATCH] hack TH
|
2014-10-14 04:16:38 +00:00
|
|
|
|
|
|
|
---
|
2015-08-02 19:48:36 +00:00
|
|
|
Yesod/Form/Bootstrap3.hs | 186 +++++++++--
|
|
|
|
Yesod/Form/Fields.hs | 816 +++++++++++++++++++++++++++++++++++------------
|
|
|
|
Yesod/Form/Functions.hs | 257 ++++++++++++---
|
|
|
|
Yesod/Form/Jquery.hs | 134 ++++++--
|
2014-10-16 04:31:59 +00:00
|
|
|
Yesod/Form/MassInput.hs | 226 ++++++++++---
|
2015-08-02 19:48:36 +00:00
|
|
|
Yesod/Form/Nic.hs | 67 +++-
|
|
|
|
6 files changed, 1322 insertions(+), 364 deletions(-)
|
2014-10-14 04:16:38 +00:00
|
|
|
|
2014-09-13 02:35:36 +00:00
|
|
|
diff --git a/Yesod/Form/Bootstrap3.hs b/Yesod/Form/Bootstrap3.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index 84e85fc..1954fb4 100644
|
2014-09-13 02:35:36 +00:00
|
|
|
--- a/Yesod/Form/Bootstrap3.hs
|
|
|
|
+++ b/Yesod/Form/Bootstrap3.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -26,6 +26,9 @@ import Data.String (IsString(..))
|
2014-10-13 21:08:29 +00:00
|
|
|
import Yesod.Core
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
+import qualified Text.Hamlet
|
|
|
|
+import qualified Text.Blaze.Internal
|
|
|
|
+import qualified Data.Foldable
|
|
|
|
|
|
|
|
import Yesod.Form.Types
|
|
|
|
import Yesod.Form.Functions
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -152,44 +155,144 @@ renderBootstrap3 formLayout aform fragment = do
|
2014-09-13 02:35:36 +00:00
|
|
|
let views = views' []
|
|
|
|
has (Just _) = True
|
|
|
|
has Nothing = False
|
|
|
|
- widget = [whamlet|
|
|
|
|
- $newline never
|
|
|
|
- #{fragment}
|
|
|
|
- $forall view <- views
|
|
|
|
- <div .form-group :fvRequired view:.required :not $ fvRequired view:.optional :has $ fvErrors view:.has-error>
|
|
|
|
- $case formLayout
|
|
|
|
- $of BootstrapBasicForm
|
|
|
|
- $if fvId view /= bootstrapSubmitId
|
|
|
|
- <label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- ^{fvInput view}
|
|
|
|
- ^{helpWidget view}
|
|
|
|
- $of BootstrapInlineForm
|
|
|
|
- $if fvId view /= bootstrapSubmitId
|
|
|
|
- <label .sr-only for=#{fvId view}>#{fvLabel view}
|
|
|
|
- ^{fvInput view}
|
|
|
|
- ^{helpWidget view}
|
|
|
|
- $of BootstrapHorizontalForm labelOffset labelSize inputOffset inputSize
|
|
|
|
- $if fvId view /= bootstrapSubmitId
|
|
|
|
- <label .control-label .#{toOffset labelOffset} .#{toColumn labelSize} for=#{fvId view}>#{fvLabel view}
|
|
|
|
- <div .#{toOffset inputOffset} .#{toColumn inputSize}>
|
|
|
|
- ^{fvInput view}
|
|
|
|
- ^{helpWidget view}
|
|
|
|
- $else
|
|
|
|
- <div .#{toOffset (addGO inputOffset (addGO labelOffset labelSize))} .#{toColumn inputSize}>
|
|
|
|
- ^{fvInput view}
|
|
|
|
- ^{helpWidget view}
|
|
|
|
- |]
|
|
|
|
+ widget = do { (asWidgetT . toWidget) (toHtml fragment);
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ view_as0a
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<div class=\"form-group ");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_as0a,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_as0a),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "optional "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(has (fvErrors view_as0a),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "has-error"))]
|
|
|
|
+ Nothing;
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
|
|
|
+ case formLayout of {
|
|
|
|
+ ; BootstrapBasicForm
|
|
|
|
+ -> do { Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [((/=) (fvId view_as0a) bootstrapSubmitId,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<label for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "</label>") })]
|
|
|
|
+ Nothing;
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_as0a);
|
|
|
|
+ (asWidgetT . toWidget) (helpWidget view_as0a) }
|
2014-09-13 02:35:36 +00:00
|
|
|
+ ; BootstrapInlineForm
|
|
|
|
+ -> do { Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [((/=) (fvId view_as0a) bootstrapSubmitId,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<label class=\"sr-only\" for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "</label>") })]
|
|
|
|
+ Nothing;
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_as0a);
|
|
|
|
+ (asWidgetT . toWidget) (helpWidget view_as0a) }
|
|
|
|
+ ; BootstrapHorizontalForm labelOffset_as0b
|
|
|
|
+ labelSize_as0c
|
|
|
|
+ inputOffset_as0d
|
|
|
|
+ inputSize_as0e
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [((/=) (fvId view_as0a) bootstrapSubmitId,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<label class=\"control-label ");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (toOffset labelOffset_as0b));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) " ");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (toColumn labelSize_as0c));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\" for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_as0a));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "</label><div class=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (toOffset inputOffset_as0d));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) " ");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (toColumn inputSize_as0e));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_as0a);
|
|
|
|
+ (asWidgetT . toWidget) (helpWidget view_as0a);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "</div>") })]
|
|
|
|
+ (Just
|
|
|
|
+ (do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<div class=\"");
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ (toHtml
|
|
|
|
+ (toOffset
|
|
|
|
+ (addGO
|
2015-08-02 19:48:36 +00:00
|
|
|
+ inputOffset_as0d
|
|
|
|
+ (addGO labelOffset_as0b labelSize_as0c))));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) " ");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (toColumn inputSize_as0e));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_as0a);
|
|
|
|
+ (asWidgetT . toWidget) (helpWidget view_as0a);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "</div>") })) };
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "</div>") })
|
|
|
|
+ views }
|
|
|
|
+
|
|
|
|
return (res, widget)
|
|
|
|
|
|
|
|
|
|
|
|
-- | (Internal) Render a help widget for tooltips and errors.
|
|
|
|
helpWidget :: FieldView site -> WidgetT site IO ()
|
|
|
|
-helpWidget view = [whamlet|
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <span .help-block>#{tt}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <span .help-block>#{err}
|
|
|
|
-|]
|
|
|
|
+helpWidget view = do { Text.Hamlet.maybeH
|
|
|
|
+ (fvTooltip view)
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ tt_as0k
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<span class=\"help-block\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_as0k);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "</span>") })
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.maybeH
|
|
|
|
+ (fvErrors view)
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ err_as0l
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<span class=\"help-block\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_as0l);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "</span>") })
|
|
|
|
+ Nothing }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-- | How the 'bootstrapSubmit' button should be rendered.
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -244,7 +347,22 @@ mbootstrapSubmit
|
2014-09-13 02:35:36 +00:00
|
|
|
=> BootstrapSubmit msg -> MForm m (FormResult (), FieldView site)
|
|
|
|
mbootstrapSubmit (BootstrapSubmit msg classes attrs) =
|
|
|
|
let res = FormSuccess ()
|
|
|
|
- widget = [whamlet|<button class="btn #{classes}" type=submit *{attrs}>_{msg}|]
|
|
|
|
+ widget = do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "<button class=\"btn ");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml classes);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack)
|
|
|
|
+ "\" type=\"submit\"");
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Hamlet.attrsToHtml . Text.Hamlet.toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) ">");
|
|
|
|
+ ((liftM (toHtml .) getMessageRender)
|
2015-08-02 19:48:36 +00:00
|
|
|
+ >>= (\ urender_as0w -> (asWidgetT . toWidget) (urender_as0w msg)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . T.pack) "</button>") }
|
|
|
|
+
|
|
|
|
fv = FieldView { fvLabel = ""
|
|
|
|
, fvTooltip = Nothing
|
|
|
|
, fvId = bootstrapSubmitId
|
2013-09-22 05:27:15 +00:00
|
|
|
diff --git a/Yesod/Form/Fields.hs b/Yesod/Form/Fields.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index c6091a9..9e6bd4e 100644
|
2013-09-22 05:27:15 +00:00
|
|
|
--- a/Yesod/Form/Fields.hs
|
|
|
|
+++ b/Yesod/Form/Fields.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -1,4 +1,3 @@
|
|
|
|
-{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
|
|
@@ -18,9 +17,6 @@ module Yesod.Form.Fields
|
|
|
|
, timeField
|
|
|
|
, htmlField
|
|
|
|
, emailField
|
|
|
|
- , multiEmailField
|
|
|
|
- , searchField
|
|
|
|
- , AutoFocus
|
|
|
|
, urlField
|
|
|
|
, doubleField
|
|
|
|
, parseDate
|
|
|
|
@@ -37,15 +33,11 @@ module Yesod.Form.Fields
|
|
|
|
, selectFieldList
|
|
|
|
, radioField
|
|
|
|
, radioFieldList
|
|
|
|
- , checkboxesFieldList
|
|
|
|
- , checkboxesField
|
|
|
|
, multiSelectField
|
|
|
|
, multiSelectFieldList
|
2013-09-22 05:27:15 +00:00
|
|
|
, Option (..)
|
|
|
|
, OptionList (..)
|
|
|
|
, mkOptionList
|
|
|
|
- , optionsPersist
|
|
|
|
- , optionsPersistKey
|
|
|
|
, optionsPairs
|
|
|
|
, optionsEnum
|
|
|
|
) where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -72,6 +64,15 @@ import Control.Monad (when, unless)
|
2014-05-21 16:42:22 +00:00
|
|
|
import Data.Either (partitionEithers)
|
2013-09-22 05:27:15 +00:00
|
|
|
import Data.Maybe (listToMaybe, fromMaybe)
|
|
|
|
|
|
|
|
+import qualified Text.Blaze as Text.Blaze.Internal
|
|
|
|
+import qualified Text.Blaze.Internal
|
|
|
|
+import qualified Text.Hamlet
|
|
|
|
+import qualified Yesod.Core.Widget
|
|
|
|
+import qualified Text.Css
|
|
|
|
+import qualified Data.Monoid
|
|
|
|
+import qualified Data.Foldable
|
|
|
|
+import qualified Control.Monad
|
|
|
|
+
|
|
|
|
import qualified Blaze.ByteString.Builder.Html.Utf8 as B
|
|
|
|
import Blaze.ByteString.Builder (writeByteString, toLazyByteString)
|
|
|
|
import Blaze.ByteString.Builder.Internal.Write (fromWriteList)
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -91,15 +92,12 @@ import qualified Data.Text as T (drop, dropWhile)
|
|
|
|
import qualified Data.Text.Read
|
|
|
|
|
|
|
|
import qualified Data.Map as Map
|
|
|
|
-import Yesod.Persist (selectList, runDB, Filter, SelectOpt, Key, YesodPersist, PersistEntity, PersistQuery)
|
|
|
|
import Control.Arrow ((&&&))
|
|
|
|
|
|
|
|
import Control.Applicative ((<$>), (<|>))
|
2013-09-22 05:27:15 +00:00
|
|
|
|
|
|
|
import Data.Attoparsec.Text (Parser, char, string, digit, skipSpace, endOfInput, parseOnly)
|
|
|
|
|
|
|
|
-import Yesod.Persist.Core
|
2014-05-21 16:42:22 +00:00
|
|
|
-
|
2013-09-22 05:27:15 +00:00
|
|
|
defaultFormMessage :: FormMessage -> Text
|
|
|
|
defaultFormMessage = englishFormMessage
|
2014-05-21 16:42:22 +00:00
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -111,10 +109,25 @@ intField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
Right (a, "") -> Right a
|
|
|
|
_ -> Left $ MsgInvalidInteger s
|
|
|
|
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
2014-02-08 17:24:31 +00:00
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="number" step=1 :isReq:required="" value="#{showVal val}">
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJJh
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
2014-09-13 02:35:36 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"number\" step=\"1\"");
|
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -128,10 +141,25 @@ doubleField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
Right (a, "") -> Right a
|
|
|
|
_ -> Left $ MsgInvalidNumber s
|
|
|
|
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
2014-02-08 17:24:31 +00:00
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="number" step=any :isReq:required="" value="#{showVal val}">
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJJu
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
2014-09-13 02:35:36 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"number\" step=\"any\"");
|
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where showVal = either id (pack . show)
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -139,10 +167,24 @@ $newline never
|
2013-09-22 05:27:15 +00:00
|
|
|
dayField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Day
|
|
|
|
dayField = Field
|
|
|
|
{ fieldParse = parseHelper $ parseDate . unpack
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="date" :isReq:required="" value="#{showVal val}">
|
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJJF
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"date\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where showVal = either id (pack . show)
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -150,10 +192,23 @@ $newline never
|
|
|
|
timeField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
|
|
|
|
timeField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fieldParse = parseHelper parseTime
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
2015-08-02 19:48:36 +00:00
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} :isReq:required="" value="#{showVal val}">
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJJT
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -166,10 +221,23 @@ $newline never
|
2013-09-22 05:27:15 +00:00
|
|
|
htmlField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Html
|
|
|
|
htmlField = Field
|
|
|
|
{ fieldParse = parseHelper $ Right . preEscapedText . sanitizeBalance
|
2014-09-13 02:35:36 +00:00
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
2013-09-22 05:27:15 +00:00
|
|
|
-$newline never
|
2014-09-13 02:35:36 +00:00
|
|
|
-<textarea :isReq:required="" id="#{theId}" name="#{name}" *{attrs}>#{showVal val}
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJK4
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
2014-09-13 02:35:36 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<textarea");
|
|
|
|
+ condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " id=\"");
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "</textarea>") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where showVal = either id (pack . renderHtml)
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -197,10 +265,18 @@ instance ToHtml Textarea where
|
2014-10-14 04:16:38 +00:00
|
|
|
textareaField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Textarea
|
2013-09-22 05:27:15 +00:00
|
|
|
textareaField = Field
|
|
|
|
{ fieldParse = parseHelper $ Right . Textarea
|
2015-08-02 19:48:36 +00:00
|
|
|
- , fieldView = \theId name attrs val _isReq -> toWidget [hamlet|
|
2013-09-22 05:27:15 +00:00
|
|
|
-$newline never
|
2015-08-02 19:48:36 +00:00
|
|
|
-<textarea id="#{theId}" name="#{name}" *{attrs}>#{either id unTextarea val}
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val _isReq -> toWidget $ \ _render_aJKe
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<textarea id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ id (toHtml (either id unTextarea val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "</textarea>") }
|
2014-10-16 04:31:59 +00:00
|
|
|
+
|
2013-09-22 05:27:15 +00:00
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -208,10 +284,19 @@ hiddenField :: (Monad m, PathPiece p, RenderMessage (HandlerSite m) FormMessage)
|
2013-09-22 05:27:15 +00:00
|
|
|
=> Field m p
|
|
|
|
hiddenField = Field
|
|
|
|
{ fieldParse = parseHelper $ maybe (Left MsgValueRequired) Right . fromPathPiece
|
|
|
|
- , fieldView = \theId name attrs val _isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input type="hidden" id="#{theId}" name="#{name}" *{attrs} value="#{either id toPathPiece val}">
|
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val _isReq -> toWidget $ \ _render_aJKo
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"hidden\" id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"");
|
|
|
|
+ id (toHtml (either id toPathPiece val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -219,20 +304,53 @@ textField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Tex
|
2013-09-22 05:27:15 +00:00
|
|
|
textField = Field
|
|
|
|
{ fieldParse = parseHelper $ Right
|
|
|
|
, fieldView = \theId name attrs val isReq ->
|
|
|
|
- [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="text" :isReq:required value="#{either id id val}">
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"text\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " required"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (either id id val));
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
2015-08-02 19:48:36 +00:00
|
|
|
|
2013-09-22 05:27:15 +00:00
|
|
|
passwordField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
|
|
|
|
passwordField = Field
|
|
|
|
{ fieldParse = parseHelper $ Right
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="password" :isReq:required="" value="#{either id id val}">
|
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJKH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"password\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (either id id val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -304,10 +422,24 @@ emailField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
case Email.canonicalizeEmail $ encodeUtf8 s of
|
|
|
|
Just e -> Right $ decodeUtf8With lenientDecode e
|
|
|
|
Nothing -> Left $ MsgInvalidEmail s
|
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="email" :isReq:required="" value="#{either id id val}">
|
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJLq
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"email\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (either id id val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
2014-09-13 02:35:36 +00:00
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
2013-09-22 05:27:15 +00:00
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -322,10 +454,25 @@ multiEmailField = Field
|
2014-09-13 02:35:36 +00:00
|
|
|
in case partitionEithers addrs of
|
|
|
|
([], good) -> Right good
|
|
|
|
(bad, _) -> Left $ MsgInvalidEmail $ cat bad
|
2014-05-21 16:42:22 +00:00
|
|
|
- , fieldView = \theId name attrs val isReq -> toWidget [hamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="email" multiple :isReq:required="" value="#{either id cat val}">
|
|
|
|
-|]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> toWidget $ \ _render_aJMd
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"email\" multiple");
|
|
|
|
+ condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (either id cat val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -341,20 +488,75 @@ searchField :: Monad m => RenderMessage (HandlerSite m) FormMessage => AutoFocus
|
2014-09-13 02:35:36 +00:00
|
|
|
searchField autoFocus = Field
|
|
|
|
{ fieldParse = parseHelper Right
|
|
|
|
, fieldView = \theId name attrs val isReq -> do
|
2014-05-21 16:42:22 +00:00
|
|
|
- [whamlet|
|
2013-09-22 05:27:15 +00:00
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="search" :isReq:required="" :autoFocus:autofocus="" value="#{either id id val}">
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"search\"");
|
|
|
|
+ condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ condH
|
|
|
|
+ [(autoFocus,
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " autofocus=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml (either id id val));
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
when autoFocus $ do
|
|
|
|
-- we want this javascript to be placed immediately after the field
|
2013-09-22 05:27:15 +00:00
|
|
|
- [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<script>if (!('autofocus' in document.createElement('input'))) {document.getElementById('#{theId}').focus();}
|
|
|
|
-|]
|
|
|
|
- toWidget [cassius|
|
|
|
|
- ##{theId}
|
|
|
|
- -webkit-appearance: textfield
|
|
|
|
- |]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<script>if (!('autofocus' in document.createElement('input'))) {document.getElementById('");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "').focus();}</script>") }
|
|
|
|
+
|
2015-08-02 19:48:36 +00:00
|
|
|
+ toWidget $ \ _render_aJMx
|
|
|
|
+ -> (Text.Css.CssNoWhitespace
|
|
|
|
+ . (foldr ($) []))
|
2014-09-13 02:35:36 +00:00
|
|
|
+ [((++)
|
|
|
|
+ $ (map
|
|
|
|
+ Text.Css.TopBlock
|
|
|
|
+ (((Text.Css.Block
|
|
|
|
+ {Text.Css.blockSelector = Data.Monoid.mconcat
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(Text.Css.fromText
|
|
|
|
+ . Text.Css.pack)
|
|
|
|
+ "#",
|
|
|
|
+ toCss theId],
|
2014-09-13 02:35:36 +00:00
|
|
|
+ Text.Css.blockAttrs = (Prelude.concat
|
2015-08-02 19:48:36 +00:00
|
|
|
+ $ ([Text.Css.Attr
|
|
|
|
+ (Data.Monoid.mconcat
|
|
|
|
+ [(Text.Css.fromText
|
|
|
|
+ . Text.Css.pack)
|
|
|
|
+ "-webkit-appearance"])
|
|
|
|
+ (Data.Monoid.mconcat
|
|
|
|
+ [(Text.Css.fromText
|
|
|
|
+ . Text.Css.pack)
|
|
|
|
+ "textfield"])]
|
|
|
|
+ :
|
|
|
|
+ (map
|
|
|
|
+ Text.Css.mixinAttrs
|
|
|
|
+ []))),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ Text.Css.blockBlocks = (),
|
|
|
|
+ Text.Css.blockMixins = ()} :)
|
|
|
|
+ . ((foldr (.) id [])
|
|
|
|
+ . (concatMap Text.Css.mixinBlocks [] ++)))
|
|
|
|
+ [])))]
|
|
|
|
+
|
2013-09-22 05:27:15 +00:00
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
2015-08-02 19:48:36 +00:00
|
|
|
|
|
|
|
@@ -365,7 +567,28 @@ urlField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
Nothing -> Left $ MsgInvalidUrl s
|
|
|
|
Just _ -> Right s
|
|
|
|
, fieldView = \theId name attrs val isReq ->
|
|
|
|
- [whamlet|<input ##{theId} name=#{name} *{attrs} type=url :isReq:required value=#{either id id val}>|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"url\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " required"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (either id id val));
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -378,18 +601,54 @@ selectField :: (Eq a, RenderMessage site FormMessage)
|
2013-09-22 05:27:15 +00:00
|
|
|
=> HandlerT site IO (OptionList a)
|
|
|
|
-> Field (HandlerT site IO) a
|
|
|
|
selectField = selectFieldHelper
|
|
|
|
- (\theId name attrs inside -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<select ##{theId} name=#{name} *{attrs}>^{inside}
|
|
|
|
-|]) -- outside
|
|
|
|
- (\_theId _name isSel -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<option value=none :isSel:selected>_{MsgSelectNone}
|
|
|
|
-|]) -- onOpt
|
|
|
|
- (\_theId _name _attrs value isSel text -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<option value=#{value} :isSel:selected>#{text}
|
|
|
|
-|]) -- inside
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\theId name attrs inside -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<select id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) inside;
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</select>") })
|
|
|
|
+ -- outside
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\_theId _name isSel -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<option value=\"none\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isSel,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " selected"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ ((Control.Monad.liftM (toHtml .) getMessageRender)
|
|
|
|
+ >>=
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ urender_aJMX
|
|
|
|
+ -> (asWidgetT . toWidget) (urender_aJMX MsgSelectNone)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</option>") })
|
|
|
|
+ -- onOpt
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\_theId _name _attrs value isSel text -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<option value=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml value);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isSel,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " selected"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml text);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</option>") })
|
|
|
|
+ -- inside
|
|
|
|
|
|
|
|
multiSelectFieldList :: (Eq a, RenderMessage site FormMessage, RenderMessage site msg)
|
2015-08-02 19:48:36 +00:00
|
|
|
=> [(msg, a)]
|
|
|
|
@@ -412,11 +671,45 @@ multiSelectField ioptlist =
|
2013-09-22 05:27:15 +00:00
|
|
|
view theId name attrs val isReq = do
|
|
|
|
opts <- fmap olOptions $ handlerToWidget ioptlist
|
|
|
|
let selOpts = map (id &&& (optselected val)) opts
|
|
|
|
- [whamlet|
|
|
|
|
- <select ##{theId} name=#{name} :isReq:required multiple *{attrs}>
|
|
|
|
- $forall (opt, optsel) <- selOpts
|
|
|
|
- <option value=#{optionExternalValue opt} :optsel:selected>#{optionDisplay opt}
|
|
|
|
- |]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<select id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " required"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " multiple");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ (opt_aJNs, optsel_aJNt)
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<option value=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (optionExternalValue opt_aJNs));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(optsel_aJNt,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " selected"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (optionDisplay opt_aJNs));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</option>") })
|
|
|
|
+ selOpts;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</select>") }
|
|
|
|
+
|
|
|
|
where
|
|
|
|
optselected (Left _) _ = False
|
|
|
|
optselected (Right vals) opt = (optionInternalValue opt) `elem` vals
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -439,54 +732,196 @@ checkboxesField ioptlist = (multiSelectField ioptlist)
|
2014-09-13 02:35:36 +00:00
|
|
|
opts <- fmap olOptions $ handlerToWidget ioptlist
|
|
|
|
let optselected (Left _) _ = False
|
|
|
|
optselected (Right vals) opt = (optionInternalValue opt) `elem` vals
|
2013-10-19 02:44:06 +00:00
|
|
|
- [whamlet|
|
|
|
|
- <span ##{theId}>
|
|
|
|
- $forall opt <- opts
|
|
|
|
- <label>
|
|
|
|
- <input type=checkbox name=#{name} value=#{optionExternalValue opt} *{attrs} :optselected val opt:checked>
|
|
|
|
- #{optionDisplay opt}
|
|
|
|
- |]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<span id=\"");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ opt_aJNI
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<label><input type=\"checkbox\" name=\"");
|
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (optionExternalValue opt_aJNI));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
|
|
|
+ condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(optselected val opt_aJNI,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (optionDisplay opt_aJNI));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</label>") })
|
|
|
|
+ opts;
|
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</span>") }
|
|
|
|
+
|
|
|
|
}
|
2015-08-02 19:48:36 +00:00
|
|
|
|
2013-10-19 02:44:06 +00:00
|
|
|
radioField :: (Eq a, RenderMessage site FormMessage)
|
2013-09-22 05:27:15 +00:00
|
|
|
=> HandlerT site IO (OptionList a)
|
|
|
|
-> Field (HandlerT site IO) a
|
|
|
|
radioField = selectFieldHelper
|
|
|
|
- (\theId _name _attrs inside -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<div ##{theId}>^{inside}
|
|
|
|
-|])
|
|
|
|
- (\theId name isSel -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<label .radio for=#{theId}-none>
|
|
|
|
- <div>
|
|
|
|
- <input id=#{theId}-none type=radio name=#{name} value=none :isSel:checked>
|
|
|
|
- _{MsgSelectNone}
|
|
|
|
-|])
|
|
|
|
- (\theId name attrs value isSel text -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<label .radio for=#{theId}-#{value}>
|
|
|
|
- <div>
|
|
|
|
- <input id=#{theId}-#{value} type=radio name=#{name} value=#{value} :isSel:checked *{attrs}>
|
|
|
|
- \#{text}
|
|
|
|
-|])
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\theId _name _attrs inside -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<div id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) inside;
|
|
|
|
+ (asWidgetT . toWidget)
|
2014-10-13 21:08:29 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div>") })
|
2013-09-22 05:27:15 +00:00
|
|
|
+
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\theId name isSel -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<label class=\"radio\" for=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "-none\"><div><input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "-none\" type=\"radio\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"none\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isSel,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ ((Control.Monad.liftM (toHtml .) getMessageRender)
|
|
|
|
+ >>=
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ urender_aJNY
|
|
|
|
+ -> (asWidgetT . toWidget) (urender_aJNY MsgSelectNone)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div></label>") })
|
|
|
|
+
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (\theId name attrs value isSel text -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<label class=\"radio\" for=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "-");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml value);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\"><div><input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "-");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml value);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"radio\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml value);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isSel,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml text);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div></label>") })
|
|
|
|
+
|
|
|
|
|
|
|
|
boolField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Bool
|
|
|
|
boolField = Field
|
|
|
|
{ fieldParse = \e _ -> return $ boolParser e
|
|
|
|
- , fieldView = \theId name attrs val isReq -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
- $if not isReq
|
|
|
|
- <input id=#{theId}-none *{attrs} type=radio name=#{name} value=none checked>
|
|
|
|
- <label for=#{theId}-none>_{MsgSelectNone}
|
2014-05-21 16:42:22 +00:00
|
|
|
-
|
2014-09-13 02:35:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val isReq -> do { condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(not isReq,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "-none\" type=\"radio\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" value=\"none\" checked");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "><label for=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "-none\">");
|
|
|
|
+ ((Control.Monad.liftM (toHtml .) getMessageRender)
|
|
|
|
+ >>=
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ urender_aJOn
|
|
|
|
+ -> (asWidgetT . toWidget) (urender_aJOn MsgSelectNone)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</label>") })]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "-yes\" type=\"radio\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"yes\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(showVal id val,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "><label for=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "-yes\">");
|
|
|
|
+ ((Control.Monad.liftM (toHtml .) getMessageRender)
|
|
|
|
+ >>=
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ urender_aJOo
|
|
|
|
+ -> (asWidgetT . toWidget) (urender_aJOo MsgBoolYes)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "</label><input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "-no\" type=\"radio\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"no\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(showVal not val,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "><label for=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "-no\">");
|
|
|
|
+ ((Control.Monad.liftM (toHtml .) getMessageRender)
|
|
|
|
+ >>=
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ urender_aJOp
|
|
|
|
+ -> (asWidgetT . toWidget) (urender_aJOp MsgBoolNo)));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</label>") }
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
-<input id=#{theId}-yes *{attrs} type=radio name=#{name} value=yes :showVal id val:checked>
|
|
|
|
-<label for=#{theId}-yes>_{MsgBoolYes}
|
|
|
|
-
|
2013-09-22 05:27:15 +00:00
|
|
|
-<input id=#{theId}-no *{attrs} type=radio name=#{name} value=no :showVal not val:checked>
|
|
|
|
-<label for=#{theId}-no>_{MsgBoolNo}
|
|
|
|
-|]
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -512,10 +947,24 @@ $newline never
|
2013-09-22 05:27:15 +00:00
|
|
|
checkBoxField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Bool
|
|
|
|
checkBoxField = Field
|
|
|
|
{ fieldParse = \e _ -> return $ checkBoxParser e
|
|
|
|
- , fieldView = \theId name attrs val _ -> [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id=#{theId} *{attrs} type=checkbox name=#{name} value=yes :showVal id val:checked>
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ , fieldView = \theId name attrs val _ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml theId);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\" type=\"checkbox\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"yes\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(showVal id val,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " checked"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) attrs);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -559,69 +1008,6 @@ optionsPairs opts = do
|
2014-10-14 04:16:38 +00:00
|
|
|
optionsEnum :: (MonadHandler m, Show a, Enum a, Bounded a) => m (OptionList a)
|
|
|
|
optionsEnum = optionsPairs $ map (\x -> (pack $ show x, x)) [minBound..maxBound]
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
-#if MIN_VERSION_persistent(2, 0, 0)
|
2014-10-14 04:16:38 +00:00
|
|
|
-optionsPersist :: ( YesodPersist site, PersistEntity a
|
|
|
|
- , PersistQuery (PersistEntityBackend a)
|
|
|
|
- , PathPiece (Key a)
|
|
|
|
- , RenderMessage site msg
|
|
|
|
- , YesodPersistBackend site ~ PersistEntityBackend a
|
|
|
|
- )
|
2015-08-02 19:48:36 +00:00
|
|
|
-#else
|
|
|
|
-optionsPersist :: ( YesodPersist site, PersistEntity a
|
|
|
|
- , PersistQuery (YesodPersistBackend site (HandlerT site IO))
|
|
|
|
- , PathPiece (Key a)
|
|
|
|
- , PersistEntityBackend a ~ PersistMonadBackend (YesodPersistBackend site (HandlerT site IO))
|
|
|
|
- , RenderMessage site msg
|
|
|
|
- )
|
|
|
|
-#endif
|
2014-10-14 04:16:38 +00:00
|
|
|
- => [Filter a]
|
|
|
|
- -> [SelectOpt a]
|
|
|
|
- -> (a -> msg)
|
|
|
|
- -> HandlerT site IO (OptionList (Entity a))
|
|
|
|
-optionsPersist filts ords toDisplay = fmap mkOptionList $ do
|
|
|
|
- mr <- getMessageRender
|
|
|
|
- pairs <- runDB $ selectList filts ords
|
|
|
|
- return $ map (\(Entity key value) -> Option
|
|
|
|
- { optionDisplay = mr (toDisplay value)
|
|
|
|
- , optionInternalValue = Entity key value
|
|
|
|
- , optionExternalValue = toPathPiece key
|
|
|
|
- }) pairs
|
|
|
|
-
|
2015-08-02 19:48:36 +00:00
|
|
|
--- | An alternative to 'optionsPersist' which returns just the @Key@ instead of
|
|
|
|
--- the entire @Entity@.
|
2014-10-14 04:16:38 +00:00
|
|
|
---
|
|
|
|
--- Since 1.3.2
|
2015-08-02 19:48:36 +00:00
|
|
|
-#if MIN_VERSION_persistent(2, 0, 0)
|
2014-10-14 04:16:38 +00:00
|
|
|
-optionsPersistKey
|
|
|
|
- :: (YesodPersist site
|
|
|
|
- , PersistEntity a
|
|
|
|
- , PersistQuery (PersistEntityBackend a)
|
|
|
|
- , PathPiece (Key a)
|
|
|
|
- , RenderMessage site msg
|
|
|
|
- , YesodPersistBackend site ~ PersistEntityBackend a
|
|
|
|
- )
|
2015-08-02 19:48:36 +00:00
|
|
|
-#else
|
|
|
|
-optionsPersistKey
|
|
|
|
- :: (YesodPersist site
|
|
|
|
- , PersistEntity a
|
|
|
|
- , PersistQuery (YesodPersistBackend site (HandlerT site IO))
|
|
|
|
- , PathPiece (Key a)
|
|
|
|
- , RenderMessage site msg
|
|
|
|
- , PersistEntityBackend a ~ PersistMonadBackend (YesodDB site))
|
|
|
|
-#endif
|
2014-10-14 04:16:38 +00:00
|
|
|
- => [Filter a]
|
|
|
|
- -> [SelectOpt a]
|
|
|
|
- -> (a -> msg)
|
|
|
|
- -> HandlerT site IO (OptionList (Key a))
|
|
|
|
-
|
|
|
|
-optionsPersistKey filts ords toDisplay = fmap mkOptionList $ do
|
|
|
|
- mr <- getMessageRender
|
|
|
|
- pairs <- runDB $ selectList filts ords
|
|
|
|
- return $ map (\(Entity key value) -> Option
|
|
|
|
- { optionDisplay = mr (toDisplay value)
|
|
|
|
- , optionInternalValue = key
|
|
|
|
- , optionExternalValue = toPathPiece key
|
|
|
|
- }) pairs
|
2015-08-02 19:48:36 +00:00
|
|
|
|
2014-10-14 04:16:38 +00:00
|
|
|
selectFieldHelper
|
|
|
|
:: (Eq a, RenderMessage site FormMessage)
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -665,9 +1051,21 @@ fileField = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
case files of
|
|
|
|
[] -> Right Nothing
|
|
|
|
file:_ -> Right $ Just file
|
|
|
|
- , fieldView = \id' name attrs _ isReq -> toWidget [hamlet|
|
|
|
|
- <input id=#{id'} name=#{name} *{attrs} type=file :isReq:required>
|
|
|
|
- |]
|
2015-08-02 19:48:36 +00:00
|
|
|
+ , fieldView = \id' name attrs _ isReq -> toWidget $ \ _render_aJPt
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml id');
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"file\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ condH
|
2013-09-22 05:27:15 +00:00
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ id ((attrsToHtml . toAttributes) attrs);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fieldEnctype = Multipart
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -694,10 +1092,19 @@ fileAFormReq fs = AForm $ \(site, langs) menvs ints -> do
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fvLabel = toHtml $ renderMessage site langs $ fsLabel fs
|
|
|
|
, fvTooltip = fmap (toHtml . renderMessage site langs) $ fsTooltip fs
|
|
|
|
, fvId = id'
|
|
|
|
- , fvInput = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input type=file name=#{name} ##{id'} *{fsAttrs fs}>
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ , fvInput = do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"file\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml id');
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) (fsAttrs fs));
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fvErrors = errs
|
|
|
|
, fvRequired = True
|
|
|
|
}
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -726,10 +1133,19 @@ fileAFormOpt fs = AForm $ \(master, langs) menvs ints -> do
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fvLabel = toHtml $ renderMessage master langs $ fsLabel fs
|
|
|
|
, fvTooltip = fmap (toHtml . renderMessage master langs) $ fsTooltip fs
|
|
|
|
, fvId = id'
|
|
|
|
- , fvInput = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input type=file name=#{name} ##{id'} *{fsAttrs fs}>
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ , fvInput = do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"file\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml name);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" id=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml id');
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) ((attrsToHtml . toAttributes) (fsAttrs fs));
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
, fvErrors = errs
|
|
|
|
, fvRequired = False
|
|
|
|
}
|
|
|
|
diff --git a/Yesod/Form/Functions.hs b/Yesod/Form/Functions.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index 9e6abaf..0c2a0ce 100644
|
2013-09-22 05:27:15 +00:00
|
|
|
--- a/Yesod/Form/Functions.hs
|
|
|
|
+++ b/Yesod/Form/Functions.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -60,12 +60,16 @@ import Text.Blaze (Markup, toMarkup)
|
2013-12-18 21:41:17 +00:00
|
|
|
#define toHtml toMarkup
|
|
|
|
import Yesod.Core
|
|
|
|
import Network.Wai (requestMethod)
|
|
|
|
-import Text.Hamlet (shamlet)
|
2015-08-02 19:48:36 +00:00
|
|
|
+--import Text.Hamlet (shamlet)
|
2013-12-18 21:41:17 +00:00
|
|
|
import Data.Monoid (mempty)
|
|
|
|
import Data.Maybe (listToMaybe, fromMaybe)
|
2013-09-22 05:27:15 +00:00
|
|
|
import qualified Data.Map as Map
|
|
|
|
import qualified Data.Text.Encoding as TE
|
|
|
|
import Control.Arrow (first)
|
|
|
|
+import qualified Text.Blaze.Internal
|
2015-08-02 19:48:36 +00:00
|
|
|
+import qualified Yesod.Core.Widget
|
2013-09-22 05:27:15 +00:00
|
|
|
+import qualified Data.Foldable
|
2015-08-02 19:48:36 +00:00
|
|
|
+import qualified Text.Hamlet
|
2013-09-22 05:27:15 +00:00
|
|
|
|
|
|
|
-- | Get a unique identifier.
|
|
|
|
newFormIdent :: Monad m => MForm m Text
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -217,7 +221,14 @@ postHelper form env = do
|
2013-09-22 05:27:15 +00:00
|
|
|
let token =
|
|
|
|
case reqToken req of
|
|
|
|
Nothing -> mempty
|
|
|
|
- Just n -> [shamlet|<input type=hidden name=#{tokenKey} value=#{n}>|]
|
|
|
|
+ Just n -> do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"hidden\" name=\"");
|
|
|
|
+ id (toHtml tokenKey);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"");
|
|
|
|
+ id (toHtml n);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\">") }
|
|
|
|
+
|
|
|
|
m <- getYesod
|
|
|
|
langs <- languages
|
|
|
|
((res, xml), enctype) <- runFormGeneric (form token) m langs env
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -297,7 +308,12 @@ getHelper :: MonadHandler m
|
2013-09-22 05:27:15 +00:00
|
|
|
-> Maybe (Env, FileEnv)
|
|
|
|
-> m (a, Enctype)
|
|
|
|
getHelper form env = do
|
|
|
|
- let fragment = [shamlet|<input type=hidden name=#{getKey}>|]
|
|
|
|
+ let fragment = do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"hidden\" name=\"");
|
|
|
|
+ id (toHtml getKey);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\">") }
|
|
|
|
+
|
|
|
|
langs <- languages
|
|
|
|
m <- getYesod
|
|
|
|
runFormGeneric (form fragment) m langs env
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -332,10 +348,15 @@ identifyForm
|
2014-09-13 02:35:36 +00:00
|
|
|
identifyForm identVal form = \fragment -> do
|
|
|
|
-- Create hidden <input>.
|
|
|
|
let fragment' =
|
2014-05-21 16:42:22 +00:00
|
|
|
- [shamlet|
|
|
|
|
- <input type=hidden name=#{identifyFormKey} value=#{identVal}>
|
|
|
|
- #{fragment}
|
|
|
|
- |]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input type=\"hidden\" name=\"");
|
|
|
|
+ id (toHtml identifyFormKey);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" value=\"");
|
|
|
|
+ id (toHtml identVal);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
|
|
|
+ id (toHtml fragment) }
|
|
|
|
+
|
2014-05-21 16:42:22 +00:00
|
|
|
|
2014-09-13 02:35:36 +00:00
|
|
|
-- Check if we got its value back.
|
|
|
|
mp <- askParams
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -365,22 +386,70 @@ renderTable, renderDivs, renderDivsNoLabels :: Monad m => FormRender m a
|
2013-09-22 05:27:15 +00:00
|
|
|
renderTable aform fragment = do
|
|
|
|
(res, views') <- aFormToForm aform
|
|
|
|
let views = views' []
|
|
|
|
- let widget = [whamlet|
|
|
|
|
-$newline never
|
2014-09-13 02:35:36 +00:00
|
|
|
-$if null views
|
|
|
|
- \#{fragment}
|
|
|
|
-$forall (isFirst, view) <- addIsFirst views
|
2013-09-22 05:27:15 +00:00
|
|
|
- <tr :fvRequired view:.required :not $ fvRequired view:.optional>
|
|
|
|
- <td>
|
2014-09-13 02:35:36 +00:00
|
|
|
- $if isFirst
|
|
|
|
- \#{fragment}
|
2013-09-22 05:27:15 +00:00
|
|
|
- <label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <div .tooltip>#{tt}
|
|
|
|
- <td>^{fvInput view}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <td .errors>#{err}
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ let widget = do { Text.Hamlet.condH
|
|
|
|
+ [(null views, (asWidgetT . toWidget) (toHtml fragment))] Nothing;
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ (isFirst_ab5u, view_ab5v)
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<tr");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(or [fvRequired view_ab5v, not (fvRequired view_ab5v)],
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " class=\"");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_ab5v,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_ab5v),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "optional"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"") })]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "><td>");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(isFirst_ab5u, (asWidgetT . toWidget) (toHtml fragment))] Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<label for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_ab5v));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_ab5v));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</label>");
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvTooltip view_ab5v)
|
|
|
|
+ (\ tt_ab5w
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<div class=\"tooltip\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_ab5w);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</td><td>");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_ab5v);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</td>");
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvErrors view_ab5v)
|
|
|
|
+ (\ err_ab5x
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<td class=\"errors\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_ab5x);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</td>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</tr>") })
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (addIsFirst views) }
|
2013-09-22 05:27:15 +00:00
|
|
|
+
|
|
|
|
return (res, widget)
|
2014-09-13 02:35:36 +00:00
|
|
|
where
|
|
|
|
addIsFirst [] = []
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -396,19 +465,66 @@ renderDivsMaybeLabels :: Monad m => Bool -> FormRender m a
|
2013-09-22 05:27:15 +00:00
|
|
|
renderDivsMaybeLabels withLabels aform fragment = do
|
|
|
|
(res, views') <- aFormToForm aform
|
|
|
|
let views = views' []
|
|
|
|
- let widget = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-\#{fragment}
|
|
|
|
-$forall view <- views
|
|
|
|
- <div :fvRequired view:.required :not $ fvRequired view:.optional>
|
|
|
|
- $if withLabels
|
|
|
|
- <label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <div .tooltip>#{tt}
|
|
|
|
- ^{fvInput view}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <div .errors>#{err}
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ let widget = do { (asWidgetT . toWidget) (toHtml fragment);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ view_ab5K
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<div");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(or [fvRequired view_ab5K, not (fvRequired view_ab5K)],
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) " class=\"");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_ab5K,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_ab5K),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "optional"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\"") })]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ Text.Hamlet.condH
|
|
|
|
+ [(withLabels,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<label for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_ab5K));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_ab5K));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</label>") })]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvTooltip view_ab5K)
|
|
|
|
+ (\ tt_ab5L
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<div class=\"tooltip\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_ab5L);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div>") })
|
|
|
|
+ Nothing;
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_ab5K);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvErrors view_ab5K)
|
|
|
|
+ (\ err_ab5M
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<div class=\"errors\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_ab5M);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div>") })
|
|
|
|
+ views }
|
|
|
|
+
|
|
|
|
return (res, widget)
|
|
|
|
|
2014-05-21 16:42:22 +00:00
|
|
|
-- | Render a form using Bootstrap v2-friendly shamlet syntax.
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -436,19 +552,62 @@ renderBootstrap2 aform fragment = do
|
2013-09-22 05:27:15 +00:00
|
|
|
let views = views' []
|
|
|
|
has (Just _) = True
|
|
|
|
has Nothing = False
|
|
|
|
- let widget = [whamlet|
|
|
|
|
- $newline never
|
|
|
|
- \#{fragment}
|
|
|
|
- $forall view <- views
|
|
|
|
- <div .control-group .clearfix :fvRequired view:.required :not $ fvRequired view:.optional :has $ fvErrors view:.error>
|
|
|
|
- <label .control-label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- <div .controls .input>
|
|
|
|
- ^{fvInput view}
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <span .help-block>#{tt}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <span .help-block>#{err}
|
|
|
|
- |]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ let widget = do { (asWidgetT . toWidget) (toHtml fragment);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ view_ab5Y
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<div class=\"control-group clearfix ");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_ab5Y,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_ab5Y),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "optional "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(has (fvErrors view_ab5Y),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "error"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "\"><label class=\"control-label\" for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_ab5Y));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_ab5Y));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "</label><div class=\"controls input\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_ab5Y);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvTooltip view_ab5Y)
|
|
|
|
+ (\ tt_ab5Z
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<span class=\"help-block\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_ab5Z);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</span>") })
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvErrors view_ab5Y)
|
|
|
|
+ (\ err_ab60
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<span class=\"help-block\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_ab60);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</span>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "</div></div>") })
|
|
|
|
+ views }
|
|
|
|
+
|
|
|
|
return (res, widget)
|
|
|
|
|
2014-09-13 02:35:36 +00:00
|
|
|
-- | Deprecated synonym for 'renderBootstrap2'.
|
2013-09-22 05:27:15 +00:00
|
|
|
diff --git a/Yesod/Form/Jquery.hs b/Yesod/Form/Jquery.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index 362eb8a..1df9966 100644
|
2013-09-22 05:27:15 +00:00
|
|
|
--- a/Yesod/Form/Jquery.hs
|
|
|
|
+++ b/Yesod/Form/Jquery.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -17,11 +17,23 @@ import Yesod.Core
|
2014-09-13 02:35:36 +00:00
|
|
|
import Yesod.Form
|
|
|
|
import Data.Time (Day)
|
|
|
|
import Data.Default
|
|
|
|
-import Text.Hamlet (shamlet)
|
|
|
|
-import Text.Julius (julius, rawJS)
|
2015-08-02 19:48:36 +00:00
|
|
|
+--import Text.Hamlet (shamlet)
|
2014-09-13 02:35:36 +00:00
|
|
|
+import Text.Julius (rawJS)
|
|
|
|
import Data.Text (Text, pack, unpack)
|
|
|
|
import Data.Monoid (mconcat)
|
2013-09-22 05:27:15 +00:00
|
|
|
|
|
|
|
+import qualified Text.Blaze as Text.Blaze.Internal
|
|
|
|
+import qualified Text.Blaze.Internal
|
|
|
|
+import qualified Text.Hamlet
|
|
|
|
+import qualified Yesod.Core.Widget
|
|
|
|
+import qualified Text.Css
|
|
|
|
+import qualified Data.Monoid
|
|
|
|
+import qualified Data.Foldable
|
|
|
|
+import qualified Control.Monad
|
|
|
|
+import qualified Text.Julius
|
|
|
|
+import qualified Data.Text.Lazy.Builder
|
|
|
|
+import qualified Text.Shakespeare
|
|
|
|
+
|
2014-09-13 02:35:36 +00:00
|
|
|
-- | Gets the Google hosted jQuery UI 1.8 CSS file with the given theme.
|
|
|
|
googleHostedJqueryUiCss :: Text -> Text
|
|
|
|
googleHostedJqueryUiCss theme = mconcat
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -61,27 +73,59 @@ jqueryDayField jds = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
. readMay
|
|
|
|
. unpack
|
|
|
|
, fieldView = \theId name attrs val isReq -> do
|
|
|
|
- toWidget [shamlet|
|
|
|
|
-$newline never
|
2015-08-02 19:48:36 +00:00
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="date" :isReq:required="" value="#{showVal val}">
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
|
|
|
+ toWidget $ do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "<input id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
2015-08-02 19:48:36 +00:00
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"date\"");
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Hamlet.condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
|
|
|
+ id ((Text.Hamlet.attrsToHtml . Text.Hamlet.toAttributes) attrs);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
addScript' urlJqueryJs
|
|
|
|
addScript' urlJqueryUiJs
|
|
|
|
addStylesheet' urlJqueryUiCss
|
|
|
|
- toWidget [julius|
|
|
|
|
-$(function(){
|
|
|
|
- var i = document.getElementById("#{rawJS theId}");
|
|
|
|
- if (i.type != "date") {
|
|
|
|
- $(i).datepicker({
|
|
|
|
- dateFormat:'yy-mm-dd',
|
|
|
|
- changeMonth:#{jsBool $ jdsChangeMonth jds},
|
|
|
|
- changeYear:#{jsBool $ jdsChangeYear jds},
|
|
|
|
- numberOfMonths:#{rawJS $ mos $ jdsNumberOfMonths jds},
|
|
|
|
- yearRange:#{toJSON $ jdsYearRange jds}
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
-|]
|
|
|
|
+ toWidget $ Text.Julius.asJavascriptUrl
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ _render_a2l4S
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> mconcat
|
|
|
|
+ [Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\n$(function(){\n var i = document.getElementById(\""),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (rawJS theId),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\");\n if (i.type != \"date\") {\n $(i).datepicker({\n dateFormat:'yy-mm-dd',\n changeMonth:"),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (jsBool (jdsChangeMonth jds)),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ ",\n changeYear:"),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (jsBool (jdsChangeYear jds)),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ ",\n numberOfMonths:"),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (rawJS (mos (jdsNumberOfMonths jds))),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ ",\n yearRange:"),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (toJSON (jdsYearRange jds)),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\n });\n }\n});")])
|
2013-09-22 05:27:15 +00:00
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -108,16 +152,52 @@ jqueryAutocompleteField' :: (RenderMessage site FormMessage, YesodJquery site)
|
2014-09-13 02:35:36 +00:00
|
|
|
jqueryAutocompleteField' minLen src = Field
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fieldParse = parseHelper $ Right
|
|
|
|
, fieldView = \theId name attrs val isReq -> do
|
|
|
|
- toWidget [shamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input id="#{theId}" name="#{name}" *{attrs} type="text" :isReq:required="" value="#{either id id val}" .autocomplete>
|
|
|
|
-|]
|
|
|
|
+ toWidget $ do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<input class=\"autocomplete\" id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack) "\" type=\"text\"");
|
|
|
|
+ Text.Hamlet.condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required=\"\""))]
|
|
|
|
+ Nothing;
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " value=\"");
|
|
|
|
+ id (toHtml (either id id val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
|
|
|
+ id ((Text.Hamlet.attrsToHtml . Text.Hamlet.toAttributes) attrs);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">") }
|
|
|
|
+
|
|
|
|
addScript' urlJqueryJs
|
|
|
|
addScript' urlJqueryUiJs
|
|
|
|
addStylesheet' urlJqueryUiCss
|
|
|
|
- toWidget [julius|
|
2014-09-13 02:35:36 +00:00
|
|
|
-$(function(){$("##{rawJS theId}").autocomplete({source:"@{src}",minLength:#{toJSON minLen}})});
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
|
|
|
+ toWidget $ Text.Julius.asJavascriptUrl
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ _render_a2l58
|
2013-09-22 05:27:15 +00:00
|
|
|
+ -> mconcat
|
|
|
|
+ [Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\n$(function(){$(\"#"),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.toJavascript (rawJS theId),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
2013-09-22 05:27:15 +00:00
|
|
|
+ "\").autocomplete({source:\""),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (Data.Text.Lazy.Builder.fromText
|
|
|
|
+ (_render_a2l58 src [])),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
2014-09-13 02:35:36 +00:00
|
|
|
+ "\",minLength:"),
|
|
|
|
+ Text.Julius.toJavascript (toJSON minLen),
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
2014-09-13 02:35:36 +00:00
|
|
|
+ "})});")])
|
2013-09-22 05:27:15 +00:00
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/Yesod/Form/MassInput.hs b/Yesod/Form/MassInput.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index a2b434d..75eb484 100644
|
2013-09-22 05:27:15 +00:00
|
|
|
--- a/Yesod/Form/MassInput.hs
|
|
|
|
+++ b/Yesod/Form/MassInput.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -9,6 +9,16 @@ module Yesod.Form.MassInput
|
|
|
|
, massTable
|
|
|
|
) where
|
2013-09-22 05:27:15 +00:00
|
|
|
|
|
|
|
+import qualified Data.Text
|
|
|
|
+import qualified Text.Blaze as Text.Blaze.Internal
|
|
|
|
+import qualified Text.Blaze.Internal
|
|
|
|
+import qualified Text.Hamlet
|
|
|
|
+import qualified Yesod.Core.Widget
|
|
|
|
+import qualified Text.Css
|
|
|
|
+import qualified Data.Monoid
|
|
|
|
+import qualified Data.Foldable
|
|
|
|
+import qualified Control.Monad
|
|
|
|
+
|
2015-08-02 19:48:36 +00:00
|
|
|
import Yesod.Form.Types
|
|
|
|
import Yesod.Form.Functions
|
|
|
|
import Yesod.Form.Fields (checkBoxField)
|
2014-09-13 02:35:36 +00:00
|
|
|
@@ -70,16 +80,27 @@ inputList label fixXml single mdef = formToAForm $ do
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fvLabel = label
|
|
|
|
, fvTooltip = Nothing
|
|
|
|
, fvId = theId
|
|
|
|
- , fvInput = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-^{fixXml views}
|
|
|
|
-<p>
|
|
|
|
- $forall xml <- xmls
|
|
|
|
- ^{xml}
|
|
|
|
- <input .count type=hidden name=#{countName} value=#{count}>
|
|
|
|
- <input type=checkbox name=#{addName}>
|
|
|
|
- Add another row
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ , fvInput = do { (asWidgetT . toWidget) (fixXml views);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "<p>");
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ xml_a1yM1 -> (asWidgetT . toWidget) xml_a1yM1) xmls;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<input class=\"count\" type=\"hidden\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml countName);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\" value=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml count);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\"><input type=\"checkbox\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml addName);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\">Add another row</p>") }
|
|
|
|
+
|
|
|
|
, fvErrors = Nothing
|
|
|
|
, fvRequired = False
|
|
|
|
}])
|
2014-09-13 02:35:36 +00:00
|
|
|
@@ -92,10 +113,14 @@ withDelete af = do
|
2013-09-22 05:27:15 +00:00
|
|
|
deleteName <- newFormIdent
|
|
|
|
(menv, _, _) <- ask
|
|
|
|
res <- case menv >>= Map.lookup deleteName . fst of
|
|
|
|
- Just ("yes":_) -> return $ Left [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-<input type=hidden name=#{deleteName} value=yes>
|
|
|
|
-|]
|
2014-09-13 02:35:36 +00:00
|
|
|
+ Just ("yes":_) -> return $ Left $ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<input type=\"hidden\" name=\"");
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml deleteName);
|
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\" value=\"yes\">") }
|
|
|
|
+
|
|
|
|
_ -> do
|
2014-05-21 16:42:22 +00:00
|
|
|
(_, xml2) <- aFormToForm $ areq checkBoxField FieldSettings
|
2013-09-22 05:27:15 +00:00
|
|
|
{ fsLabel = SomeMessage MsgDelete
|
2014-09-13 02:35:36 +00:00
|
|
|
@@ -121,32 +146,149 @@ fixme eithers =
|
2013-09-22 05:27:15 +00:00
|
|
|
massDivs, massTable
|
|
|
|
:: [[FieldView site]]
|
|
|
|
-> WidgetT site IO ()
|
|
|
|
-massDivs viewss = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-$forall views <- viewss
|
|
|
|
- <fieldset>
|
|
|
|
- $forall view <- views
|
|
|
|
- <div :fvRequired view:.required :not $ fvRequired view:.optional>
|
|
|
|
- <label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <div .tooltip>#{tt}
|
|
|
|
- ^{fvInput view}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <div .errors>#{err}
|
|
|
|
-|]
|
|
|
|
+massDivs viewss = Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ views_a1yMm
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<fieldset>");
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ view_a1yMn
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "<div");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(or [fvRequired view_a1yMn, not (fvRequired view_a1yMn)],
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ " class=\"");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_a1yMn,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_a1yMn),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "optional"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\"") })]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "><label for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_a1yMn));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_a1yMn));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</label>");
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvTooltip view_a1yMn)
|
|
|
|
+ (\ tt_a1yMo
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<div class=\"tooltip\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_a1yMo);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</div>") })
|
|
|
|
+ Nothing;
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_a1yMn);
|
2013-09-22 05:27:15 +00:00
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvErrors view_a1yMn)
|
|
|
|
+ (\ err_a1yMp
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<div class=\"errors\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_a1yMp);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</div>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</div>") })
|
2015-08-02 19:48:36 +00:00
|
|
|
+ views_a1yMm;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</fieldset>") })
|
|
|
|
+ viewss
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+massTable viewss = Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ views_a1yMv
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<fieldset><table>");
|
|
|
|
+ Data.Foldable.mapM_
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ view_a1yMw
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "<tr");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(or [fvRequired view_a1yMw, not (fvRequired view_a1yMw)],
|
2014-09-13 02:35:36 +00:00
|
|
|
+ do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ " class=\"");
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(fvRequired view_a1yMw,
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "required "))]
|
|
|
|
+ Nothing;
|
|
|
|
+ Text.Hamlet.condH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ [(not (fvRequired view_a1yMw),
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "optional"))]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "\"") })]
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "><td><label for=\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvId view_a1yMw));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml (fvLabel view_a1yMw));
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</label>");
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvTooltip view_a1yMw)
|
|
|
|
+ (\ tt_a1yMx
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<div class=\"tooltip\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml tt_a1yMx);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</div>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</td><td>");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (fvInput view_a1yMw);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</td>");
|
|
|
|
+ Text.Hamlet.maybeH
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (fvErrors view_a1yMw)
|
|
|
|
+ (\ err_a1yMy
|
2014-09-13 02:35:36 +00:00
|
|
|
+ -> do { (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "<td class=\"errors\">");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (asWidgetT . toWidget) (toHtml err_a1yMy);
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</td>") })
|
|
|
|
+ Nothing;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</tr>") })
|
2015-08-02 19:48:36 +00:00
|
|
|
+ views_a1yMv;
|
2014-09-13 02:35:36 +00:00
|
|
|
+ (asWidgetT . toWidget)
|
2013-09-22 05:27:15 +00:00
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
|
|
|
|
+ "</table></fieldset>") })
|
|
|
|
+ viewss
|
|
|
|
|
|
|
|
-massTable viewss = [whamlet|
|
|
|
|
-$newline never
|
|
|
|
-$forall views <- viewss
|
|
|
|
- <fieldset>
|
|
|
|
- <table>
|
|
|
|
- $forall view <- views
|
|
|
|
- <tr :fvRequired view:.required :not $ fvRequired view:.optional>
|
|
|
|
- <td>
|
|
|
|
- <label for=#{fvId view}>#{fvLabel view}
|
|
|
|
- $maybe tt <- fvTooltip view
|
|
|
|
- <div .tooltip>#{tt}
|
|
|
|
- <td>^{fvInput view}
|
|
|
|
- $maybe err <- fvErrors view
|
|
|
|
- <td .errors>#{err}
|
|
|
|
-|]
|
|
|
|
diff --git a/Yesod/Form/Nic.hs b/Yesod/Form/Nic.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
index 7e4af07..b59745a 100644
|
2013-09-22 05:27:15 +00:00
|
|
|
--- a/Yesod/Form/Nic.hs
|
|
|
|
+++ b/Yesod/Form/Nic.hs
|
2015-08-02 19:48:36 +00:00
|
|
|
@@ -9,11 +9,22 @@ module Yesod.Form.Nic
|
|
|
|
, nicHtmlField
|
|
|
|
) where
|
2013-09-22 05:27:15 +00:00
|
|
|
|
|
|
|
+import qualified Text.Blaze as Text.Blaze.Internal
|
|
|
|
+import qualified Text.Blaze.Internal
|
|
|
|
+import qualified Text.Hamlet
|
|
|
|
+import qualified Yesod.Core.Widget
|
|
|
|
+import qualified Text.Css
|
|
|
|
+import qualified Data.Monoid
|
|
|
|
+import qualified Data.Foldable
|
|
|
|
+import qualified Control.Monad
|
|
|
|
+import qualified Text.Julius
|
|
|
|
+import qualified Data.Text.Lazy.Builder
|
|
|
|
+import qualified Text.Shakespeare
|
|
|
|
+
|
2015-08-02 19:48:36 +00:00
|
|
|
import Yesod.Core
|
|
|
|
import Yesod.Form
|
|
|
|
import Text.HTML.SanitizeXSS (sanitizeBalance)
|
|
|
|
-import Text.Hamlet (shamlet)
|
|
|
|
-import Text.Julius (julius, rawJS)
|
|
|
|
+import Text.Julius ( rawJS)
|
|
|
|
import Text.Blaze.Html.Renderer.String (renderHtml)
|
|
|
|
import Data.Text (Text, pack)
|
|
|
|
import Data.Maybe (listToMaybe)
|
|
|
|
@@ -27,20 +38,52 @@ nicHtmlField :: YesodNic site => Field (HandlerT site IO) Html
|
2014-10-16 04:31:59 +00:00
|
|
|
nicHtmlField = Field
|
|
|
|
{ fieldParse = \e _ -> return . Right . fmap (preEscapedToMarkup . sanitizeBalance) . listToMaybe $ e
|
2015-08-02 19:48:36 +00:00
|
|
|
, fieldView = \theId name attrs val isReq -> do
|
2013-09-22 05:27:15 +00:00
|
|
|
- toWidget [shamlet|
|
|
|
|
-$newline never
|
2015-08-02 19:48:36 +00:00
|
|
|
- <textarea id="#{theId}" *{attrs} name="#{name}" :isReq:required .html>#{showVal val}
|
2013-09-22 05:27:15 +00:00
|
|
|
-|]
|
2014-10-16 04:31:59 +00:00
|
|
|
+ toWidget $ do { id
|
|
|
|
+ ((Text.Blaze.Internal.preEscapedText . pack)
|
|
|
|
+ "<textarea class=\"html\" id=\"");
|
|
|
|
+ id (toHtml theId);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\" name=\"");
|
|
|
|
+ id (toHtml name);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "\"");
|
2015-08-02 19:48:36 +00:00
|
|
|
+ Text.Hamlet.condH
|
|
|
|
+ [(isReq,
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) " required"))]
|
|
|
|
+ Nothing;
|
2014-10-16 04:31:59 +00:00
|
|
|
+ id ((Text.Hamlet.attrsToHtml . Text.Hamlet.toAttributes) attrs);
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) ">");
|
|
|
|
+ id (toHtml (showVal val));
|
|
|
|
+ id ((Text.Blaze.Internal.preEscapedText . pack) "</textarea>") }
|
|
|
|
+
|
|
|
|
addScript' urlNicEdit
|
|
|
|
master <- getYesod
|
|
|
|
toWidget $
|
|
|
|
case jsLoader master of
|
2013-09-22 05:27:15 +00:00
|
|
|
- BottomOfHeadBlocking -> [julius|
|
|
|
|
-bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{rawJS theId}")});
|
|
|
|
-|]
|
|
|
|
- _ -> [julius|
|
|
|
|
-(function(){new nicEditor({fullPanel:true}).panelInstance("#{rawJS theId}")})();
|
|
|
|
-|]
|
2014-10-16 04:31:59 +00:00
|
|
|
+ BottomOfHeadBlocking -> Text.Julius.asJavascriptUrl
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ _render_a2rMh
|
2014-10-16 04:31:59 +00:00
|
|
|
+ -> Data.Monoid.mconcat
|
|
|
|
+ [Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\nbkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance(\""),
|
2014-10-16 04:31:59 +00:00
|
|
|
+ Text.Julius.toJavascript (rawJS theId),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
2014-10-16 04:31:59 +00:00
|
|
|
+ "\")});")])
|
|
|
|
+
|
|
|
|
+ _ -> Text.Julius.asJavascriptUrl
|
2015-08-02 19:48:36 +00:00
|
|
|
+ (\ _render_a2rMm
|
2014-10-16 04:31:59 +00:00
|
|
|
+ -> Data.Monoid.mconcat
|
|
|
|
+ [Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
|
|
|
+ "\n(function(){new nicEditor({fullPanel:true}).panelInstance(\""),
|
2014-10-16 04:31:59 +00:00
|
|
|
+ Text.Julius.toJavascript (rawJS theId),
|
|
|
|
+ Text.Julius.Javascript
|
2015-08-02 19:48:36 +00:00
|
|
|
+ ((Data.Text.Lazy.Builder.fromText
|
|
|
|
+ . Text.Shakespeare.pack')
|
2014-10-16 04:31:59 +00:00
|
|
|
+ "\")})();")])
|
|
|
|
+
|
|
|
|
, fieldEnctype = UrlEncoded
|
|
|
|
}
|
|
|
|
where
|
2014-10-14 04:16:38 +00:00
|
|
|
--
|
2015-08-02 19:48:36 +00:00
|
|
|
2.1.1
|
2014-10-14 04:16:38 +00:00
|
|
|
|