summaryrefslogtreecommitdiff
path: root/elm3/ProdEdit/General.elm
blob: 19ca79b716e354a6e73f8a3f9851690c08d285a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module ProdEdit.General exposing (..)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Lib.Html exposing (..)
import Lib.Gen exposing (languages, weburlPattern, producerTypes, ProdEdit)
import Lib.Util exposing (..)


type alias Model =
  { desc    : String
  , l_wp    : String
  , lang    : String
  , ptype   : String
  , website : String
  }


init : ProdEdit -> Model
init d =
  { desc    = d.desc
  , l_wp    = d.l_wp
  , lang    = d.lang
  , ptype   = d.ptype
  , website = d.website
  }


new : Model
new =
  { desc    = ""
  , l_wp    = ""
  , lang    = "ja"
  , ptype   = "co"
  , website = ""
  }


type Msg
  = Desc String
  | LWP String
  | Lang String
  | PType String
  | Website String


update : Msg -> Model -> Model
update msg model =
  case msg of
    Desc s    -> { model | desc    = s }
    LWP s     -> { model | l_wp    = s }
    Lang s    -> { model | lang    = s }
    PType s   -> { model | ptype   = s }
    Website s -> { model | website = s }


view : Model -> (Msg -> a) -> List (Html a) -> Html a
view model wrap names = card "general" "General info" [] <|
  names ++ List.map (Html.map wrap)
  [ cardRow "Meta" Nothing <| formGroups
    [ [ label [for "ptype"] [ text "Type" ]
      , inputSelect [id "ptype", name "ptype", onInput PType] model.ptype producerTypes
      ]
    , [ label [for "lang"] [ text "Primary language" ]
      , inputSelect [id "lang", name "lang", onInput Lang] model.lang languages
      ]
    , [ label [for "website"] [ text "Official Website" ]
      , inputText "website" model.website Website [pattern weburlPattern]
      ]
    , [ label [] [ text "Wikipedia" ]
      , p [] [ text "https://en.wikipedia.org/wiki/", inputText "l_wp" model.l_wp LWP [class "form-control--inline", maxlength 100] ]
      ]
    ]

  , cardRow "Description" (Just "English please!") <| formGroup
    [ inputTextArea "desc" model.desc Desc [rows 8] ]
  ]