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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ nicHtmlFieldProfile = FieldProfile
#else
[$hamlet|
#endif
%textarea.html#$theId$!name=$name$ $val$
<textarea id="#{theId}" name="#{name}" .html>#{val}
|]
addScript' urlNicEdit
addJulius
@ -52,7 +52,7 @@ nicHtmlFieldProfile = FieldProfile
#else
[$julius|
#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
, fpRender = showI
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=number!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="number" :isReq:required="" value="#{val}">
|]
}
where
@ -71,8 +71,8 @@ doubleFieldProfile = FieldProfile
{ fpParse = maybe (Left "Invalid number") Right . readMay
, fpRender = show
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=text!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="text" :isReq:required="" value="#{val}">
|]
}
@ -81,8 +81,8 @@ dayFieldProfile = FieldProfile
{ fpParse = parseDate
, fpRender = show
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=date!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="date" :isReq:required="" value="#{val}">
|]
}
@ -91,8 +91,8 @@ timeFieldProfile = FieldProfile
{ fpParse = parseTime
, fpRender = show . roundFullSeconds
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" :isReq:required="" value="#{val}">
|]
}
where
@ -106,8 +106,8 @@ htmlFieldProfile = FieldProfile
{ fpParse = Right . preEscapedString . sanitizeBalance
, fpRender = renderHtml
, fpWidget = \theId name val _isReq -> addHamlet
[HAMLET|
%textarea.html#$theId$!name=$name$ $val$
[HAMLET|\
<textarea id="#{theId}" name="#{name}" .html>#{val}
|]
}
@ -133,8 +133,8 @@ textareaFieldProfile = FieldProfile
{ fpParse = Right . Textarea
, fpRender = unTextarea
, fpWidget = \theId name val _isReq -> addHamlet
[HAMLET|
%textarea#$theId$!name=$name$ $val$
[HAMLET|\
<textarea id="#{theId}" name="#{name}">#{val}
|]
}
@ -143,8 +143,8 @@ hiddenFieldProfile = FieldProfile
{ fpParse = Right
, fpRender = id
, fpWidget = \theId name val _isReq -> addHamlet
[HAMLET|
%input!type=hidden#$theId$!name=$name$!value=$val$
[HAMLET|\
<input type="hidden" id="#{theId}" name="#{name}" value="#{val}">
|]
}
@ -153,8 +153,8 @@ stringFieldProfile = FieldProfile
{ fpParse = Right
, fpRender = id
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=text!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="text" :isReq:required="" value="#{val}">
|]
}
@ -163,8 +163,8 @@ passwordFieldProfile = FieldProfile
{ fpParse = Right
, fpRender = id
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=password!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="password" :isReq:required="" value="#{val}">
|]
}
@ -213,8 +213,8 @@ emailFieldProfile = FieldProfile
else Left "Invalid e-mail address"
, fpRender = id
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=email!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="email" :isReq:required="" value="#{val}">
|]
}
@ -224,11 +224,12 @@ searchFieldProfile autoFocus = FieldProfile
{ fpParse = Right
, fpRender = id
, fpWidget = \theId name val isReq -> do
addHtml [HAMLET|
%input#$theId$!name=$name$!type=search!:isReq:required!:autoFocus:autofocus!value=$val$
addHtml [HAMLET|\
<input id="#{theId}" name="#{name}" type="search" :isReq:required="" :autoFocus:autofocus="" value="#{val}">
|]
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|
#$theId$
-webkit-appearance: textfield
@ -242,7 +243,7 @@ urlFieldProfile = FieldProfile
Just _ -> Right s
, fpRender = id
, fpWidget = \theId name val isReq -> addHamlet
[HAMLET|
%input#$theId$!name=$name$!type=url!:isReq:required!value=$val$
[HAMLET|\
<input id="#{theId}" name="#{name}" type="url" :isReq:required="" value="#{val}">
|]
}

View File

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