Extract strings in item detail modals

This commit is contained in:
Eike Kettner 2021-04-26 22:02:45 +02:00
parent a98211af22
commit e3053549b3
8 changed files with 138 additions and 81 deletions

View File

@ -0,0 +1,60 @@
module Comp.ItemDetail.ConfirmModalView exposing (view)
import Comp.ConfirmModal
import Comp.ItemDetail.Model exposing (..)
import Html exposing (..)
import Messages.Comp.ItemDetail.ConfirmModal exposing (Texts)
view : Texts -> ConfirmModalValue -> Model -> Html Msg
view texts modal itemModel =
case modal of
ConfirmModalReprocessItem msg ->
Comp.ConfirmModal.view
(makeSettings texts
msg
ItemModalCancelled
(texts.confirmReprocessItem itemModel.item.state)
)
ConfirmModalReprocessFile msg ->
Comp.ConfirmModal.view
(makeSettings texts
msg
AttachModalCancelled
(texts.confirmReprocessFile itemModel.item.state)
)
ConfirmModalDeleteItem msg ->
Comp.ConfirmModal.view
(makeSettings texts
msg
ItemModalCancelled
texts.confirmDeleteItem
)
ConfirmModalDeleteFile msg ->
Comp.ConfirmModal.view
(makeSettings texts
msg
AttachModalCancelled
texts.confirmDeleteFile
)
ConfirmModalDeleteAllFiles msg ->
Comp.ConfirmModal.view
(makeSettings texts
msg
AttachModalCancelled
texts.confirmDeleteAllFiles
)
makeSettings : Texts -> Msg -> Msg -> String -> Comp.ConfirmModal.Settings Msg
makeSettings texts confirm cancel confirmMsg =
Comp.ConfirmModal.defaultSettings
confirm
cancel
texts.basics.ok
texts.basics.cancel
confirmMsg

View File

@ -1,5 +1,6 @@
module Comp.ItemDetail.Model exposing
( AttachmentRename
, ConfirmModalValue(..)
, MailSendResult(..)
, Model
, Msg(..)
@ -76,7 +77,7 @@ type alias Model =
, nameSaveThrottle : Throttle Msg
, notesModel : Maybe String
, notesField : NotesField
, itemModal : Maybe (Comp.ConfirmModal.Settings Msg)
, itemModal : Maybe ConfirmModalValue
, itemDatePicker : DatePicker
, itemDate : Maybe Int
, itemProposals : ItemProposals
@ -91,7 +92,7 @@ type alias Model =
, attachMeta : Dict String Comp.AttachmentMeta.Model
, attachMetaOpen : Bool
, pdfNativeView : Maybe Bool
, attachModal : Maybe (Comp.ConfirmModal.Settings Msg)
, attachModal : Maybe ConfirmModalValue
, addFilesOpen : Bool
, addFilesModel : Comp.Dropzone.Model
, selectedFiles : List File
@ -113,6 +114,14 @@ type alias Model =
}
type ConfirmModalValue
= ConfirmModalReprocessItem Msg
| ConfirmModalReprocessFile Msg
| ConfirmModalDeleteItem Msg
| ConfirmModalDeleteFile Msg
| ConfirmModalDeleteAllFiles Msg
type ViewMode
= SimpleView
| SelectView SelectViewModel

View File

