diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index fcc8007cd..7e649f3cf 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -24,7 +24,6 @@ class Status extends FHCAPI_Controller 'updateStatus' => ['admin:rw', 'assistenz:rw'], 'advanceStatus' => ['admin:rw', 'assistenz:rw'], 'confirmStatus' => ['admin:rw', 'assistenz:rw'], - ]); //Load Models @@ -435,9 +434,10 @@ class Status extends FHCAPI_Controller ]); if (!$this->form_validation->run()) + { $this->terminateWithValidationErrors($this->form_validation->error_array()); + } - $this->load->library('PrestudentLib'); $this->db->trans_start(); @@ -623,8 +623,9 @@ class Status extends FHCAPI_Controller ]); if (!$this->form_validation->run()) + { $this->terminateWithValidationErrors($this->form_validation->error_array()); - + } // Start DB transaction $this->db->trans_start(); diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js index ab8f83fab..cff6b2be6 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js @@ -142,14 +142,15 @@ export default { this.addStudent({status_kurzbz: 'student', statusgrund_id}); }, addStudent(data) { - Promise - .allSettled( - this.prestudentIds.map(prestudent_id => this.$api.call( - ApiStvStatus.addStudent(prestudent_id, data), - { errorHeader: prestudent_id } - )) - ) - .then(res => this.showFeedback(res, data.status_kurzbz)); + this.$api.call(this.prestudentIds.map(prestudent_id => [ + prestudent_id, + ApiStvStatus.addStudent(prestudent_id, data), + { errorHeader: prestudent_id } + ])) + .then(() => { + this.$emit('reloadTable'); + this.$reloadList(); + }); }, changeStatusToAbbrecher(statusgrund_id) { this @@ -242,31 +243,15 @@ export default { return askForSemester(); }, changeStatus(data) { - Promise - .allSettled( - this.prestudentIds.map(prestudent_id => this.$api.call( - ApiStvStatus.changeStatus(prestudent_id, data), - { errorHeader: prestudent_id } - )) - ) - .then(res => this.showFeedback(res, data.status_kurzbz)); - }, - showFeedback(results, status_kurzbz) { - const countSuccess = results.filter(result => result.status == "fulfilled").length; - const countError = results.length - countSuccess; - - //Feedback Success als infoalert - this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { - countSuccess, - status: status_kurzbz, - countError - })); - - if(results.length == 1 && countSuccess > 0){ + this.$api.call(this.prestudentIds.map(prestudent_id => [ + prestudent_id, + ApiStvStatus.changeStatus(prestudent_id, data) + ])) + .then(() => { this.$emit('reloadTable'); - } - this.$reloadList(); - } + this.$reloadList(); + }); + }, }, created() { this.$api diff --git a/public/js/plugins/Api.js b/public/js/plugins/Api.js index d0ffaa439..47139b79f 100644 --- a/public/js/plugins/Api.js +++ b/public/js/plugins/Api.js @@ -42,10 +42,13 @@ export default { } function _clean_return_value(response) { + if (typeof response.data === 'string' || response.data instanceof String) + return _clean_return_value({ data: response }); + const result = response.data; delete response.data; if (!result.meta) - result.meta = {response}; + result.meta = { response }; else result.meta.response = response; return result; @@ -159,6 +162,77 @@ export default { return fhcApiAxios.post(uri, data, config); }, call(factory, configoverwrite, form) { + if (Array.isArray(factory)) { + const $fhcAlert = app.config.globalProperties.$fhcAlert; + const $api = app.config.globalProperties.$api; + + Promise + .allSettled(factory.map((config, index) => { + if (Array.isArray(config)) + return $api.call(config[1], { + errorHeader: config[0], + errorHandling: false + }); + else + return $api.call(config, { + errorHeader: '#' + index, + errorHandling: false + }); + })) + .then(res => { + // TODO(chris): obey form & configoverwrite + let messagesError = []; + let messagesSuccessful = []; + + res.forEach(result => { + if (result.status === 'fulfilled') { + //console.log(JSON.parse(result.value.data)); + const successTitle = "