Grand unification of modals

This commit is contained in:
Gregor Kleen 2018-10-05 13:11:00 +02:00
parent 57c313702c
commit 7068b3462e
8 changed files with 26 additions and 30 deletions

View File

@ -59,7 +59,7 @@ colDescription = sortable Nothing (i18nCell MsgCourseDescription)
$ \DBRow{ dbrOutput=(Entity cid Course{..}, _, _, _) } ->
case courseDescription of
Nothing -> mempty
(Just descr) -> cell $ modalStatic "Beschreibung" descr False
(Just descr) -> cell $ modal "Beschreibung" (Right $ toWidget descr)
colCShort :: IsDBTable m a => Colonnade _ CourseTableData (DBCell m a)
colCShort = sortable (Just "cshort") (i18nCell MsgCourseShort)
@ -73,7 +73,11 @@ colCShortDescr = sortable (Just "cshort") (i18nCell MsgCourseShort)
( case courseDescription of
Nothing -> mempty
(Just descr) -> cell
[whamlet|<span style="float:right"> ^{modalStatic "Beschreibung" descr False} |]
[whamlet|
$newline never
<span style="float:right">
^{modal "Beschreibung" (Right $ toWidget descr)}
|]
)
colTerm :: IsDBTable m a => Colonnade _ CourseTableData (DBCell m a)

View File

@ -76,7 +76,11 @@ courseCell (Course {..}) = anchorCell link name `mappend` desc
name = citext2widget courseName
desc = case courseDescription of
Nothing -> mempty
(Just descr) -> cell [whamlet| <span style="float:right"> ^{modalStatic "Beschreibung" descr False} |]
(Just descr) -> cell [whamlet|
$newline never
<span style="float:right">
^{modal "Beschreibung" (Right $ toWidget descr)}
|]
sheetCell :: IsDBTable m a => CourseLink -> SheetName -> DBCell m a
sheetCell crse shn =

View File

@ -2,26 +2,19 @@
module Handler.Utils.Templates where
import Data.Either (isLeft)
import Import.NoFoundation
lipsum :: WidgetT site IO ()
lipsum = $(widgetFile "widgets/lipsum")
modalStatic :: Html -> Html -> Bool -> WidgetT site IO ()
modalStatic modalTrigger modalContent modalDynamic = do
modalId <- newIdent
triggerId <- newIdent
$(widgetFile "widgets/modalStatic")
[whamlet|<div ##{triggerId}>#{modalTrigger}|] -- TODO: modalDynamic
modalWidget :: Html -> WidgetT site IO () -> Bool -> WidgetT site IO ()
modalWidget modalTrigger modalContent modalDynamic = do
modal :: WidgetT site IO () -> Either (Route site) (WidgetT site IO ()) -> WidgetT site IO ()
modal modalTrigger modalContent = do
let modalDynamic = isLeft modalContent
modalId <- newIdent
triggerId <- newIdent
$(widgetFile "widgets/modalWidget")
[whamlet|<div .btn ##{triggerId}>#{modalTrigger}|]
modal :: Html -> [Char] -> Bool -> WidgetT site IO ()
modal triggerId modalContent modalDynamic = do
modalId <- newIdent
$(widgetFile "widgets/modal")
case modalContent of
Left route -> [whamlet|<a .btn ##{triggerId} href=@{route}>^{modalTrigger}|]
Right content -> [whamlet|<div .btn ##{triggerId}>^{modalTrigger}|]

View File

@ -32,9 +32,5 @@
^{btnWdgt}
<li><br>
Modals:
^{modal "toggler1" "" True}
<a href=@{UsersR} .btn #toggler1>Klick mich für Ajax-Test
<noscript>(Für Modals bitte JS aktivieren)</noscript>
^{modal "toggler2" "Test Inhalt für Modal" False}
<div .btn #toggler2>Klick mich für Content-Test
<noscript>(Für Modals bitte JS aktivieren)</noscript>
^{modal "Klick mich für Ajax-Test" (Left UsersR)}
^{modal "Klick mich für Content-Test" (Right "Test Inhalt für Modal")}

View File

@ -51,7 +51,7 @@
.
<h2>
^{modalWidget "Alle Benutzerbezogenen Daten löschen" delWdgt False}
^{modal "Alle Benutzerbezogenen Daten löschen" (Right delWdgt)}
<p>
<h4>Hinweise:
<ul>

View File

@ -1,2 +0,0 @@
<div .modal.js-modal #modal-#{modalId} data-trigger=#{triggerId} data-closeable=true data-dynamic=#{modalDynamic}>
#{modalContent}

View File

@ -1,2 +0,0 @@
<div .modal.js-modal #modal-#{modalId} data-trigger=#{triggerId} data-closeable=true data-dynamic=#{modalDynamic}>
#{modalContent}

View File

@ -1,2 +1,5 @@
<div .modal.js-modal #modal-#{modalId} data-trigger=#{triggerId} data-closeable=true data-dynamic=#{modalDynamic}>
^{modalContent}
$case modalContent
$of Right content
^{content}
$of Left _