From 61616fbaefacd0abece97545bc0838eb44659f99 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Mon, 15 Jan 2024 13:56:17 +0100 Subject: [PATCH] Update AppendForm mit JSON.stringify, Update Form, authUid --- .../controllers/components/stv/Notiz.php | 52 ++++++++++-- public/js/components/Notiz/Notiz.js | 40 ++++----- .../Studentenverwaltung/Details/Notizen.js | 82 ++++++------------- 3 files changed, 89 insertions(+), 85 deletions(-) diff --git a/application/controllers/components/stv/Notiz.php b/application/controllers/components/stv/Notiz.php index 507e9ed07..494b1fdbf 100644 --- a/application/controllers/components/stv/Notiz.php +++ b/application/controllers/components/stv/Notiz.php @@ -19,6 +19,24 @@ class Notiz extends FHC_Controller ]); } + public function getUid() + { + // Load Libraries + $this->load->library('AuthLib'); + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + $result = getAuthUid(); + $this->outputJsonError($result); + + // $this->outputJson(getData($result)); + +/* if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->outputJson(getError($result)); + } else { + $this->outputJson($result); + }*/ + } + public function getNotizen($person_id) { $this->load->model('person/Notiz_model', 'NotizModel'); @@ -74,19 +92,26 @@ class Notiz extends FHC_Controller $this->form_validation->set_rules('text', 'Text', 'required');*/ //TODO(Manu) form validation - schon für type hier? - //Speichern der Notiz und Notizzuordnung $uid = getAuthUID(); - $verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid; + + if (isset($_POST['data'])) + { + $data = json_decode($_POST['data']); + unset($_POST['data']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } + } + $titel = $this->input->post('titel'); $text = $this->input->post('text'); - $bearbeiter_uid = $this->input->post('bearbeiter'); $erledigt = $this->input->post('erledigt'); + $verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid; + $bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : null; $type = $this->input->post('typeId'); - - //get rid of null value error - $start = $this->input->post(date('von')); - $ende = $this->input->post(date('bis')); + $start = $this->input->post('von'); + $ende = $this->input->post('bis'); $result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid); if (isError($result)) @@ -215,6 +240,15 @@ class Notiz extends FHC_Controller return $this->outputJsonError($this->form_validation->error_array()); }*/ + if (isset($_POST['data'])) + { + $data = json_decode($_POST['data']); + unset($_POST['data']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } + } + if(!$notiz_id) { return $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); @@ -228,8 +262,8 @@ class Notiz extends FHC_Controller $bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : $uid; $erledigt = $this->input->post('erledigt'); $type = $this->input->post('typeId'); - $start = $this->input->post(date('von')); - $ende = $this->input->post(date('bis')); + $start = $this->input->post('von'); + $ende = $this->input->post('bis'); $result = $this->NotizModel->update( [ diff --git a/public/js/components/Notiz/Notiz.js b/public/js/components/Notiz/Notiz.js index 660404f7c..46b6a6992 100644 --- a/public/js/components/Notiz/Notiz.js +++ b/public/js/components/Notiz/Notiz.js @@ -88,7 +88,8 @@ export default { return this.verfasser; }, set(value) { - this.$emit('update:verfasser', value); + //this.$emit('update:verfasser', value); + this.$emit('update:verfasser', value.mitarbeiter_uid); } }, intBearbeiter: { @@ -179,24 +180,12 @@ export default {
-
- - {{uid}} -
-
- -
- -
- - +
+
-
- -
- -
+ +
+
+
+ +
+ +
+
- + -
+
+ +
+ +
- +
diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js index ba82b2628..f88ce0627 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js @@ -7,7 +7,7 @@ var editIcon = function (cell, formatterParams) { return ""; }; var deleteIcon = function (cell, formatterParams){ - return ""; + return ""; }; export default { @@ -28,13 +28,13 @@ export default { columns: [ {title: "Titel", field: "titel"}, {title: "Text", field: "text", width: 350}, - {title: "VerfasserIn", field: "verfasser_uid", visible: false}, + {title: "VerfasserIn", field: "verfasser_uid"}, {title: "BearbeiterIn", field: "bearbeiter_uid", visible: false}, {title: "Start", field: "start", visible: false}, {title: "Ende", field: "ende", visible: false}, /* {title: "Dokumente", field: "dms_id"},*/ {title: "Dokumente", field: "countdoc"}, - {title: "Erledigt", field: "erledigt"}, + {title: "Erledigt", field: "erledigt", visible: false}, {title: "Notiz_id", field: "notiz_id", visible: false}, {title: "Notizzuordnung_id", field: "notizzuordnung_id", visible: false}, { @@ -58,6 +58,8 @@ export default { }, tabulatorEvents: [], notizen: [], + uid: '', + intVerfasser: '', filteredMitarbeiter: [], formData: { typeId: 'person_id', @@ -68,12 +70,13 @@ export default { bis: null, document: null, erledigt: false, - verfasser: null, + verfasser: this.uid, bearbeiter: null, anhang: [] }, showErweitert: true, - showDocument: true, + showDocument: true + } }, methods:{ @@ -111,35 +114,22 @@ export default { this.resetFormData(); this.formData.typeId = 'person_id'; this.formData.titel = ''; - this.formData.statusNew = false; + this.formData.statusNew = true; this.formData.text = null; this.formData.von = null; this.formData.bis = null; this.formData.document = null; this.formData.erledigt = false; - this.formData.verfasser = null; + this.formData.verfasser = this.uid; this.formData.bearbeiter = null; this.formData.anhang = []; }, addNewNotiz(notizData) { - /* console.log("here: anhang noch empty"); - console.log(this.formData);*/ const formData = new FormData(); - //working with single files - // Object.entries(this.formData).forEach(([k, v]) => formData.append(k, v)); - - //multiple files - //console.log(this.formData.anhang); - Object.entries(this.formData).forEach(([k, v]) => { - if(k!= 'anhang') - formData.append(k, v); - }); + formData.append('data', JSON.stringify(this.formData)); Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v)); -/* - console.log(this.formData); - console.log(formData);*/ CoreRESTClient.post('components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id, formData, @@ -228,46 +218,18 @@ export default { bis: null, document: null, erledigt: false, - verfasser: null, + verfasser: this.uid, bearbeiter: null, anhang: [] }; }, - /* updateNotiz(notiz_id){ - CoreRESTClient.post('components/stv/Notiz/updateNotiz/' + notiz_id, - this.formData - ).then(response => { - if (!response.data.error) { - this.$fhcAlert.alertSuccess('Update erfolgreich'); - this.resetFormData(); - this.reload(); - } else { - const errorData = response.data.retval; - Object.entries(errorData).forEach(entry => { - const [key, value] = entry; - this.$fhcAlert.alertError(value); - }); - } - }).catch(error => { - this.statusMsg = 'Error in Catch'; - this.$fhcAlert.alertError('Fehler bei Updateroutine aufgetreten'); - }).finally(() => { - window.scrollTo(0, 0); - //this.reload(); - }); - },*/ updateNotiz(notiz_id){ const formData = new FormData(); - - Object.entries(this.formData).forEach(([k, v]) => { - if(k!= 'anhang') - formData.append(k, v); - }); + formData.append('data', JSON.stringify(this.formData)); Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v)); - console.log(this.formData); + //console.log(this.formData); - //warum geht das nicht analog? wie kann titel = null sein? CoreRESTClient.post('components/stv/Notiz/updateNotiz/' + notiz_id, formData, { Headers: { "Content-Type": "multipart/form-data" } } @@ -290,6 +252,17 @@ export default { }); }, }, + created(){ + CoreRESTClient + .get('components/stv/Notiz/getUid') + .then(result => { + if(result.data.retval) { + this.formData.verfasser = result.data.retval; + } + }) + .catch(this.$fhcAlert.handleSystemError); + }, + computed: { }, template: `
@@ -343,10 +316,7 @@ export default {
- parent: {{formData.bearbeiter}} - - +
`