hamlet6to7

This commit is contained in:
Michael Snoyman 2011-01-19 23:05:06 +02:00
parent ba55a82d1a
commit adb2bef9c8
6 changed files with 113 additions and 112 deletions

View File

@ -79,14 +79,14 @@ fieldsToTable = mapFormXml $ mapM_ go
#else #else
[$hamlet| [$hamlet|
#endif #endif
%tr.$clazz.fi$ <tr .#{clazz fi}>
%td <td>
%label!for=$fiIdent.fi$ $fiLabel.fi$ <label for="#{fiIdent fi}">#{fiLabel fi}
.tooltip $fiTooltip.fi$ <div .tooltip>#{fiTooltip fi}
%td <td>
^fiInput.fi^ \^{fiInput fi}
$maybe fiErrors.fi err $maybe err <- fiErrors fi
%td.errors $err$ <td .errors>#{err}
|] |]
clazz fi = if fiRequired fi then "required" else "optional" clazz fi = if fiRequired fi then "required" else "optional"
@ -100,12 +100,12 @@ fieldsToDivs = mapFormXml $ mapM_ go
#else #else
[$hamlet| [$hamlet|
#endif #endif
.$clazz.fi$ <div .#{clazz fi}>
%label!for=$fiIdent.fi$ $fiLabel.fi$ <label for="#{fiIdent fi}">#{fiLabel fi}
.tooltip $fiTooltip.fi$ <div .tooltip>#{fiTooltip fi}
^fiInput.fi^ \^{fiInput fi}
$maybe fiErrors.fi err $maybe err <- fiErrors fi
%div.errors $err$ <div .errors>#{err}
|] |]
clazz fi = if fiRequired fi then "required" else "optional" clazz fi = if fiRequired fi then "required" else "optional"
@ -142,7 +142,7 @@ runFormPost f = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%input!type=hidden!name=$nonceName$!value=$nonce$ <input type="hidden" name="#{nonceName}" value="#{nonce}">
|] |]
nonceName :: String nonceName :: String
@ -182,13 +182,13 @@ runFormTable dest inputLabel form = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%form!method=post!action=@dest@!enctype=$enctype$ <form method="post" action="@{dest}" enctype="#{enctype}">
%table <table>
^widget^ \^{widget}
%tr <tr>
%td!colspan=2 <td colspan="2">
$nonce$ \#{nonce}
%input!type=submit!value=$inputLabel$ <input type="submit" value="#{inputLabel}">
|] |]
return (res, widget') return (res, widget')
@ -203,11 +203,11 @@ runFormDivs dest inputLabel form = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%form!method=post!action=@dest@!enctype=$enctype$ <form method="post" action="@{dest}" enctype="#{enctype}">
^widget^ \^{widget}
%div <div>
$nonce$ \#{nonce}
%input!type=submit!value=$inputLabel$ <input type="submit" value="#{inputLabel}">
|] |]
return (res, widget') return (res, widget')
@ -233,7 +233,7 @@ generateForm f = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%input!type=hidden!name=$nonceName$!value=$nonce$ <input type="hidden" name="#{nonceName}" value="#{nonce}">
|]) |])
-- | Run a form against GET parameters. -- | Run a form against GET parameters.

View File

