From 5ee241d9146a009e89edcdc561f3186e52dd687f Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 13 Feb 2024 15:30:23 +0100 Subject: [PATCH] now editAdressen shows a warning message if a new adresse is marked as zustelladresse --- application/controllers/Cis/Profil.php | 53 ++++++++++++------- public/js/apps/api/userdata.js | 7 +++ .../components/Cis/Profil/EditProfilSelect.js | 2 +- .../Profil/ProfilComponents/EditAdresse.js | 29 +++++++++- 4 files changed, 69 insertions(+), 22 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index da5b62298..50a4c21a4 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -22,6 +22,7 @@ class Profil extends Auth_Controller 'View' => ['student/anrechnung_beantragen:r', 'user:r'], 'isMitarbeiter' => ['student/anrechnung_beantragen:r', 'user:r'], 'isStudent' => ['student/anrechnung_beantragen:r', 'user:r'], + 'getZustellAdresse' => ['student/anrechnung_beantragen:r', 'user:r'], ]); @@ -70,6 +71,36 @@ class Profil extends Auth_Controller } + //? foreward declaration of the function isStudent in Student_model.php + public function isStudent($uid){ + $result = $this->StudentModel->isStudent($uid); + if(!isSuccess($result)){ + show_error("error when calling Student_model function isStudent with uid ".$uid); + } + $result = getData($result); + echo json_encode($result); + } + + //? foreward declaration of the function isMitarbeiter in Mitarbeiter_model.php + public function isMitarbeiter($uid){ + $result = $this->MitarbeiterModel->isMitarbeiter($uid); + if(!isSuccess($result)){ + show_error("error when calling Mitarbeiter_model function isMitarbeiter with uid ".$uid); + } + $result = getData($result); + echo json_encode($result); + } + + public function getZustellAdresse(){ + $this->AdresseModel->addSelect(["adresse_id"]); + $adressen_res = $this->AdresseModel->loadWhere(['person_id'=>$this->pid, 'zustelladresse'=>true]); + $adressen_res = hasData($adressen_res) ? getData($adressen_res): null; + $adressen_res = array_map(function($item){ + return $item->adresse_id; + },$adressen_res); + echo json_encode($adressen_res); + } + private function viewMitarbeiterProfil($uid) { @@ -557,7 +588,7 @@ class Profil extends Auth_Controller private function getAdressenInfo($pid){ $adresse_res = null; if ( - + isSuccess($adresse_res = $this->AdresseModel->addSelect(["adresse_id","strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort","zustelladresse"])) && isSuccess($adresse_res = $this->AdresseModel->addOrder("zustelladresse", "DESC")) && isSuccess($adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp", "typ=adressentyp_kurzbz")) @@ -613,24 +644,6 @@ class Profil extends Auth_Controller return $zutrittskarte_ausgegebenam; } - //? foreward declaration of the function isStudent in Student_model.php - public function isStudent($uid){ - $result = $this->StudentModel->isStudent($uid); - if(!isSuccess($result)){ - show_error("error when calling Student_model function isStudent with uid ".$uid); - } - $result = getData($result); - echo json_encode($result); - } - - //? foreward declaration of the function isMitarbeiter in Mitarbeiter_model.php - public function isMitarbeiter($uid){ - $result = $this->MitarbeiterModel->isMitarbeiter($uid); - if(!isSuccess($result)){ - show_error("error when calling Mitarbeiter_model function isMitarbeiter with uid ".$uid); - } - $result = getData($result); - echo json_encode($result); - } + } diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index 02b82dde8..0c4c049a7 100755 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -36,4 +36,11 @@ export default { `cis.php/Cis/Profil/isMitarbeiter/${uid}`; return axios.get(url); }, + + getZustellAdresse: function () { + const url = + FHC_JS_DATA_STORAGE_OBJECT.app_root + + `cis.php/Cis/Profil/getZustellAdresse`; + return axios.get(url); + }, }; diff --git a/public/js/components/Cis/Profil/EditProfilSelect.js b/public/js/components/Cis/Profil/EditProfilSelect.js index 615ddcc18..a78a58d7b 100755 --- a/public/js/components/Cis/Profil/EditProfilSelect.js +++ b/public/js/components/Cis/Profil/EditProfilSelect.js @@ -71,7 +71,7 @@ export default { typ: null, plz: null, ort: null, - zustelladresse:null, + zustelladresse:false, } : { //? add flag diff --git a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js index e8878a886..4f7240893 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilComponents/EditAdresse.js @@ -9,6 +9,7 @@ export default { data(){ return{ originalValue:null, + zustellAdressenCount:null, } }, methods:{ @@ -24,6 +25,20 @@ export default { }, }, computed:{ + showZustellAdressenWarning: function(){ + if(this.zustellAdressenCount){ + + if(this.zustellAdressenCount.includes(this.data.adresse_id)){ + //? if the adresse was already saved + return false; + } + return this.zustellAdressenCount > 0 && this.data.zustelladresse; + } + //? if this.zustellAdressenCount is still not set by the api call and is still null + return false; + + + }, ortLayoutClasses: function(){ return this.showKontaktTyp?[ 'col-12', @@ -45,13 +60,25 @@ export default { }, }, created(){ + Vue.$fhcapi.UserData.getZustellAdresse().then(res => { + + this.zustellAdressenCount = res.data; + }) this.originalValue = JSON.stringify(this.data); }, template:`
- + + +
+
+
+ !Achtung: Eine deiner Adressen ist bereits als Zustelladresse gespeichert, sind sie sicher, dass sie die aktuelle Adresse stattdessen als Zustelladresse speichern wollen? +
+
+