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

View File

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

View File

@ -27,6 +27,7 @@ import Comp.ItemDetail.FieldTabState as FTabState
import Comp.ItemDetail.Model import Comp.ItemDetail.Model
exposing exposing
( AttachmentRename ( AttachmentRename
, ConfirmModalValue(..)
, MailSendResult(..) , MailSendResult(..)
, Model , Model
, Msg(..) , Msg(..)
@ -560,19 +561,7 @@ update key flags inav settings msg model =
resultModel { model | itemModal = Nothing } resultModel { model | itemModal = Nothing }
RequestDelete -> RequestDelete ->
let resultModel { model | itemModal = Just (ConfirmModalDeleteItem DeleteItemConfirmed) }
confirmMsg =
"Really delete this item? This cannot be undone."
confirm =
Comp.ConfirmModal.defaultSettings
DeleteItemConfirmed
ItemModalCancelled
"Ok"
"Cancel"
confirmMsg
in
resultModel { model | itemModal = Just confirm }
SetCorrOrgSuggestion idname -> SetCorrOrgSuggestion idname ->
resultModelCmd ( model, setCorrOrg flags model (Just idname) ) resultModelCmd ( model, setCorrOrg flags model (Just idname) )
@ -940,18 +929,10 @@ update key flags inav settings msg model =
RequestDeleteAttachment id -> RequestDeleteAttachment id ->
let let
confirmModal =
Comp.ConfirmModal.defaultSettings
(DeleteAttachConfirmed id)
AttachModalCancelled
"Ok"
"Cancel"
"Really delete this file?"
model_ = model_ =
{ model { model
| attachmentDropdownOpen = False | attachmentDropdownOpen = False
, attachModal = Just confirmModal , attachModal = Just (ConfirmModalDeleteFile (DeleteAttachConfirmed id))
} }
in in
resultModel model_ resultModel model_
@ -964,14 +945,6 @@ update key flags inav settings msg model =
else else
let let
confirmModal =
Comp.ConfirmModal.defaultSettings
DeleteSelectedConfirmed
AttachModalCancelled
"Ok"
"Cancel"
"Really delete these files?"
model_ = model_ =
{ model { model
| viewMode = | viewMode =
@ -979,7 +952,7 @@ update key flags inav settings msg model =
{ svm { svm
| action = DeleteSelected | action = DeleteSelected
} }
, attachModal = Just confirmModal , attachModal = Just (ConfirmModalDeleteAllFiles DeleteSelectedConfirmed)
} }
in in
resultModel model_ resultModel model_
@ -1567,27 +1540,10 @@ update key flags inav settings msg model =
RequestReprocessFile id -> RequestReprocessFile id ->
let 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_ =
{ model { model
| attachmentDropdownOpen = False | attachmentDropdownOpen = False
, attachModal = Just confirmModal , attachModal = Just (ConfirmModalReprocessFile (ReprocessFileConfirmed id))
} }
in in
resultModel model_ resultModel model_
@ -1604,27 +1560,10 @@ update key flags inav settings msg model =
RequestReprocessItem -> RequestReprocessItem ->
let 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_ =
{ model { model
| attachmentDropdownOpen = False | attachmentDropdownOpen = False
, itemModal = Just confirmModal , itemModal = Just (ConfirmModalReprocessItem ReprocessItemConfirmed)
} }
in in
resultModel model_ resultModel model_

View File

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

View File

@ -4,6 +4,7 @@ import Http
import Messages.Comp.DetailEdit import Messages.Comp.DetailEdit
import Messages.Comp.HttpError import Messages.Comp.HttpError
import Messages.Comp.ItemDetail.AddFilesForm import Messages.Comp.ItemDetail.AddFilesForm
import Messages.Comp.ItemDetail.ConfirmModal
import Messages.Comp.ItemDetail.ItemInfoHeader import Messages.Comp.ItemDetail.ItemInfoHeader
import Messages.Comp.ItemDetail.Notes import Messages.Comp.ItemDetail.Notes
import Messages.Comp.ItemDetail.SingleAttachment import Messages.Comp.ItemDetail.SingleAttachment
@ -21,6 +22,7 @@ type alias Texts =
, notes : Messages.Comp.ItemDetail.Notes.Texts , notes : Messages.Comp.ItemDetail.Notes.Texts
, itemMail : Messages.Comp.ItemMail.Texts , itemMail : Messages.Comp.ItemMail.Texts
, detailEdit : Messages.Comp.DetailEdit.Texts , detailEdit : Messages.Comp.DetailEdit.Texts
, confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts
, httpError : Http.Error -> String , httpError : Http.Error -> String
, key : String , key : String
, backToSearchResults : String , backToSearchResults : String
@ -53,6 +55,7 @@ gb =
, notes = Messages.Comp.ItemDetail.Notes.gb , notes = Messages.Comp.ItemDetail.Notes.gb
, itemMail = Messages.Comp.ItemMail.gb , itemMail = Messages.Comp.ItemMail.gb
, detailEdit = Messages.Comp.DetailEdit.gb , detailEdit = Messages.Comp.DetailEdit.gb
, confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb
, httpError = Messages.Comp.HttpError.gb , httpError = Messages.Comp.HttpError.gb
, key = "Key" , key = "Key"
, backToSearchResults = "Back to search results" , 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) module Messages.Comp.ItemDetail.SingleAttachment exposing (Texts, gb)
import Messages.Comp.AttachmentMeta import Messages.Comp.AttachmentMeta
import Messages.Comp.ItemDetail.ConfirmModal
type alias Texts = type alias Texts =
{ attachmentMeta : Messages.Comp.AttachmentMeta.Texts { attachmentMeta : Messages.Comp.AttachmentMeta.Texts
, confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts
, noName : String , noName : String
, openFileInNewTab : String , openFileInNewTab : String
, downloadFile : String , downloadFile : String
@ -24,6 +26,7 @@ type alias Texts =
gb : Texts gb : Texts
gb = gb =
{ attachmentMeta = Messages.Comp.AttachmentMeta.gb { attachmentMeta = Messages.Comp.AttachmentMeta.gb
, confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb
, noName = "No name" , noName = "No name"
, openFileInNewTab = "Open file in new tab" , openFileInNewTab = "Open file in new tab"
, downloadFile = "Download file" , downloadFile = "Download file"