@ -147,7 +147,7 @@ boolField ffs orig = toForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%input#$theId$!type=checkbox!name=$name$!:val:checked <input id="#{theId}" type="checkbox" name="#{name}" :val:checked="">
|] |]
, fiErrors = case res of , fiErrors = case res of
FormFailure [x] -> Just $ string x FormFailure [x] -> Just $ string x
@ -196,10 +196,10 @@ selectField pairs ffs initial = toForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%select#$theId$!name=$name$ <select id="#{theId}" name="#{name}">
%option!value=none <option value="none">
$forall pairs' pair $forall pair <- pairs'
%option!value=$show.fst.pair$!:isSelected.fst.snd.pair:selected $snd.snd.pair$ <option value="#{show (fst pair)}" :isSelected (fst (snd pair)):selected="">#{snd (snd pair)}
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = string label { fiLabel = string label
@ -246,10 +246,10 @@ maybeSelectField pairs ffs initial' = toForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%select#$theId$!name=$name$ <select id="#{theId}" name="#{name}">
%option!value=none <option value="none">
$forall pairs' pair $forall pair <- pairs'
%option!value=$show.fst.pair$!:isSelected.fst.snd.pair:selected $snd.snd.pair$ <option value="#{show (fst pair)}" :isSelected (fst (snd pair)):selected="">#{snd (snd pair)}
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = string label { fiLabel = string label
@ -287,7 +287,7 @@ boolInput n = GForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%input#$n$!type=checkbox!name=$n$ <input id="#{n}" type="checkbox" name="#{n}">
|] |]
return (res, [xml], UrlEncoded) return (res, [xml], UrlEncoded)
@ -407,7 +407,7 @@ fileWidget theId name isReq =
#else #else
[$hamlet| [$hamlet|
#endif #endif
%input#$theId$!type=file!name=$name$!:isReq:required <input id="#{theId}" type="file" name="#{name}" :isReq:required="">
|] |]
radioField :: (Eq x, IsForm f, FormType f ~ x) radioField :: (Eq x, IsForm f, FormType f ~ x)
@ -442,11 +442,11 @@ radioField pairs ffs initial = toForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%div#$theId$ <div id="#{theId}">
$forall pairs' pair $forall pair <- pairs'
%div <div>
%input#$theId$-$show.fst.pair$!type=radio!name=$name$!value=$show.fst.pair$!:isSelected.fst.snd.pair:checked <input id="#{theId}-#{show (fst pair)}" type="radio" name="#{name}" value="#{show (fst pair)}" :isSelected (fst (snd pair)):checked="">
%label!for=$name$-$show.fst.pair$ $snd.snd.pair$ <label for="#{name}-#{show (fst pair)}">#{snd (snd pair)}
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = string label { fiLabel = string label
@ -499,13 +499,13 @@ maybeRadioField pairs ffs initial' = toForm $ do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%div#$theId$ <div id="#{theId}">
$forall pairs' pair $forall pair <- pairs'
%div <div>
%input#$theId$-none!type=radio!name=$name$!value=none!:isNone:checked None <input id="#{theId}-none" type="radio" name="#{name}" value="none" :isNone:checked="">None
%div <div>
%input#$theId$-$show.fst.pair$!type=radio!name=$name$!value=$show.fst.pair$!:isSelected.fst.snd.pair:checked <input id="#{theId}-#{show (fst pair)}" type="radio" name="#{name}" value="#{show (fst pair)}" :isSelected (fst (snd pair)):checked="">
%label!for=$name$-$show.fst.pair$ $snd.snd.pair$ <label for="#{name}-#{show (fst pair)}">#{snd (snd pair)}
|] |]
let fi = FieldInfo let fi = FieldInfo
{ fiLabel = string label { fiLabel = string label

View File

@ -87,8 +87,8 @@ jqueryDayFieldProfile jds = FieldProfile
. readMay . readMay
, fpRender = show , fpRender = show
, fpWidget = \theId name val isReq -> do , fpWidget = \theId name val isReq -> do
addHtml [HAMLET| addHtml [HAMLET|\
%input#$theId$!name=$name$!type=date!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="date" :isReq:required="" value="#{val}">
|] |]
addScript' urlJqueryJs addScript' urlJqueryJs
addScript' urlJqueryUiJs addScript' urlJqueryUiJs
@ -145,8 +145,8 @@ jqueryDayTimeFieldProfile = FieldProfile
{ fpParse = parseUTCTime { fpParse = parseUTCTime
, fpRender = jqueryDayTimeUTCTime , fpRender = jqueryDayTimeUTCTime
, fpWidget = \theId name val isReq -> do , fpWidget = \theId name val isReq -> do
addHtml [HAMLET| addHtml [HAMLET|\
%input#$theId$!name=$name$!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" :isReq:required="" value="#{val}">
|] |]
addScript' urlJqueryJs addScript' urlJqueryJs
addScript' urlJqueryUiJs addScript' urlJqueryUiJs
@ -189,8 +189,8 @@ jqueryAutocompleteFieldProfile src = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> do , fpWidget = \theId name val isReq -> do
addHtml [HAMLET| addHtml [HAMLET|\
%input.autocomplete#$theId$!name=$name$!type=text!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="text" :isReq:required="" value="#{val}" .autocomplete>
|] |]
addScript' urlJqueryJs addScript' urlJqueryJs
addScript' urlJqueryUiJs addScript' urlJqueryUiJs

View File

@ -43,7 +43,7 @@ nicHtmlFieldProfile = FieldProfile
#else #else
[$hamlet| [$hamlet|
#endif #endif
%textarea.html#$theId$!name=$name$ $val$ <textarea id="#{theId}" name="#{name}" .html>#{val}
|] |]
addScript' urlNicEdit addScript' urlNicEdit
addJulius addJulius
@ -52,7 +52,7 @@ nicHtmlFieldProfile = FieldProfile
#else #else
[$julius| [$julius|
#endif #endif
bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("%theId%")}); bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")});
|] |]
} }

