@@ -16,6 +16,7 @@ import Pages.Loader exposing (loader)
1616import Pages.Login as Login
1717import Pages.MasterPassword as MasterPassword
1818import Pages.Navigation as Navigation exposing (TopButton(..))
19+import Pages.SelectCipherType as SelectCipherType
1920import Task
2021import Time
2122import Types exposing (CipherId)
@@ -58,8 +59,12 @@ type Msg
5859 | UpdateLastNotificatioTime Time.Posix
5960 | EditCipher Bridge.FullCipher
6061 | UpdateCipher Bridge.FullCipher
62+ | CreateCipher Bridge.FullCipher
6163 | FireGlobalEvent Event
6264 | GeneratePassword Bridge.PasswordGeneratorConfig
65+ | CreateNewCipher
66+ | SelectCipherTypeMsg SelectCipherType.Msg
67+ | OpenNewCipherEditPage Bridge.CipherType
6368
6469
6570type alias Model =
@@ -79,10 +84,11 @@ type PageModel
7984 = LoginModel Login.Model
8085 | LoadingPage
8186 | CiphersModel Ciphers.Model
82− | EditCipherModel EditCipher.Model
87+ | EditCipherModel (EditCipher.Model Msg)
8388 | MasterPasswordModel MasterPassword.Model
8489 | CipherModel Cipher.Model
8590 | CaptchaModel Captcha.Model
91+ | SelectCipherTypeModel SelectCipherType.Model
8692
8793
8894showPage :
@@ -162,13 +168,23 @@ showPage email page =
162168 EditCipherModel model ->
163169 let
164170 p =
165− EditCipher.page editCipherCallbacks EditCipherMsg
171+ EditCipher.page EditCipherMsg
166172 in
167173 { title = p.title model
168174 , body = p.view model
169175 , topButton = Just (BackButton { action = PopView, icon = Just "close" })
170176 }
171177
178+ SelectCipherTypeModel model ->
179+ let
180+ p =
181+ SelectCipherType.page selectCipherTypeCallbacks SelectCipherTypeMsg
182+ in
183+ { title = p.title model
184+ , body = p.view model
185+ , topButton = Just simpleBackButton
186+ }
187+
172188
173189main : Program () Model Msg
174190main =
@@ -263,6 +279,9 @@ doNotStoreInHistory page =
263279 LoadingPage ->
264280 True
265281
282+ SelectCipherTypeModel _ ->
283+ True
284+
266285 _ ->
267286 False
268287
@@ -388,8 +407,6 @@ update msg model =
388407 , cmd
389408 )
390409
391− -- (Ciphers.page ciphersCallbacks CiphersMsg).init ciphers
392− -- |> Tuple.mapFirst (\pageModel -> appendPageStack <| CiphersModel pageModel)
393410 OpenCiphersScreen ->
394411 ( appendPageStack <| LoadingPage, Cmd.batch [ sendBridge Bridge.NeedCiphersList, sendBridge Bridge.NeedEmail ] )
395412
@@ -425,7 +442,7 @@ update msg model =
425442 EditCipherMsg imsg ->
426443 case currentPage of
427444 EditCipherModel page ->
428− (EditCipher.page editCipherCallbacks EditCipherMsg).update imsg page |> processPage EditCipherModel
445+ (EditCipher.page EditCipherMsg).update imsg page |> processPage EditCipherModel
429446
430447 _ ->
431448 ( model, Cmd.none )
@@ -479,7 +496,7 @@ update msg model =
479496 ( model, Cmd.none )
480497
481498 EditCipher cipher ->
482− (EditCipher.page editCipherCallbacks EditCipherMsg).init cipher
499+ (EditCipher.page EditCipherMsg).init { fullCipher = cipher, callbacks = editCipherCallbacks }
483500 |> Tuple.mapFirst (\pageModel -> keepStackWith <| EditCipherModel pageModel)
484501
485502 UpdateCipher cipher ->
@@ -491,6 +508,14 @@ update msg model =
491508 ]
492509 )
493510
511+ CreateCipher cipher ->
512+ ( model
513+ , Cmd.batch
514+ [ Bridge.CreateCipher cipher |> sendBridge
515+ , PopView |> pureCmd
516+ ]
517+ )
518+
494519 FireGlobalEvent ev ->
495520 ( { model
496521 | pageStack =
@@ -514,10 +539,13 @@ update msg model =
514539 (Cipher.page cipherCallbacks CipherMsg).event m ev |> CipherModel
515540
516541 EditCipherModel m ->
517− (EditCipher.page editCipherCallbacks EditCipherMsg).event m ev |> EditCipherModel
542+ (EditCipher.page EditCipherMsg).event m ev |> EditCipherModel
518543
519544 CaptchaModel m ->
520545 (Captcha.page captchaCallbacks CaptchaMsg).event m ev |> CaptchaModel
546+
547+ SelectCipherTypeModel m ->
548+ (SelectCipherType.page selectCipherTypeCallbacks SelectCipherTypeMsg).event m ev |> SelectCipherTypeModel
521549 )
522550 }
523551 , Cmd.none
@@ -526,6 +554,73 @@ update msg model =
526554 GeneratePassword cfg ->
527555 ( model, FFI.sendBridge (Bridge.GeneratePassword cfg) )
528556
557+ SelectCipherTypeMsg imsg ->
558+ case currentPage of
559+ SelectCipherTypeModel page ->
560+ (SelectCipherType.page selectCipherTypeCallbacks SelectCipherTypeMsg).update imsg page |> processPage SelectCipherTypeModel
561+
562+ _ ->
563+ ( model, Cmd.none )
564+
565+ CreateNewCipher ->
566+ (SelectCipherType.page selectCipherTypeCallbacks SelectCipherTypeMsg).init ()
567+ |> Tuple.mapFirst (\pageModel -> appendPageStack <| SelectCipherTypeModel pageModel)
568+
569+ OpenNewCipherEditPage t ->
570+ (EditCipher.page EditCipherMsg).init
571+ { callbacks = createCipherCallbacks
572+ , fullCipher =
573+ { reprompt = 0
574+ , favorite = False
575+ , id = ""
576+ , name = ""
577+ , cipher =
578+ case t of
579+ Bridge.LoginType ->
580+ Bridge.LoginCipher
581+ { uris = []
582+ , username = Nothing
583+ , password = Nothing
584+ }
585+
586+ Bridge.NoteType ->
587+ Bridge.NoteCipher ""
588+
589+ Bridge.CardType ->
590+ Bridge.CardCipher
591+ { cardholderName = Nothing
592+ , brand = Nothing
593+ , number = Nothing
594+ , expMonth = Nothing
595+ , expYear = Nothing
596+ , code = Nothing
597+ }
598+
599+ Bridge.IdentityType ->
600+ Bridge.IdentityCipher
601+ { title = Nothing
602+ , firstName = Nothing
603+ , middleName = Nothing
604+ , lastName = Nothing
605+ , address1 = Nothing
606+ , address2 = Nothing
607+ , address3 = Nothing
608+ , city = Nothing
609+ , state = Nothing
610+ , postalCode = Nothing
611+ , country = Nothing
612+ , company = Nothing
613+ , email = Nothing
614+ , phone = Nothing
615+ , ssn = Nothing
616+ , username = Nothing
617+ , passportNumber = Nothing
618+ , licenseNumber = Nothing
619+ }
620+ }
621+ }
622+ |> Tuple.mapFirst (\pageModel -> keepStackWith <| EditCipherModel pageModel)
623+
529624
530625loginCallbacks : Login.Callbacks Msg
531626loginCallbacks =
@@ -534,7 +629,10 @@ loginCallbacks =
534629
535630ciphersCallbacks : Ciphers.Callbacks Msg
536631ciphersCallbacks =
537− { selected = RequestCipher, logOut = NeedsReset }
632+ { selected = RequestCipher
633+ , logOut = NeedsReset
634+ , createNewCipher = CreateNewCipher
635+ }
538636
539637
540638cipherCallbacks : Cipher.Callbacks Msg
@@ -547,6 +645,11 @@ editCipherCallbacks =
547645 { save = UpdateCipher, generatePassword = GeneratePassword }
548646
549647
648+createCipherCallbacks : EditCipher.Callbacks Msg
649+createCipherCallbacks =
650+ { save = CreateCipher, generatePassword = GeneratePassword }
651+
652+
550653captchaCallbacks : Captcha.Callbacks
551654captchaCallbacks =
552655 {}
@@ -557,3 +660,8 @@ masterPasswordCallbacks =
557660 { submit = SendMasterPassword
558661 , reset = NeedsReset
559662 }
663+
664+
665+selectCipherTypeCallbacks : SelectCipherType.Callbacks Msg
666+selectCipherTypeCallbacks =
667+ { choose = OpenNewCipherEditPage }