@ -3,7 +3,7 @@ module Comp.ItemDetail.SingleAttachment exposing (view)
import Api
import Api.Model.Attachment exposing (Attachment)
import Comp.AttachmentMeta
import Comp.ConfirmModal
import Comp.ItemDetail.ConfirmModalView
import Comp.ItemDetail.Model exposing (Model, Msg(..), NotesField(..), SaveNameState(..), ViewMode(..))
import Comp.MenuBar as MB
import Data.UiSettings exposing (UiSettings)
@ -32,7 +32,7 @@ view texts settings model pos attach =
[ ( "hidden", not (attachmentVisible model pos) )
]
]
[ renderModal model
[ renderModal texts model
, div
[ class "flex flex-row px-2 py-2 text-sm"
, class S.border
@ -420,11 +420,11 @@ menuItem texts model pos attach =
]
renderModal : Model -> Html Msg
renderModal model =
renderModal : Texts -> Model -> Html Msg
renderModal texts model =
case model.attachModal of
Just confirmModal ->
Comp.ConfirmModal.view confirmModal
Just mm ->
Comp.ItemDetail.ConfirmModalView.view texts.confirmModal mm model
Nothing ->
span [ class "hidden" ] []

View File

@ -27,6 +27,7 @@ import Comp.ItemDetail.FieldTabState as FTabState
import Comp.ItemDetail.Model
exposing
( AttachmentRename
, ConfirmModalValue(..)
, MailSendResult(..)
, Model
, Msg(..)
@ -560,19 +561,7 @@ update key flags inav settings msg model =
resultModel { model | itemModal = Nothing }
RequestDelete ->
let
confirmMsg =
"Really delete this item? This cannot be undone."
confirm =
Comp.ConfirmModal.defaultSettings
DeleteItemConfirmed
ItemModalCancelled
"Ok"
"Cancel"
confirmMsg
in
resultModel { model | itemModal = Just confirm }
resultModel { model | itemModal = Just (ConfirmModalDeleteItem DeleteItemConfirmed) }
SetCorrOrgSuggestion idname ->
resultModelCmd ( model, setCorrOrg flags model (Just idname) )
@ -940,18 +929,10 @@ update key flags inav settings msg model =
RequestDeleteAttachment id ->
let
confirmModal =
Comp.ConfirmModal.defaultSettings
(DeleteAttachConfirmed id)
AttachModalCancelled
"Ok"
"Cancel"
"Really delete this file?"
model_ =
{ model
| attachmentDropdownOpen = False
, attachModal = Just confirmModal
, attachModal = Just (ConfirmModalDeleteFile (DeleteAttachConfirmed id))
}
in
resultModel model_
@ -964,14 +945,6 @@ update key flags inav settings msg model =
else
let
confirmModal =
Comp.ConfirmModal.defaultSettings
DeleteSelectedConfirmed
AttachModalCancelled
"Ok"
"Cancel"
"Really delete these files?"
model_ =
{ model
| viewMode =
@ -979,7 +952,7 @@ update key flags inav settings msg model =
{ svm
| action = DeleteSelected
}
, attachModal = Just confirmModal
, attachModal = Just (ConfirmModalDeleteAllFiles DeleteSelectedConfirmed)
}
in
resultModel model_
@ -1567,27 +1540,10 @@ update key flags inav settings msg model =
RequestReprocessFile id ->
let
confirmMsg =
if model.item.state == "created" then
"Reprocessing this file may change metadata of "
++ "this item, since it is unconfirmed. Do you want to proceed?"
else
"Reprocessing this file will not change metadata of "
++ "this item, since it has been confirmed. Do you want to proceed?"
confirmModal =
Comp.ConfirmModal.defaultSettings
(ReprocessFileConfirmed id)
AttachModalCancelled
"Ok"
"Cancel"
confirmMsg
model_ =
{ model
| attachmentDropdownOpen = False
, attachModal = Just confirmModal
, attachModal = Just (ConfirmModalReprocessFile (ReprocessFileConfirmed id))
}
in
resultModel model_
@ -1604,27 +1560,10 @@ update key flags inav settings msg model =
RequestReprocessItem ->
let
confirmMsg =
if model.item.state == "created" then
"Reprocessing this item may change its metadata, "
++ "since it is unconfirmed. Do you want to proceed?"
else
"Reprocessing this item will not change its metadata, "
++ "since it has been confirmed. Do you want to proceed?"
confirmModal =
Comp.ConfirmModal.defaultSettings
ReprocessItemConfirmed
ItemModalCancelled
"Ok"
"Cancel"
confirmMsg
model_ =
{ model
| attachmentDropdownOpen = False
, itemModal = Just confirmModal
, itemModal = Just (ConfirmModalReprocessItem ReprocessItemConfirmed)
}
in
resultModel model_

View File

@ -1,9 +1,9 @@
module Comp.ItemDetail.View2 exposing (view)
import Comp.Basic as B
import Comp.ConfirmModal
import Comp.DetailEdit
import Comp.ItemDetail.AddFilesForm
import Comp.ItemDetail.ConfirmModalView
import Comp.ItemDetail.ItemInfoHeader
import Comp.ItemDetail.Model
exposing
@ -27,7 +27,6 @@ import Html.Events exposing (onClick)
import Messages.Comp.ItemDetail exposing (Texts)
import Page exposing (Page(..))
import Styles as S
import Util.Time
view : Texts -> ItemNav -> UiSettings -> Model -> Html Msg
@ -36,15 +35,15 @@ view texts inav settings model =
[ header texts settings model
, menuBar texts inav settings model
, body texts inav settings model
, itemModal model
, itemModal texts model
]
itemModal : Model -> Html Msg
itemModal model =
itemModal : Texts -> Model -> Html Msg
itemModal texts model =
case model.itemModal of
Just confirm ->
Comp.ConfirmModal.view confirm
Comp.ItemDetail.ConfirmModalView.view texts.confirmModal confirm model
Nothing ->
span [ class "hidden" ] []

View File

@ -4,6 +4,7 @@ import Http
import Messages.Comp.DetailEdit
import Messages.Comp.HttpError
import Messages.Comp.ItemDetail.AddFilesForm
import Messages.Comp.ItemDetail.ConfirmModal
import Messages.Comp.ItemDetail.ItemInfoHeader
import Messages.Comp.ItemDetail.Notes
import Messages.Comp.ItemDetail.SingleAttachment
@ -21,6 +22,7 @@ type alias Texts =
, notes : Messages.Comp.ItemDetail.Notes.Texts
, itemMail : Messages.Comp.ItemMail.Texts
, detailEdit : Messages.Comp.DetailEdit.Texts
, confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts
, httpError : Http.Error -> String
, key : String
, backToSearchResults : String
@ -53,6 +55,7 @@ gb =
, notes = Messages.Comp.ItemDetail.Notes.gb
, itemMail = Messages.Comp.ItemMail.gb
, detailEdit = Messages.Comp.DetailEdit.gb
, confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb
, httpError = Messages.Comp.HttpError.gb
, key = "Key"
, backToSearchResults = "Back to search results"

View File

@ -0,0 +1,44 @@
module Messages.Comp.ItemDetail.ConfirmModal exposing
( Texts
, gb
)
import Messages.Basics
type alias Texts =
{ basics : Messages.Basics.Texts
, confirmReprocessItem : String -> String
, confirmReprocessFile : String -> String
, confirmDeleteItem : String
, confirmDeleteFile : String
, confirmDeleteAllFiles : String
}
gb : Texts
gb =
{ basics = Messages.Basics.gb
, confirmReprocessItem =
\state ->
if state == "created" then
"Reprocessing this item may change its metadata, "
++ "since it is unconfirmed. Do you want to proceed?"
else
"Reprocessing this item will not change its metadata, "
++ "since it has been confirmed. Do you want to proceed?"
, confirmReprocessFile =
\state ->
if state == "created" then
"Reprocessing this file may change metadata of "
++ "this item, since it is unconfirmed. Do you want to proceed?"
else
"Reprocessing this file will not change metadata of "
++ "this item, since it has been confirmed. Do you want to proceed?"
, confirmDeleteItem =
"Really delete this item? This cannot be undone."
, confirmDeleteFile = "Really delete this file?"
, confirmDeleteAllFiles = "Really delete these files?"
}

View File

@ -1,10 +1,12 @@
module Messages.Comp.ItemDetail.SingleAttachment exposing (Texts, gb)
import Messages.Comp.AttachmentMeta
import Messages.Comp.ItemDetail.ConfirmModal
type alias Texts =
{ attachmentMeta : Messages.Comp.AttachmentMeta.Texts
, confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts
, noName : String
, openFileInNewTab : String
, downloadFile : String
@ -24,6 +26,7 @@ type alias Texts =
gb : Texts
gb =
{ attachmentMeta = Messages.Comp.AttachmentMeta.gb
, confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb
, noName = "No name"
, openFileInNewTab = "Open file in new tab"
, downloadFile = "Download file"