View File

@ -56,8 +56,8 @@ intFieldProfile = FieldProfile
{ fpParse = maybe (Left "Invalid integer") Right . readMayI { fpParse = maybe (Left "Invalid integer") Right . readMayI
, fpRender = showI , fpRender = showI
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=number!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="number" :isReq:required="" value="#{val}">
|] |]
} }
where where
@ -71,8 +71,8 @@ doubleFieldProfile = FieldProfile
{ fpParse = maybe (Left "Invalid number") Right . readMay { fpParse = maybe (Left "Invalid number") Right . readMay
, fpRender = show , fpRender = show
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=text!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="text" :isReq:required="" value="#{val}">
|] |]
} }
@ -81,8 +81,8 @@ dayFieldProfile = FieldProfile
{ fpParse = parseDate { fpParse = parseDate
, fpRender = show , fpRender = show
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=date!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="date" :isReq:required="" value="#{val}">
|] |]
} }
@ -91,8 +91,8 @@ timeFieldProfile = FieldProfile
{ fpParse = parseTime { fpParse = parseTime
, fpRender = show . roundFullSeconds , fpRender = show . roundFullSeconds
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" :isReq:required="" value="#{val}">
|] |]
} }
where where
@ -106,8 +106,8 @@ htmlFieldProfile = FieldProfile
{ fpParse = Right . preEscapedString . sanitizeBalance { fpParse = Right . preEscapedString . sanitizeBalance
, fpRender = renderHtml , fpRender = renderHtml
, fpWidget = \theId name val _isReq -> addHamlet , fpWidget = \theId name val _isReq -> addHamlet
[HAMLET| [HAMLET|\
%textarea.html#$theId$!name=$name$ $val$ <textarea id="#{theId}" name="#{name}" .html>#{val}
|] |]
} }
@ -133,8 +133,8 @@ textareaFieldProfile = FieldProfile
{ fpParse = Right . Textarea { fpParse = Right . Textarea
, fpRender = unTextarea , fpRender = unTextarea
, fpWidget = \theId name val _isReq -> addHamlet , fpWidget = \theId name val _isReq -> addHamlet
[HAMLET| [HAMLET|\
%textarea#$theId$!name=$name$ $val$ <textarea id="#{theId}" name="#{name}">#{val}
|] |]
} }
@ -143,8 +143,8 @@ hiddenFieldProfile = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpWidget = \theId name val _isReq -> addHamlet , fpWidget = \theId name val _isReq -> addHamlet
[HAMLET| [HAMLET|\
%input!type=hidden#$theId$!name=$name$!value=$val$ <input type="hidden" id="#{theId}" name="#{name}" value="#{val}">
|] |]
} }
@ -153,8 +153,8 @@ stringFieldProfile = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=text!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="text" :isReq:required="" value="#{val}">
|] |]
} }
@ -163,8 +163,8 @@ passwordFieldProfile = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=password!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="password" :isReq:required="" value="#{val}">
|] |]
} }
@ -213,8 +213,8 @@ emailFieldProfile = FieldProfile
else Left "Invalid e-mail address" else Left "Invalid e-mail address"
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=email!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="email" :isReq:required="" value="#{val}">
|] |]
} }
@ -224,11 +224,12 @@ searchFieldProfile autoFocus = FieldProfile
{ fpParse = Right { fpParse = Right
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> do , fpWidget = \theId name val isReq -> do
addHtml [HAMLET| addHtml [HAMLET|\
%input#$theId$!name=$name$!type=search!:isReq:required!:autoFocus:autofocus!value=$val$ <input id="#{theId}" name="#{name}" type="search" :isReq:required="" :autoFocus:autofocus="" value="#{val}">
|] |]
when autoFocus $ do when autoFocus $ do
addHtml $ [HAMLET|\<script>if (!('autofocus' in document.createElement('input'))) {document.getElementById('$theId$').focus();}</script> |] addHtml $ [HAMLET|\<script>if (!('autofocus' in document.createElement('input'))) {document.getElementById('#{theId}').focus();}</script>
|]
addCassius [CASSIUS| addCassius [CASSIUS|
#$theId$ #$theId$
-webkit-appearance: textfield -webkit-appearance: textfield
@ -242,7 +243,7 @@ urlFieldProfile = FieldProfile
Just _ -> Right s Just _ -> Right s
, fpRender = id , fpRender = id
, fpWidget = \theId name val isReq -> addHamlet , fpWidget = \theId name val isReq -> addHamlet
[HAMLET| [HAMLET|\
%input#$theId$!name=$name$!type=url!:isReq:required!value=$val$ <input id="#{theId}" name="#{name}" type="url" :isReq:required="" value="#{val}">
|] |]
} }

View File

@ -67,14 +67,14 @@ getCrudListR = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%h1 Items <h1>Items
%ul <ul>
$forall items item $forall item <- items
%li <li>
%a!href=@toMaster.CrudEditR.toSinglePiece.fst.item@ <a href="@{toMaster (CrudEditR (toSinglePiece (fst item)))}">
$itemTitle.snd.item$ \#{itemTitle (snd item)}
%p <p>
%a!href=@toMaster.CrudAddR@ Add new item <a href="@{toMaster CrudAddR}">Add new item
|] |]
getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item), getCrudAddR :: (Yesod master, Item item, SinglePiece (Key item),
@ -132,13 +132,13 @@ getCrudDeleteR s = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%form!method=post!action=@toMaster.CrudDeleteR.s@ <form method="post" action="@{toMaster (CrudDeleteR s)}">
%h1 Really delete? <h1>Really delete?
%p Do you really want to delete $itemTitle.item$? <p>Do you really want to delete #{itemTitle item}?
%p <p>
%input!type=submit!value=Yes <input type="submit" value="Yes">
\ $ \
%a!href=@toMaster.CrudListR@ No <a href="@{toMaster CrudListR}">No
|] |]
postCrudDeleteR :: (Yesod master, Item item, SinglePiece (Key item)) postCrudDeleteR :: (Yesod master, Item item, SinglePiece (Key item))
@ -179,19 +179,19 @@ crudHelper title me isPost = do
#else #else
[$hamlet| [$hamlet|
#endif #endif
%p <p>
%a!href=@toMaster.CrudListR@ Return to list <a href="@{toMaster CrudListR}">Return to list
%h1 $title$ <h1>#{title}
%form!method=post!enctype=$enctype$ <form method="post" enctype="#{enctype}">
%table <table>
^form^ \^{form}
%tr <tr>
%td!colspan=2 <td colspan="2">
$hidden$ \#{hidden}
%input!type=submit <input type="submit">
$maybe me e $maybe e <- me
\ $ \
%a!href=@toMaster.CrudDeleteR.toSinglePiece.fst.e@ Delete <a href="@{toMaster (CrudDeleteR (toSinglePiece (fst e)))}">Delete
|] |]
-- | A default 'Crud' value which relies about persistent and "Yesod.Form". -- | A default 'Crud' value which relies about persistent and "Yesod.Form".