From a4d60c0d92dea11ab5891dba3413821175cd1066 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Thu, 11 Jun 2020 22:10:48 +0200 Subject: [PATCH] Add correspondent organizations in item edit view --- modules/webapp/src/main/elm/Api.elm | 13 ++++++++++++- modules/webapp/src/main/elm/Comp/DetailEdit.elm | 14 ++++++++++++++ modules/webapp/src/main/elm/Comp/ItemDetail.elm | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/webapp/src/main/elm/Api.elm b/modules/webapp/src/main/elm/Api.elm index 8ad6ec93..138466d5 100644 --- a/modules/webapp/src/main/elm/Api.elm +++ b/modules/webapp/src/main/elm/Api.elm @@ -1,5 +1,6 @@ module Api exposing - ( addTag + ( addCorrOrg + , addTag , cancelJob , changePassword , checkCalEvent @@ -1086,6 +1087,16 @@ setCorrOrg flags item id receive = } +addCorrOrg : Flags -> String -> Organization -> (Result Http.Error BasicResult -> msg) -> Cmd msg +addCorrOrg flags item org receive = + Http2.authPost + { url = flags.config.baseUrl ++ "/api/v1/sec/item/" ++ item ++ "/corrOrg" + , account = getAccount flags + , body = Http.jsonBody (Api.Model.Organization.encode org) + , expect = Http.expectJson receive Api.Model.BasicResult.decoder + } + + setCorrPerson : Flags -> String -> OptionalId -> (Result Http.Error BasicResult -> msg) -> Cmd msg setCorrPerson flags item id receive = Http2.authPut diff --git a/modules/webapp/src/main/elm/Comp/DetailEdit.elm b/modules/webapp/src/main/elm/Comp/DetailEdit.elm index 225f6af5..d48ae157 100644 --- a/modules/webapp/src/main/elm/Comp/DetailEdit.elm +++ b/modules/webapp/src/main/elm/Comp/DetailEdit.elm @@ -196,6 +196,20 @@ update flags msg model = else ( model, Cmd.none, Nothing ) + OM om -> + let + org = + Comp.OrgForm.getOrg om + in + if Comp.OrgForm.isValid om then + ( { model | submitting = True } + , Api.addCorrOrg flags model.itemId org SubmitResp + , Nothing + ) + + else + ( model, Cmd.none, Nothing ) + _ -> Debug.todo "implement" diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail.elm b/modules/webapp/src/main/elm/Comp/ItemDetail.elm index be3b214c..d44728a3 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail.elm @@ -30,6 +30,7 @@ import Comp.Dropdown exposing (isDropdownChangeMsg) import Comp.Dropzone import Comp.ItemMail import Comp.MarkdownInput +import Comp.OrgForm import Comp.SentMails import Comp.YesNoDimmer import Data.Direction exposing (Direction) @@ -247,6 +248,7 @@ type Msg | AttachDDMsg (DD.Msg String String) | ModalEditMsg Comp.DetailEdit.Msg | StartTagModal + | StartCorrOrgModal | CloseModal @@ -1240,6 +1242,14 @@ update key flags next msg model = , Cmd.none ) + StartCorrOrgModal -> + noSub + ( { model + | modalEdit = Just (Comp.DetailEdit.initOrg model.item.id Comp.OrgForm.emptyModel) + } + , Cmd.none + ) + CloseModal -> noSub ( { model | modalEdit = Nothing }, Cmd.none ) @@ -1938,6 +1948,13 @@ renderEditForm settings model = [ label [] [ Icons.organizationIcon , text "Organization" + , a + [ class "right-float" + , href "#" + , onClick StartCorrOrgModal + ] + [ i [ class "add link icon" ] [] + ] ] , Html.map OrgDropdownMsg (Comp.Dropdown.view settings model.corrOrgModel) , renderOrgSuggestions model