adds the fields gemeinde and nation to the EditAdresse Component and adds autocomplete for the gemeinde if the nation is A

This commit is contained in:
SimonGschnell
2024-02-21 12:31:41 +01:00
parent 1bed062a01
commit 2a393f0087
3 changed files with 63 additions and 64 deletions
+27 -40
View File
@@ -25,6 +25,7 @@ class Profil extends Auth_Controller
'getZustellAdresse' => ['student/anrechnung_beantragen:r', 'user:r'],
'getZustellKontakt' => ['student/anrechnung_beantragen:r', 'user:r'],
'getAllNationen' => ['student/anrechnung_beantragen:r', 'user:r'],
'getGemeinden' => ['student/anrechnung_beantragen:r', 'user:r'],
]);
@@ -366,49 +367,35 @@ class Profil extends Auth_Controller
}
//TODO: use the old query check to get the correct values to display for the user in case he selected the nation Austria (A)
/* if($_POST['nation']=='A')
{
if(is_numeric($_POST['plz']) && $_POST['plz']<32000)
{
$qry = "SELECT * FROM bis.tbl_gemeinde WHERE lower(name)=lower(".$db->db_add_param($_POST['gemeinde']).")
AND plz=".$db->db_add_param($_POST['plz']);
if($db->db_query($qry))
{
if($row = $db->db_fetch_object())
{
$adresse->gemeinde = $row->name;
}
else
{
$error = true;
$errormsg = 'Gemeinde ist ungueltig';
$return = false;
public function getGemeinden(){
$nation = $this->input->get('nation',true);
//? json_decode on zip to transform zip from string to integer
$zip = json_decode($this->input->get('zip',true));
$this->load->model('codex/Gemeinde_model',"GemeindeModel");
$this->GemeindeModel->addSelect(["name"]);
if($nation == "A"){
if(isset($zip) && $zip>999 && $zip <32000){
$gemeinde_res = $this->GemeindeModel->loadWhere(['ortschaftskennziffer'=>$zip]);
if(isError($gemeinde_res)){
show_error("error while trying to query bis.tbl_gemeinde");
}
$gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null;
$gemeinde_res = array_map(function($obj){
return $obj->name;
},$gemeinde_res);
echo json_encode($gemeinde_res);
}else{
echo json_encode(error("ortschaftskennziffer code was not valid"));
}
else
{
$error = true;
$errormsg = 'Fehler beim Ermitteln der Gemeinde';
$return = false;
}
}else{
echo json_encode(error("Nation was not 'A' (Austria)"));
}
else
{
$error = true;
$errormsg = 'Postleitzahl ist fuer diese Nation ungueltig';
$return = false;
}
} */
public function getAllGemeinden(){
$this->load->model('public/Gemeinde_model',"NationModel");
$this->NationModel->addSelect(["langtext"]);
$nation_res = $this->NationModel->load();
if(isError($nation_res)){
show_error("error while trying to query table codex.tbl_nation");
}
$nation_res = hasData($nation_res) ? getData($nation_res) : null;
echo json_encode($nation_res);
}
+7
View File
@@ -1,6 +1,13 @@
export default {
//! API Calls for Profil Views
getGemeinden: function(nation,zip=null){
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
`cis.php/Cis/Profil/getGemeinden`;
return axios.get(url,{params:{nation:nation,zip:zip}});
},
getAllNationen:function(){
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
@@ -9,12 +9,29 @@ export default {
inject:["zustellAdresseCount"],
data(){
return{
gemeinden:[],
selectedNation:null,
nationenList:[],
originalValue:null,
zustellAdressenCount:null,
}
},
methods:{
getGemeinde: function(){
//? only query the gemeinde is the nation is Austria and the PLZ is greater than 999 and less than 32000
if(this.data.nation && this.data.nation ==="A" && (this.data.plz && (this.data.plz >999 && this.data.plz <32000))){
Vue.$fhcapi.UserData.getGemeinden(this.data.nation,this.data.plz).then(res => {
if(res.data.length){
this.gemeinden = res.data;
}
})
}else{
this.gemeinden = [];
}
},
updateValue: function(event,bind){
//? sets the value of a property to null when an empty string is entered to keep the isChanged function valid
if(bind ==="zustelladresse" ){
@@ -38,20 +55,6 @@ export default {
}
//? if this.zustellAdressenCount is still not set by the api call and is still null
return false;
},
ortLayoutClasses: function(){
return this.showKontaktTyp?[
'col-12',
'col-sm-7',
'col-xl-12',
'col-xxl-7',
]:['col-12'];
},
showKontaktTyp: function(){
let kontaktTypen = ["Nebenwohnsitz","Hauptwohnsitz"];
return kontaktTypen.includes(this.data.typ) || !this.data.typ
},
isChanged: function(){
if(!this.data.strasse || !this.data.plz || !this.data.ort || !this.data.typ){
@@ -61,23 +64,23 @@ export default {
return this.originalValue !== JSON.stringify(this.data);
},
},
created(){
Vue.$fhcapi.UserData.getAllNationen().then(res => {
this.nationenList = res.data;
this.getGemeinde();
});
//? same for Gemeinde
/* Vue.$fhcapi.UserData.getAllNationen().then(res => {
this.nationenList = res.data;
}); */
this.originalValue = JSON.stringify(this.data);
this.zustellAdressenCount = this.zustellAdresseCount();
},
template:`
<div class="gy-3 row justify-content-center align-items-center">
<pre> {{JSON.stringify(gemeinden,null,2)}}</pre>
<!-- warning message for too many zustellungs Adressen -->
<div v-if="showZustellAdressenWarning" class="col-12 ">
@@ -151,22 +154,24 @@ export default {
<div class="form-underline ">
<div class="form-underline-titel">PLZ</div>
<input class="form-control" :value="data.plz" @input="updateValue($event,'plz')" :placeholder="data.plz">
<input class="form-control" :value="data.plz" @input="updateValue($event,'plz')" @input="getGemeinde" :placeholder="data.plz">
</div>
</div>
<div class="col-6 order-5">
<div class="form-underline ">
<div class="form-underline-titel">Gemeinde</div>
<input class="form-control" :value="data.gemeinde" @input="updateValue($event,'gemeinde')" :placeholder="data.gemeinde">
<input :value="data.gemeinde" @input="updateValue($event,'gemeinde')" type="text" class="form-control" id="gemeineInput" list="gemeindeOptions">
<datalist id="gemeindeOptions">
<option v-for="option in gemeinden" :value="option">
</datalist>
</div>
</div>
<div class="col-6 order-5 ">
<div class="form-underline ">
<div class="form-underline-titel">nation</div>
<select :value="data.nation" @change="updateValue($event,'nation')" class="form-select" aria-label="Select Kontakttyp">
<select :value="data.nation" @change="updateValue($event,'nation')" @change="getGemeinde" class="form-select" aria-label="Select Kontakttyp">
<option selected></option>
<option :value="nation.code" v-for="nation in nationenList">{{nation.langtext}}</option>