Advertisement
umuro

an elm spa view example

Mar 7th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. view : State -> Html Action
  3. view state =
  4.   case state.onDemand of
  5.     NoData -> viewDefault state
  6.     TeamListBulkAddViewState _ -> viewBulkAdd state
  7.  
  8. viewBulkAdd : State -> Html Action
  9. viewBulkAdd state =
  10.   RELM_VIEW(state,RELM_TeamListBulkAddView)
  11.  
  12. viewDefault : State -> Html Action
  13. viewDefault state =
  14.   div
  15.   [ css "overflow-x" "auto" ]
  16.   [ table
  17.       [ ]
  18.       [ thead
  19.         []
  20.         [ tr [] (tableHeaders state) ]
  21.       , tbody
  22.         []
  23.         (List.indexedMap (viewItem state.teamList state.mdl MDL_IDX) state.teamList)
  24.       ]
  25.   , Snackbar.view state.snackbar |> Html.map Snackbar
  26.   ]
  27.  
  28. tableHeaders
  29.     : { b | mdl : Mdl }
  30.     -> List (Html Action)
  31. tableHeaders state  =
  32.   [ th [] [] -- Navigation
  33.   , th [] [text "Rank"]
  34.   , th [] [text "Name"]
  35.   , th [] [text "Important"]
  36.   , th []
  37.     [ Button.render Mdl [MDL_IDX] state.mdl
  38.       [ Button.ripple
  39.       , Button.colored
  40.       , Button.raised
  41.       , css "float" "right"
  42.       , onClick EnterBulkAddView
  43.       ]
  44.       [ text "Bulk Add"]
  45.     ] -- Add/Remove  ]
  46.   ]
  47.  
  48. viewItem : TeamList -> Mdl -> Int -> Int -> Team -> Html Action
  49. viewItem teamList mdl baseIndex index item =
  50.   tr
  51.   [ ]
  52.   -- Navigation
  53.   [ td OurOptions.optionsNoVerticalPadding <| tableCellNavigation teamList mdl baseIndex index item
  54.   -- Data
  55.   , td OurOptions.optionsNoVerticalPadding
  56.     [ Textfield.render Mdl [baseIndex, index, MDL_IDX] mdl
  57.       [ Maybe.map toString item.rank
  58.           |> Maybe.withDefault "" |> Textfield.value
  59.       , Textfield.label "Rank"
  60.       , css "width" "3em"
  61.       , validateRank item teamList
  62.         |> resultToTextfieldError
  63.         |> (when <| not <| item.id == 0)
  64.       , onInput (UpdateRankAction index item)
  65.       , dispatch Batch
  66.       , onBlur  SortRankAction
  67.       ] []
  68.     ]
  69.   , td OurOptions.optionsNoVerticalPadding
  70.     [ Textfield.render Mdl [baseIndex, index, MDL_IDX] mdl
  71.       [ Textfield.value item.name
  72.       , Textfield.label "Name"
  73.       , validateName item teamList
  74.         |> resultToTextfieldError
  75.         |> (when <| not <| item.id == 0 && isBlank item.name)
  76.       , Textfield.text_
  77.       , onInput (UpdateNameAction index item)
  78.       ] []
  79.     ]
  80.   , td OurOptions.optionsNoVerticalPadding
  81.     [ Toggles.switch Mdl [baseIndex, index, MDL_IDX] mdl
  82.       [ Toggles.value item.isImportant
  83.       , Toggles.ripple
  84.       , onToggle (ToggleIsImportantAction index item)
  85.       ] [text "Important"]
  86.     ]
  87.   -- Add/Remove Buttons
  88.   , td OurOptions.optionsNoVerticalPadding <| tableCellActions teamList mdl baseIndex index item
  89.   ]
  90.  
  91. tableCellNavigation : a -> b -> c -> d -> e -> List f
  92. tableCellNavigation teamList mdl baseIndex index item =
  93.   [ ]
  94.  
  95. tableCellActions
  96.     : List Team
  97.     -> Mdl
  98.     -> Int
  99.     -> Int
  100.     -> Team
  101.     -> List (Html Action)
  102.  
  103. tableCellActions teamList mdl baseIndex index item =
  104.     [
  105.       if item.id == 0 then
  106.         Button.render Mdl [baseIndex, index, MDL_IDX] mdl
  107.           [ Button.fab
  108.           , Button.colored
  109.           , onClick (CreateAction index item)
  110.           , Button.disabled |> when (isErr <| Team.validate item teamList)
  111.           ]
  112.         [ i "add"]
  113.       else
  114.         Button.render Mdl [baseIndex, index, MDL_IDX] mdl
  115.         ( [ Button.minifab
  116.           , onClick (RemoveAction index item)
  117.           ]
  118.         )
  119.         [ i "remove"]
  120.     ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement