View difference between Paste ID: n25q2aq2 and inYGL3Rj
SHOW: | | - or go back to the newest paste.
1
splices :: Monad m => View Text -> Splices (Splice m)
2
splices v = do
3
	"dfInputText" ## dfInputText v
4
	"dfSubView" ## dfSubView splices v
5
	"dfInputList" ## dfInputList splices v
6
7-
dfInputList :: Monad m => (View Text -> Splices (Splice m)) -> View Text -> Splice m
7+
dfInputList :: MonadIO m => (View Text -> Splices (Splice m)) -> View Text -> Splice m
8-
dfInputList = undefined
8+
dfInputList userSplices view = do
9
    (ref, _) <- getRefAttributes Nothing
10
    let listRef = absoluteRef ref view
11
        listAttrs =
12
            [ ("id", listRef)
13
            , ("class", "inputList")
14
            ]
15
        addControl _ = return $ disableOnclick ref view
16
            [ ("onclick", T.concat [ "addInputListItem(this, '"
17
                                   , listRef
18
                                   , "'); return false;"] ) ]
19
        removeControl _ = return $ disableOnclick ref view
20
            [ ("onclick", T.concat [ "removeInputListItem(this, '"
21
                                   , listRef
22
                                   , "'); return false;"] ) ]
23
        itemAttrs v _ = return
24
            [ ("id", T.concat [listRef, ".", last $ "0" : viewContext v])
25
            , ("class", T.append listRef ".inputListItem")
26
            ]
27
        templateAttrs v _ = return
28
            [ ("id", T.concat [listRef, ".", last $ "-1" : viewContext v])
29
            , ("class", T.append listRef ".inputListTemplate")
30
            , ("style", "display: none;")
31
            ]
32
        items = listSubViews ref view
33
        f attrs v = localHS (bindAttributeSplices ("itemAttrs" ## attrs v) .
34
                       bindDigestiveSplices v) runChildren
35
        dfListItem = do
36
            template <- f templateAttrs (makeListSubView ref (-1) view)
37
            res <- mapSplices (f itemAttrs) items
38
            return $ template ++ res
39
        attrSplices = do
40
            "addControl"    ## addControl
41
            "removeControl" ## removeControl
42
    nodes <- localHS (bindSplices (("dfListItem" ## dfListItem) <> userSplices view) .
43
                      bindAttributeSplices attrSplices) runChildren
44
    let indices = [X.Element "input"
45
                    [ ("type", "hidden")
46
                    , ("name", T.intercalate "." [listRef, indicesRef])
47
                    , ("value", T.intercalate "," $ map
48
                        (last . ("0":) . viewContext) items)
49
                    ] []
50
                  ]
51
    return [X.Element "div" listAttrs (indices ++ nodes)]
52
53
splices' :: Monad m => View Text -> Splices (Splice m)
54
splices' v = do
55
	"dfInputText" ## dfInputText v
56
	"dfSubView" ## dfSubView splices v
57
	"dfInputList" ## dfInputList splices v
58
	"foo" ## undefined