From bfba05753e52063567e41b21528ea74ff11505a1 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 14 Feb 2024 08:56:25 +0100 Subject: [PATCH] also shows the zustellungs warning when there is more than one kontakt marked as zustellung --- application/controllers/Cis/Profil.php | 11 +++++++ public/js/apps/api/userdata.js | 7 ++++ .../Profil/ProfilComponents/EditAdresse.js | 8 +++-- .../Profil/ProfilComponents/EditKontakt.js | 33 ++++++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 50a4c21a4..0a6046c1c 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -23,6 +23,7 @@ class Profil extends Auth_Controller 'isMitarbeiter' => ['student/anrechnung_beantragen:r', 'user:r'], 'isStudent' => ['student/anrechnung_beantragen:r', 'user:r'], 'getZustellAdresse' => ['student/anrechnung_beantragen:r', 'user:r'], + 'getZustellKontakt' => ['student/anrechnung_beantragen:r', 'user:r'], ]); @@ -101,6 +102,16 @@ class Profil extends Auth_Controller echo json_encode($adressen_res); } + public function getZustellKontakt(){ + $this->KontaktModel->addSelect(["kontakt_id"]); + $kontakt_res = $this->KontaktModel->loadWhere(['person_id'=>$this->pid, 'zustellung'=>true]); + $kontakt_res = hasData($kontakt_res) ? getData($kontakt_res): null; + $kontakt_res = array_map(function($item){ + return $item->kontakt_id; + },$kontakt_res); + echo json_encode($kontakt_res); + } + private function viewMitarbeiterProfil($uid) { diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index 0c4c049a7..8395c4ca8 100755 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -43,4 +43,11 @@ export default { `cis.php/Cis/Profil/getZustellAdresse`; return axios.get(url); }, + + getZustellKontakt: function () { + const url = + FHC_JS_DATA_STORAGE_OBJECT.app_root + + `cis.php/Cis/Profil/getZustellKontakt`; + return axios.get(url); + }, }; diff --git a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js index 4f7240893..6a64452e0 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js @@ -32,7 +32,7 @@ export default { //? if the adresse was already saved return false; } - return this.zustellAdressenCount > 0 && this.data.zustelladresse; + return this.zustellAdressenCount>0 && this.data.zustelladresse; } //? if this.zustellAdressenCount is still not set by the api call and is still null return false; @@ -62,7 +62,7 @@ export default { created(){ Vue.$fhcapi.UserData.getZustellAdresse().then(res => { - this.zustellAdressenCount = res.data; + this.zustellAdressenCount = res.data?.length; }) this.originalValue = JSON.stringify(this.data); @@ -72,6 +72,7 @@ export default {
+
@@ -79,6 +80,9 @@ export default {
+ + +
diff --git a/public/js/components/Cis/Profil/ProfilComponents/EditKontakt.js b/public/js/components/Cis/Profil/ProfilComponents/EditKontakt.js index 2598529e0..491319aae 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/EditKontakt.js +++ b/public/js/components/Cis/Profil/ProfilComponents/EditKontakt.js @@ -8,6 +8,7 @@ export default { return{ originalValue:null, + zustellKontaktCount:null, } }, methods:{ @@ -27,6 +28,20 @@ export default { }, }, computed:{ + showZustellKontakteWarning: function(){ + if(this.zustellKontaktCount){ + + if(this.zustellKontaktCount.includes(this.data.kontakt_id)){ + //? if the adresse was already saved + return false; + } + return this.zustellKontaktCount>0 && this.data.zustellung; + } + //? if this.zustellAdressenCount is still not set by the api call and is still null + return false; + + + }, isChanged: function(){ //? returns true if the original passed data object was changed if(!this.data.kontakt || !this.data.kontakttyp) {return false;} @@ -35,14 +50,30 @@ export default { }, created(){ - this.originalValue = JSON.stringify(this.data); + Vue.$fhcapi.UserData.getZustellKontakt().then(res => { + + this.zustellKontaktCount = res.data?.length; + }) + this.originalValue = JSON.stringify(this.data); }, template: ` +
+ + +
+
+
+ !Achtung: Eine deiner Kontakte ist bereits als Zustellungskontakt gespeichert, sind sie sicher, dass sie den aktuellen Kontakt stattdessen als Zustellkontakt speichern wollen? +
+
+
+ +