diff --git a/application/controllers/api/frontend/v1/education/Ferien.php b/application/controllers/api/frontend/v1/education/Ferien.php index 419164fa8..932bbca10 100644 --- a/application/controllers/api/frontend/v1/education/Ferien.php +++ b/application/controllers/api/frontend/v1/education/Ferien.php @@ -35,6 +35,7 @@ class Ferien extends FHCAPI_Controller 'getFerien' => 'basis/ferien:r', 'getStg' => 'basis/ferien:r', 'insert' => 'basis/ferien:w', + 'update' => 'basis/ferien:w', 'delete' => 'basis/ferien:w' ]); @@ -105,44 +106,52 @@ class Ferien extends FHCAPI_Controller */ public function insert() { - $this->load->library('form_validation'); + $this->_validate(); - $this->form_validation->set_rules('vondatum', 'Von Datum', 'required|is_valid_date'); - $this->form_validation->set_rules('bisdatum', 'Bis Datum', 'required|is_valid_date'); - $this->form_validation->set_rules('bezeichnung', 'Bezeichnung', 'required|max_length[128]'); - $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required|numeric'); - - //Events::trigger('konto_insert_validation', $this->form_validation); - - if (!$this->form_validation->run()) - $this->terminateWithValidationErrors($this->form_validation->error_array()); - - $allowed = [ - 'vondatum', - 'bisdatum', - 'bezeichnung', - 'studiengang_kz' - ]; - - $data = []; + $data = $this->_getData(); // TODO add insertaum and updateamum? //~ $data = [ //~ 'insertamum' => date('c'), //~ 'insertvon' => getAuthUID() //~ ]; - foreach ($allowed as $field) - { - if ($this->input->post($field) !== null) $data[$field] = $this->input->post($field); - } - - $result = []; - $id = $this->getDataOrTerminateWithError($this->FerienModel->insert($data)); $this->terminateWithSuccess(hasData($id) ? getData($id) : null); } + /** + * Update Ferien + * + * @return void + */ + public function update() + { + $id = $this->input->post('ferien_id'); + + if (!is_numeric($id)) + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Ferien Id']), self::ERROR_TYPE_GENERAL); + + $this->_validate(); + + $data = $this->_getData(); + + if (isEmptyArray($data)) $this->terminateWithSuccess(null); + // TODO add insertaum and updateamum? + //~ $data = [ + //~ 'updateamum' => date('c'), + //~ 'updatevon' => getAuthUID() + //~ ]; + + $data['ferien_id'] = $id; + + $result = $this->FerienModel->update($id, $data); + + if (isError($result)) $this->terminateWithError(getError($result)); + + $this->terminateWithSuccess($id); + } + /** * Delete Ferien * @@ -181,12 +190,51 @@ class Ferien extends FHCAPI_Controller //Events::trigger('konto_delete', $ferien_id); $result = $this->getDataOrTerminateWithError($this->FerienModel->delete($ferien_id)); - //~ if (isError($result)) { - //~ if (getCode($result) != 42) - //~ $this->terminateWithError(getError($result)); - //~ $this->terminateWithError($this->p->t('konto', 'error_delete_level')); - //~ } $this->terminateWithSuccess(); } + + /** + * Validate ferien post input. + * @param + * @return object success or error + */ + private function _validate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('vondatum', 'Von Datum', 'required|is_valid_date'); + $this->form_validation->set_rules('bisdatum', 'Bis Datum', 'required|is_valid_date'); + $this->form_validation->set_rules('bezeichnung', 'Bezeichnung', 'required|max_length[128]'); + $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required|numeric'); + + //Events::trigger('konto_insert_validation', $this->form_validation); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + /** + * Gets Ferien data from post input. + * @return array + */ + private function _getData() + { + $data = []; + + $allowed = [ + 'vondatum', + 'bisdatum', + 'bezeichnung', + 'studiengang_kz' + ]; + + + foreach ($allowed as $field) + { + if ($this->input->post($field) !== null) $data[$field] = $this->input->post($field); + } + + return $data; + } } diff --git a/application/views/lehre/ferienverwaltung.php b/application/views/lehre/ferienverwaltung.php index 3a9a615ca..19c09c04e 100644 --- a/application/views/lehre/ferienverwaltung.php +++ b/application/views/lehre/ferienverwaltung.php @@ -9,8 +9,9 @@ 'navigationcomponent' => true, 'tabulator6' => true, 'primevue3' => true, - 'vuedatepicker11' => true, + //'vuedatepicker11' => true, 'customJSModules' => array('public/js/apps/lehre/Ferienverwaltung/Ferienverwaltung.js'), + 'customCSSs' => array('vendor/vuejs/vuedatepicker_css/main.css') ); $this->load->view('templates/FHC-Header', $includesArray); diff --git a/public/js/api/factory/ferienverwaltung/ferienverwaltung.js b/public/js/api/factory/ferienverwaltung/ferienverwaltung.js index 093e62255..57d1fbf3a 100644 --- a/public/js/api/factory/ferienverwaltung/ferienverwaltung.js +++ b/public/js/api/factory/ferienverwaltung/ferienverwaltung.js @@ -38,6 +38,13 @@ export default { params }; }, + update(params) { + return { + method: 'post', + url: 'api/frontend/v1/education/ferien/update', + params + }; + }, delete(ferien_id) { return { method: 'post', diff --git a/public/js/components/Ferienverwaltung/Ferienverwaltung.js b/public/js/components/Ferienverwaltung/Ferienverwaltung.js index d1f6bc5b6..c6545be48 100644 --- a/public/js/components/Ferienverwaltung/Ferienverwaltung.js +++ b/public/js/components/Ferienverwaltung/Ferienverwaltung.js @@ -1,7 +1,6 @@ import {CoreFilterCmpt} from "../filter/Filter.js"; import FormInput from "../Form/Input.js"; -import FerienNew from "./New.js"; -//import KontoEdit from "./Konto/Edit.js"; +import FerienModal from "./Modal.js"; import ApiFerienverwaltung from '../../api/factory/ferienverwaltung/ferienverwaltung.js'; @@ -10,8 +9,7 @@ export default { components: { CoreFilterCmpt, FormInput, - FerienNew - //KontoEdit + FerienModal }, props: { //modelValue: Object, @@ -73,15 +71,16 @@ export default { let container = document.createElement('div'); container.className = "d-flex gap-2"; - //~ let button = document.createElement('button'); - //~ button.className = 'btn btn-outline-secondary btn-action'; - //~ button.innerHTML = ''; - //~ button.title = this.$p.t('person', 'adresse_edit'); - //~ button.addEventListener('click', (event) => - //~ this.actionEditAdress(cell.getData().adresse_id) - //~ ); - //~ container.append(button); let button = document.createElement('button'); + button.className = 'btn btn-outline-secondary btn-action'; + button.innerHTML = ''; + button.title = this.$p.t('person', 'ferien_edit'); + button.addEventListener('click', (event) => + this.$refs.modal.open(cell.getData()) + ); + container.append(button); + + button = document.createElement('button'); button.className = 'btn btn-outline-secondary'; button.innerHTML = ''; button.addEventListener('click', evt => { @@ -144,13 +143,13 @@ export default { reload() { this.$refs.table.reloadTable(); }, - updateData(data) { - if (!data) - return this.reload(); - //this.$refs.table.tabulator.updateOrAddData(data); - }, + //~ updateData(data) { + //~ if (!data) + //~ return this.reload(); + //~ //this.$refs.table.tabulator.updateOrAddData(data); + //~ }, actionNew() { - this.$refs.new.open(); + this.$refs.modal.open(); }, loadByStg() { this.reload(); @@ -172,8 +171,8 @@ export default { }); }, template: ` -