aboutsummaryrefslogtreecommitdiff
path: root/src/client/Dialog/AddCategory/Model.elm
diff options
context:
space:
mode:
authorJoris2017-03-26 21:10:42 +0200
committerJoris2017-03-26 21:10:42 +0200
commit1e47a7754ca38bd1a6c74765d8378caf68ce4619 (patch)
treed0d9238479dc2529a1b558bbbcde346e7e8c2935 /src/client/Dialog/AddCategory/Model.elm
parentc0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (diff)
downloadbudget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.gz
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.bz2
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.zip
Separate client and server watch
Diffstat (limited to 'src/client/Dialog/AddCategory/Model.elm')
-rw-r--r--src/client/Dialog/AddCategory/Model.elm52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/client/Dialog/AddCategory/Model.elm b/src/client/Dialog/AddCategory/Model.elm
new file mode 100644
index 0000000..7496c2b
--- /dev/null
+++ b/src/client/Dialog/AddCategory/Model.elm
@@ -0,0 +1,52 @@
+module Dialog.AddCategory.Model exposing
+ ( Model
+ , init
+ , initialAdd
+ , initialClone
+ , initialEdit
+ , validation
+ )
+
+import Date exposing (Date)
+import View.Date as Date
+
+import Form exposing (Form)
+import Form.Field as Field exposing (Field)
+import Form.Validate as Validate exposing (Validation)
+
+import Model.Translations exposing (Translations)
+import Model.Category exposing (Category, CategoryId)
+
+type alias Model =
+ { id : Maybe CategoryId
+ , name : String
+ , color : String
+ }
+
+init : Form String Model
+init = Form.initial [] validation
+
+initialAdd : Translations -> List (String, Field)
+initialAdd translations =
+ [ ("color", Field.string "#000000")
+ ]
+
+initialClone : Translations -> Category -> List (String, Field)
+initialClone translations category =
+ [ ("name", Field.string category.name)
+ , ("color", Field.string category.color)
+ ]
+
+initialEdit : Translations -> CategoryId -> Category -> List (String, Field)
+initialEdit translations categoryId category =
+ [ ("id", Field.string (toString categoryId))
+ , ("name", Field.string category.name)
+ , ("color", Field.string category.color)
+ ]
+
+validation : Validation String Model
+validation =
+ Validate.map3 Model
+ (Validate.field "id" (Validate.maybe Validate.int))
+ (Validate.field "name" (Validate.string |> Validate.andThen Validate.nonEmpty))
+ (Validate.field "color" (Validate.string |> Validate.andThen Validate.nonEmpty))