mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Prefill share mail form
To have access to the translated content, the messages must be given to the update function. There is no way to set the values in the view.
This commit is contained in:
@ -252,8 +252,6 @@ isValid model =
|
||||
|
||||
type alias ViewConfig =
|
||||
{ withAttachments : Bool
|
||||
, subjectTemplate : Maybe String
|
||||
, bodyTemplate : Maybe String
|
||||
, textAreaClass : String
|
||||
, showCancel : Bool
|
||||
}
|
||||
@ -264,8 +262,6 @@ view2 texts settings model =
|
||||
let
|
||||
cfg =
|
||||
{ withAttachments = True
|
||||
, subjectTemplate = Nothing
|
||||
, bodyTemplate = Nothing
|
||||
, textAreaClass = ""
|
||||
, showCancel = True
|
||||
}
|
||||
@ -357,11 +353,6 @@ view texts settings cfg model =
|
||||
[ type_ "text"
|
||||
, class S.textInput
|
||||
, onInput SetSubject
|
||||
, if model.subject == "" then
|
||||
onFocus (SetSubject <| Maybe.withDefault "" cfg.subjectTemplate)
|
||||
|
||||
else
|
||||
class ""
|
||||
, value model.subject
|
||||
]
|
||||
[]
|
||||
@ -373,11 +364,7 @@ view texts settings cfg model =
|
||||
]
|
||||
, textarea
|
||||
[ onInput SetBody
|
||||
, if model.body == "" then
|
||||
value <| Maybe.withDefault "" cfg.bodyTemplate
|
||||
|
||||
else
|
||||
value model.body
|
||||
, value model.body
|
||||
, class S.textAreaInput
|
||||
, class cfg.textAreaClass
|
||||
]
|
||||
|
@ -26,7 +26,6 @@ import Comp.ShareView
|
||||
import Data.Flags exposing (Flags)
|
||||
import Data.Icons as Icons
|
||||
import Data.ItemQuery exposing (ItemQuery)
|
||||
import Data.SearchMode exposing (SearchMode)
|
||||
import Data.UiSettings exposing (UiSettings)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
@ -131,8 +130,8 @@ type alias UpdateResult =
|
||||
}
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> UpdateResult
|
||||
update flags msg model =
|
||||
update : Texts -> Flags -> Msg -> Model -> UpdateResult
|
||||
update texts flags msg model =
|
||||
case msg of
|
||||
CancelPublish ->
|
||||
{ model = model
|
||||
@ -155,7 +154,7 @@ update flags msg model =
|
||||
MailMsg lm ->
|
||||
let
|
||||
( mm, mc ) =
|
||||
Comp.ShareMail.update flags lm model.mailModel
|
||||
Comp.ShareMail.update texts.shareMail flags lm model.mailModel
|
||||
in
|
||||
{ model = { model | mailModel = mm }
|
||||
, cmd = Cmd.map MailMsg mc
|
||||
@ -204,7 +203,7 @@ update flags msg model =
|
||||
GetShareResp (Ok share) ->
|
||||
let
|
||||
( mm, mc ) =
|
||||
Comp.ShareMail.update flags (Comp.ShareMail.setMailInfo share) model.mailModel
|
||||
Comp.ShareMail.update texts.shareMail flags (Comp.ShareMail.setMailInfo share) model.mailModel
|
||||
in
|
||||
{ model =
|
||||
{ model
|
||||
|
@ -67,8 +67,8 @@ setMailInfo share =
|
||||
SetMailInfo share
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update texts flags msg model =
|
||||
case msg of
|
||||
MailMsg lm ->
|
||||
let
|
||||
@ -107,7 +107,22 @@ update flags msg model =
|
||||
defaultResult
|
||||
|
||||
SetMailInfo share ->
|
||||
( { model | share = share }, Cmd.none )
|
||||
let
|
||||
url =
|
||||
flags.config.baseUrl ++ Page.pageToString (SharePage share.id)
|
||||
|
||||
name =
|
||||
share.name
|
||||
|
||||
lm =
|
||||
Comp.ItemMail.setMailInfo
|
||||
(texts.subjectTemplate name)
|
||||
(texts.bodyTemplate url)
|
||||
|
||||
nm =
|
||||
{ model | share = share }
|
||||
in
|
||||
update texts flags (MailMsg lm) nm
|
||||
|
||||
SendMailResp (Ok res) ->
|
||||
if res.success then
|
||||
@ -138,19 +153,8 @@ update flags msg model =
|
||||
view : Texts -> Flags -> UiSettings -> Model -> Html Msg
|
||||
view texts flags settings model =
|
||||
let
|
||||
url =
|
||||
flags.config.baseUrl ++ (Page.pageToString <| SharePage model.share.id)
|
||||
|
||||
subject =
|
||||
texts.subjectTemplate model.share.name
|
||||
|
||||
body =
|
||||
texts.bodyTemplate url
|
||||
|
||||
cfg =
|
||||
{ withAttachments = False
|
||||
, subjectTemplate = Just subject
|
||||
, bodyTemplate = Just body
|
||||
, textAreaClass = "h-52"
|
||||
, showCancel = False
|
||||
}
|
||||
|
@ -110,8 +110,8 @@ loadShares =
|
||||
--- update
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||
update flags msg model =
|
||||
update : Texts -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||
update texts flags msg model =
|
||||
case msg of
|
||||
InitNewShare ->
|
||||
let
|
||||
@ -121,7 +121,7 @@ update flags msg model =
|
||||
share =
|
||||
Api.Model.ShareDetail.empty
|
||||
in
|
||||
update flags (FormMsg (Comp.ShareForm.setShare { share | enabled = True })) nm
|
||||
update texts flags (FormMsg (Comp.ShareForm.setShare { share | enabled = True })) nm
|
||||
|
||||
SetViewMode vm ->
|
||||
( { model | viewMode = vm, formError = FormErrorNone }
|
||||
@ -150,7 +150,7 @@ update flags msg model =
|
||||
in
|
||||
case action of
|
||||
Comp.ShareTable.Edit share ->
|
||||
setShare share flags model
|
||||
setShare texts share flags model
|
||||
|
||||
RequestDelete ->
|
||||
( { model | deleteConfirm = DeleteConfirmOn }, Cmd.none, Sub.none )
|
||||
@ -209,14 +209,14 @@ update flags msg model =
|
||||
( { model | loading = False, formError = FormErrorHttp err }, Cmd.none, Sub.none )
|
||||
|
||||
GetShareResp (Ok share) ->
|
||||
setShare share flags model
|
||||
setShare texts share flags model
|
||||
|
||||
GetShareResp (Err err) ->
|
||||
( { model | formError = FormErrorHttp err }, Cmd.none, Sub.none )
|
||||
|
||||
DeleteShareResp (Ok res) ->
|
||||
if res.success then
|
||||
update flags (SetViewMode Table) { model | loading = False }
|
||||
update texts flags (SetViewMode Table) { model | loading = False }
|
||||
|
||||
else
|
||||
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none, Sub.none )
|
||||
@ -227,13 +227,13 @@ update flags msg model =
|
||||
MailMsg lm ->
|
||||
let
|
||||
( mm, mc ) =
|
||||
Comp.ShareMail.update flags lm model.mailModel
|
||||
Comp.ShareMail.update texts.shareMail flags lm model.mailModel
|
||||
in
|
||||
( { model | mailModel = mm }, Cmd.map MailMsg mc, Sub.none )
|
||||
|
||||
|
||||
setShare : ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||
setShare share flags model =
|
||||
setShare : Texts -> ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||
setShare texts share flags model =
|
||||
let
|
||||
shareUrl =
|
||||
flags.config.baseUrl ++ Page.pageToString (SharePage share.id)
|
||||
@ -245,10 +245,10 @@ setShare share flags model =
|
||||
Ports.initClipboard (Comp.ShareView.clipboardData share)
|
||||
|
||||
( nm, nc, ns ) =
|
||||
update flags (FormMsg <| Comp.ShareForm.setShare share) nextModel
|
||||
update texts flags (FormMsg <| Comp.ShareForm.setShare share) nextModel
|
||||
|
||||
( nm2, nc2, ns2 ) =
|
||||
update flags (MailMsg <| Comp.ShareMail.setMailInfo share) nm
|
||||
update texts flags (MailMsg <| Comp.ShareMail.setMailInfo share) nm
|
||||
in
|
||||
( nm2, Cmd.batch [ initClipboard, nc, nc2 ], Sub.batch [ ns, ns2 ] )
|
||||
|
||||
|
Reference in New Issue
Block a user