diff --git a/application/config/stv.php b/application/config/stv.php index 84b148362..0e18be220 100644 --- a/application/config/stv.php +++ b/application/config/stv.php @@ -119,6 +119,7 @@ $config['student_tab_order'] = [ $config['students_tab_order'] = [ 'banking', 'status', + 'messages', 'groups', 'finalexam', 'combinePeople', diff --git a/application/controllers/NeueNachricht.php b/application/controllers/NeueNachricht.php index 9b61b78ef..b0ff5c554 100644 --- a/application/controllers/NeueNachricht.php +++ b/application/controllers/NeueNachricht.php @@ -20,11 +20,18 @@ class NeueNachricht extends Auth_Controller */ public function _remap() { + $typeid = $this->input->post('typeid'); + $ids = ($this->input->post('ids') && strpos($this->input->post('ids'), ',')) + ? explode(',', $this->input->post('ids')) + : $this->input->post('ids'); + //now working $this->load->view('Nachrichten', [ 'permissions' => [ 'assistenz_schreibrechte' => $this->permissionlib->isBerechtigt('assistenz','suid'), - ] + ], + 'ids' => $ids, + 'typeid' => $typeid ]); } } diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index 355fe79a4..3035e532d 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -1,6 +1,5 @@ ['admin:r', 'assistenz:r'], 'getMsgVarsLoggedInUser' => ['admin:r', 'assistenz:r'], 'getNameOfDefaultRecipient' => ['admin:r', 'assistenz:r'], + 'getNameOfDefaultRecipients' => ['admin:r', 'assistenz:r'], 'sendMessage' => ['admin:r', 'assistenz:r'], 'deleteMessage' => ['admin:r', 'assistenz:r'], 'getDataVorlage' => ['admin:r', 'assistenz:r'], @@ -21,6 +21,7 @@ class Messages extends FHCAPI_Controller 'getReplyData' => ['admin:r', 'assistenz:r'], 'getPersonId' => ['admin:r', 'assistenz:r'], 'getUid' => ['admin:r', 'assistenz:r'], + 'getUids' => ['admin:r', 'assistenz:r'], ]); //Load Models @@ -37,7 +38,7 @@ class Messages extends FHCAPI_Controller // Load language phrases $this->loadPhrases([ - 'ui' + 'ui', 'messages' ]); } @@ -101,22 +102,49 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($vorlage); } - public function getMessageVarsPerson($id, $typeId) + public function getMessageVarsPerson($typeId) { - $person_id = ($typeId == 'mitarbeiter_uid') ? $this->_getPersonId($id, $typeId) : $id; - $result = $this->MessageModel->getMsgVarsDataByPersonId($person_id); - $data = $this->getDataOrTerminateWithError($result); + $ids = $this->input->post('ids'); + $messageVarsPerson = []; - $this->terminateWithSuccess($data); + foreach ($ids as $id) + { + $person_id = ($typeId == 'mitarbeiter_uid') ? $this->_getPersonId($id, $typeId) : $id; + $result = $this->MessageModel->getMsgVarsDataByPersonId($person_id); + $data = $this->getDataOrTerminateWithError($result); + $messageVarsPerson[] = current($data); + } + + $this->terminateWithSuccess($messageVarsPerson); } - public function getMsgVarsPrestudent($id, $typeId) + public function getMsgVarsPrestudent($typeId) { - $prestudent_id = ($typeId == 'uid') ? $this->_getPrestudentIdFromUid($id) : $id; - $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); - $data = $this->getDataOrTerminateWithError($result); + $ids = $this->input->post('ids'); + if(!is_array($ids)) { + $ids = array($ids); + } + $messageVarsPrestudent = []; - $this->terminateWithSuccess($data); + if($typeId == 'uid') + { + $prestudent_ids = []; + foreach ($ids as $id) + { + $prestudent_ids[] = $this->_getPrestudentIdFromUid($id); + } + } + else + $prestudent_ids = $ids; + + foreach ($prestudent_ids as $prestudent_id) + { + $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); + $data = $this->getDataOrTerminateWithError($result); + $messageVarsPrestudent[] = current($data); + } + + $this->terminateWithSuccess($messageVarsPrestudent); } public function getMsgVarsLoggedInUser() @@ -127,27 +155,45 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function getNameOfDefaultRecipient($id, $type_id) + public function getNameOfDefaultRecipients($type_id) { - $id = ($type_id != 'person_id') ? $this->_getPersonId($id, $type_id) : $id; + $ids = $this->input->post('ids'); + if(!is_array($ids)) { + $ids = array($ids); + } + $recipients = []; + + if (empty($ids)) { + + throw new InvalidArgumentException($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Id(s)']), self::ERROR_TYPE_GENERAL); + } $this->load->model('person/Person_model', 'PersonModel'); + if($type_id != 'person_id'){ + foreach ($ids as $id) + { + $person_id = $this->_getPersonId($id, $type_id); + $result = $this->PersonModel->load($person_id); + $data = $this->getDataOrTerminateWithError($result); + $name = current($data); + $recipients[$id] = $name->vorname . " " . $name->nachname; + } + } + else { + foreach ($ids as $id) { + $result = $this->PersonModel->load($id); + $data = $this->getDataOrTerminateWithError($result); + $name = current($data); + $recipients[$id] = $name->vorname . " " . $name->nachname; + } + } - $result = $this->PersonModel->load($id); - $data = $this->getDataOrTerminateWithError($result); - $name = current($data); - - $this->terminateWithSuccess($name->vorname . " " . $name->nachname ); + $this->terminateWithSuccess($recipients); } - public function sendMessage($recipient_id) + public function sendMessage($typeId) { - //has to be uid - // $this->terminateWithError("uid", $recipient_id, self::ERROR_TYPE_GENERAL); - - //default setting - $receiversPersonId = $this->_getPersonId($recipient_id, 'uid'); - + $resultReturn = []; $uid = getAuthUID(); $this->load->model('person/Benutzer_model', 'BenutzerModel'); $result = $this->BenutzerModel->loadWhere( @@ -185,47 +231,61 @@ class Messages extends FHCAPI_Controller $body = $this->input->post('body'); $relationmessage_id = $this->input->post('relationmessage_id'); - $typeId = $this->input->post('type_id'); - $id = $this->input->post('id'); - - if($typeId == 'uid') + if (isset($_POST['ids'])) { - $prestudent_id = $this-> _getPrestudentIdFromUid($id); - - //parseMessagetext for variables Prestudent - $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - if($typeId == 'mitarbeiter_uid') - { - $person_id = $this->_getPersonId($id, $typeId); - - $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - $this->terminateWithError($bodyParsed, self::ERROR_TYPE_GENERAL); - - } - elseif($typeId == 'person_id') - { - $result = $this->MessagesModel->parseMessageTextPerson($id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - elseif($typeId == 'prestudent_id') - { - $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); - $bodyParsed = $this->getDataOrTerminateWithError($result); - } - else - { - $this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL); + $ids = json_decode($_POST['ids']); + unset($_POST['ids']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } } - $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); + if (!is_array($ids)) { + $ids = [$ids]; + } - $this->terminateWithSuccess($result); + foreach ($ids as $id) + { + $receiversPersonId = $typeId == "person_id" ? $id : $this->_getPersonId($id, $typeId); + + if($typeId == 'uid') + { + $prestudent_id = $this-> _getPrestudentIdFromUid($id); + + $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); + $bodyParsed = $this->getDataOrTerminateWithError($result); + } + if($typeId == 'mitarbeiter_uid') + { + $person_id = $this->_getPersonId($id, $typeId); + + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); + $bodyParsed = $this->getDataOrTerminateWithError($result); + } + elseif($typeId == 'person_id') + { + $result = $this->MessagesModel->parseMessageTextPerson($id, $body); + $bodyParsed = $this->getDataOrTerminateWithError($result); + } + elseif($typeId == 'prestudent_id') + { + $result = $this->MessagesModel->parseMessageTextPrestudent($id, $body); + $bodyParsed = $this->getDataOrTerminateWithError($result); + } + else + { + $this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL); + } + + $result =$this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id); + $data = $this->getDataOrTerminateWithError($result); + $resultReturn[] = current($data); + + } + $this->terminateWithSuccess($resultReturn); } - public function getPreviewText($id, $type_id) + public function getPreviewText($type_id) { if (isset($_POST['data'])) { @@ -233,39 +293,60 @@ class Messages extends FHCAPI_Controller unset($_POST['data']); } else - $this->terminateWithError("Textbody missing ", self::ERROR_TYPE_GENERAL); + $this->terminateWithError($this->p->t('messages', 'errorMissingOrInvalidParameters', ['parameter'=> "Textbody"]), self::ERROR_TYPE_GENERAL); - switch($type_id) + if (isset($_POST['ids'])) { - case 'uid': - $prestudent_id = $this->_getPrestudentIdFromUid($id); - $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $data); - break; - case 'prestudent_id': - $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); - break; - case 'person_id': - $result = $this->MessagesModel->parseMessageTextPerson($id, $data); - break; - case 'mitarbeiter_uid': - { - $person_id = $this->_getPersonId($id, $type_id); - $result = $this->MessagesModel->parseMessageTextPerson($person_id, $data); - } - break; - default: - $this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); - break; + $ids = json_decode($_POST['ids']); + if(!is_array($ids)) + { + $ids = array($ids); + } + unset($_POST['ids']); } + else + $this->terminateWithError($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Id(s)']), self::ERROR_TYPE_GENERAL); - $bodyParsed = $this->getDataOrTerminateWithError($result); + $bodyParsed = []; + + foreach ($ids as $id) + { + switch($type_id) + { + case 'uid': + $prestudent_id = $this->_getPrestudentIdFromUid($id); + $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'prestudent_id': + $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'person_id': + $result = $this->MessagesModel->parseMessageTextPerson($id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + break; + case 'mitarbeiter_uid': + { + $person_id = $this->_getPersonId($id, $type_id); + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $data); + $bodyParsed[$id] = $this->getDataOrTerminateWithError($result); + } + break; + default: + $this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $type_id]), self::ERROR_TYPE_GENERAL); + break; + } + } $this->terminateWithSuccess($bodyParsed); } public function getReplyData($messageId) { - //TODO(Manu) validation of messageId: if number + if (!is_numeric($messageId)) { + $this->terminateWithError($this->p->t('ui', 'error_valueNotNumeric', ['value'=> 'Message ID']), self::ERROR_TYPE_GENERAL); + } $this->MessageModel->addSelect('public.tbl_msg_message.*'); $this->MessageModel->addSelect('r.*'); @@ -288,7 +369,6 @@ class Messages extends FHCAPI_Controller $replyBody = $this->_getReplyBody($body, $dataMessage[0]->nachname, $dataMessage[0]->vorname, $dataMessage[0]->insertamum); $dataMessage[0]->replyBody = $replyBody; - $dataMessage[0]->rest = "Help Manu"; $dataMessage[0]->replySubject = $prefix . $subject; $this->terminateWithSuccess($dataMessage); @@ -336,6 +416,11 @@ class Messages extends FHCAPI_Controller ['prestudent_id' => $id] ); } + else + { + $this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL); + } + $data = $this->getDataOrTerminateWithError($result); $person = current($data); @@ -343,8 +428,11 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($person->person_id); } - public function getUid($id, $typeId) + public function getUids($typeId) { + $ids = $this->input->post('ids'); + $benutzerIds = []; + if (!$typeId) { $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Type ID']), self::ERROR_TYPE_GENERAL); @@ -352,39 +440,50 @@ class Messages extends FHCAPI_Controller elseif ($typeId == 'person_id') { $this->load->model('person/Benutzer_model', 'BenutzerModel'); - $result = $this->BenutzerModel->loadWhere( - ['person_id' => $id] - ); + foreach ($ids as $id) + { + $result = $this->BenutzerModel->loadWhere( + ['person_id' => $id] + ); + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + $benutzerIds[$id] = $benutzer->uid; + } } elseif($typeId == 'prestudent_id') { $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - $result = $this->PrestudentModel->loadWhere( - ['prestudent_id' => $id] - ); + foreach ($ids as $id) + { + $result = $this->PrestudentModel->loadWhere( + ['prestudent_id' => $id] + ); - $data = $this->getDataOrTerminateWithError($result); - $person = current($data); - $person_id = $person->person_id; + $data = $this->getDataOrTerminateWithError($result); + $person = current($data); + $person_id = $person->person_id; - $this->load->model('person/Benutzer_model', 'BenutzerModel'); - $result = $this->BenutzerModel->loadWhere( - ['person_id' => $person_id] - ); + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['person_id' => $person_id] + ); + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + $benutzerIds[$id] = $benutzer->uid; + } } elseif($typeId == 'uid' || $typeId == 'mitarbeiter_uid') { - $this->terminateWithSuccess($id); + $this->terminateWithSuccess($ids); } else { - $this->terminateWithError("MESSAGES::getUID logic for type_id " . $typeId . " not defined yet", self::ERROR_TYPE_GENERAL); + $this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL); } - $data = $this->getDataOrTerminateWithError($result); - $benutzer = current($data); - - $this->terminateWithSuccess($benutzer->uid); + $this->terminateWithSuccess($benutzerIds); } private function _getPersonId($id, $typeId) @@ -403,11 +502,16 @@ class Messages extends FHCAPI_Controller ['prestudent_id' => $id] ); } + else + { + $this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL); + } + $data = $this->getDataOrTerminateWithError($result); if (count($data) < 1) { - $this->terminateWithError('Error: Messages API no person_id found.'); + $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Person ID']), self::ERROR_TYPE_GENERAL); } $person = current($data); @@ -416,7 +520,6 @@ class Messages extends FHCAPI_Controller private function _getPrestudentIdFromUid($uid) { - // $this->terminateWithError($uid, self::ERROR_TYPE_GENERAL); $this->load->model('crm/Student_model', 'StudentModel'); $result = $this->StudentModel->loadWhere( ['student_uid' => $uid] @@ -425,7 +528,7 @@ class Messages extends FHCAPI_Controller $data = $this->getDataOrTerminateWithError($result); if (count($data) < 1) { - $this->terminateWithError('Error: Messages API no prestudent_id found.'); + $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Prestudent ID']), self::ERROR_TYPE_GENERAL); } $student = current($data); diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index 3bf48bf5b..8a2f86b5f 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -362,7 +362,6 @@ class Config extends FHCAPI_Controller $result['messages'] = [ 'title' => $this->p->t('stv', 'tab_messages'), 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Messages.js'), - 'showOnlyWithUid' => true ]; $result['grades'] = [ @@ -512,6 +511,11 @@ class Config extends FHCAPI_Controller 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Kontaktieren.js'), ]; + $result['messages'] = [ + 'title' => $this->p->t('stv', 'tab_messages'), + 'component' => absoluteJsImportUrl('public/js/components/Stv/Studentenverwaltung/Details/Messages.js'), + ]; + Events::trigger('stv_conf_students', function & () use (&$result) { return $result; }); diff --git a/application/views/Nachrichten.php b/application/views/Nachrichten.php index cf34bfd53..0d0e8e707 100644 --- a/application/views/Nachrichten.php +++ b/application/views/Nachrichten.php @@ -40,6 +40,10 @@ $configArray = [ cis-root="= CIS_ROOT; ?>" :permissions="= htmlspecialchars(json_encode($permissions)); ?>" :config="= htmlspecialchars(json_encode($configArray)); ?>" + + :id ="= htmlspecialchars(json_encode($ids)); ?>" + type-id ="= htmlspecialchars($typeid); ?>" + > diff --git a/public/js/api/factory/messages/messages.js b/public/js/api/factory/messages/messages.js index c6d4b67b6..b7b21dd8a 100644 --- a/public/js/api/factory/messages/messages.js +++ b/public/js/api/factory/messages/messages.js @@ -38,16 +38,18 @@ export default { url: 'api/frontend/v1/messages/messages/getMsgVarsLoggedInUser/' }; }, - getMessageVarsPerson(userParams){ + getMessageVarsPerson(ids, type_id){ return { method: 'post', - url: 'api/frontend/v1/messages/messages/getMessageVarsPerson/' + userParams.id + '/' + userParams.type_id + url: 'api/frontend/v1/messages/messages/getMessageVarsPerson/' + type_id, + params: {ids} }; }, - getMsgVarsPrestudent(userParams){ + getMsgVarsPrestudent(ids, type_id){ return { method: 'post', - url: 'api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + userParams.id + '/' + userParams.type_id + url: 'api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + type_id, + params: {ids} }; }, getPersonId(params){ @@ -56,28 +58,23 @@ export default { url: 'api/frontend/v1/messages/messages/getPersonId/' + params.id + '/' + params.type_id }; }, - getUid(userParams){ - return { - method: 'get', - url: 'api/frontend/v1/messages/messages/getUid/' + userParams.id + '/' + userParams.type_id - }; - }, getDataVorlage(vorlage_kurzbz){ return { method: 'get', url: 'api/frontend/v1/messages/messages/getDataVorlage/' + vorlage_kurzbz }; }, - getNameOfDefaultRecipient(params){ - return { - method: 'get', - url: 'api/frontend/v1/messages/messages/getNameOfDefaultRecipient/' + params.id + '/' + params.type_id - }; - }, - getPreviewText(userParams, params){ + getNameOfDefaultRecipients(ids, type_id){ return { method: 'post', - url: 'api/frontend/v1/messages/messages/getPreviewText/' + userParams.id + '/' + userParams.type_id, + url: 'api/frontend/v1/messages/messages/getNameOfDefaultRecipients/' + type_id, + params: {ids} + }; + }, + getPreviewText(type_id, params){ + return { + method: 'post', + url: 'api/frontend/v1/messages/messages/getPreviewText/' + type_id, params }; }, @@ -87,17 +84,10 @@ export default { url: 'api/frontend/v1/messages/messages/getReplyData/' + messageId }; }, - sendMessageFromModalContext(id, params) { + sendMessage(type_id, params) { return { method: 'post', - url: 'api/frontend/v1/messages/messages/sendMessage/' + id, - params - }; - }, - sendMessage(id, params) { - return { - method: 'post', - url: 'api/frontend/v1/messages/messages/sendMessage/' + id, + url: 'api/frontend/v1/messages/messages/sendMessage/' + type_id, params }; }, diff --git a/public/js/apps/Nachrichten.js b/public/js/apps/Nachrichten.js index 84b9ddee5..ab9baf084 100644 --- a/public/js/apps/Nachrichten.js +++ b/public/js/apps/Nachrichten.js @@ -1,14 +1,15 @@ import NewMessage from "../components/Messages/Details/NewMessage/NewDiv.js"; -import Phrasen from "../plugin/Phrasen.js"; +import Phrasen from "../plugins/Phrasen.js"; const ciPath = FHC_JS_DATA_STORAGE_OBJECT.app_root.replace(/(https:|)(^|\/\/)(.*?\/)/g, '') + FHC_JS_DATA_STORAGE_OBJECT.ci_router; const router = VueRouter.createRouter({ history: VueRouter.createWebHistory(), routes: [ - { path: `/${ciPath}/NeueNachricht/:id/:typeId`, component: NewMessage }, - { path: `/${ciPath}/NeueNachricht/:id/:typeId/:messageId`, component: NewMessage }, + { path: `/${ciPath}/NeueNachricht`, component: NewMessage, props: true }, + { path: `/${ciPath}/NeueNachricht/:id/:typeId`, component: NewMessage, props: true }, + { path: `/${ciPath}/NeueNachricht/:id/:typeId/:messageId`, component: NewMessage, props: true }, ] }); diff --git a/public/js/components/Messages/Details/NewMessage/Modal.js b/public/js/components/Messages/Details/NewMessage/Modal.js index ce9235617..47187de89 100644 --- a/public/js/components/Messages/Details/NewMessage/Modal.js +++ b/public/js/components/Messages/Details/NewMessage/Modal.js @@ -4,6 +4,8 @@ import FormInput from '../../../Form/Input.js'; import ListBox from "../../../../../../index.ci.php/public/js/components/primevue/listbox/listbox.esm.min.js"; import DropdownComponent from "../../../VorlagenDropdown/VorlagenDropdown.js"; +import ApiMessages from '../../../../api/factory/messages/messages.js'; + export default { name: "ModalNewMessages", components: { @@ -14,13 +16,9 @@ export default { ListBox }, props: { - endpoint: { - type: Object, - required: true - }, typeId: String, id: { - type: [Number, String], + type: Array, required: true }, messageId: { @@ -43,6 +41,8 @@ export default { vorlagen: [], recipientsArray: [], defaultRecipient: null, + defaultRecipients: [], + defaultRecipientString: null, editor: null, fieldsUser: [], fieldsPerson: [], @@ -56,7 +56,6 @@ export default { previewText: null, previewBody: "", replyData: null, - uid: null, } }, methods: { @@ -111,34 +110,28 @@ export default { }, sendMessage() { const data = new FormData(); - const params = { - id: this.id, - type_id: this.typeId - }; - const merged = { - ...this.formData, - ...params - }; - data.append('data', JSON.stringify(merged)); + data.append('data', JSON.stringify(this.formData)); + data.append('ids', JSON.stringify(this.id)); return this.$refs.formMessage - .call(this.endpoint.sendMessageFromModalContext(this.uid, data)) + .call(ApiMessages.sendMessage(this.typeId, data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideModal('modalNewMessage'); this.resetForm(); }).catch(this.$fhcAlert.handleSystemError) .finally(() => { - //this.resetForm(); - //closeModal - //closewindwo + + //just emit if no multitasking + if(this.id.length == 1){ this.$emit('reloadTable'); + } } ); }, getDataVorlage(vorlage_kurzbz){ return this.$api - .call(this.endpoint.getDataVorlage(vorlage_kurzbz)) + .call(ApiMessages.getDataVorlage(vorlage_kurzbz)) .then(response => { this.formData.body = response.data.text; this.formData.subject = response.data.subject; @@ -146,17 +139,17 @@ export default { }, getPreviewText(){ const data = new FormData(); - data.append('data', JSON.stringify(this.formData.body)); + data.append('ids', JSON.stringify(this.id)); + return this.$api - .call(this.endpoint.getPreviewText({ - id: this.id, - type_id: this.typeId}, data)) + .call(ApiMessages.getPreviewText( + this.typeId, data)) .then(response => { - this.previewText = response.data; + const previews = response.data; + this.previewText = previews[this.defaultRecipient]; }).catch(this.$fhcAlert.handleSystemError) .finally(() => { - //this.resetForm(); //closeModal //closewindwo }); @@ -171,7 +164,7 @@ export default { this.editor.save(); } else { - console.error("Editor instance is not available."); + console.error(this.$p.t('messages', 'errorEditorNotAvailable')); } }, resetForm(){ @@ -180,6 +173,7 @@ export default { body: null, subject: null, }; + this.$emit('resetMessageId'); if (this.editor) { @@ -201,18 +195,6 @@ export default { this.previewBody = this.previewText; }); }, - getUid(id, typeId){ - const params = { - id: id, - type_id: typeId - }; - this.$api - .call(this.endpoint.getUid(params)) - .then(result => { - this.uid = result.data; - }) - .catch(this.$fhcAlert.handleSystemError); - }, show(){ this.$refs.modalNewMessage.show(); }, @@ -245,7 +227,7 @@ export default { if (!newMessageId) return; try { - const result = await this.$api.call(this.endpoint.getReplyData(newMessageId)); + const result = await this.$api.call(ApiMessages.getReplyData(newMessageId)); this.replyData = result.data; if (this.replyData.length > 0) { @@ -260,15 +242,9 @@ export default { } }, created(){ - this.getUid(this.id, this.typeId); - if(this.typeId == 'person_id' || this.typeId == 'mitarbeiter_uid'){ - const params = { - id: this.id, - type_id: this.typeId - }; this.$api - .call(this.endpoint.getMessageVarsPerson(params)) + .call(ApiMessages.getMessageVarsPerson(this.id, this.typeId)) .then(result => { this.fieldsPerson = result.data; const person = this.fieldsPerson[0]; @@ -281,12 +257,8 @@ export default { } if(this.typeId == 'prestudent_id' || this.typeId == 'uid'){ - const params = { - id: this.id, - type_id: this.typeId - }; this.$api - .call(this.endpoint.getMsgVarsPrestudent(params)) + .call(ApiMessages.getMsgVarsPrestudent(this.id, this.typeId)) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; @@ -299,7 +271,7 @@ export default { } this.$api - .call(this.endpoint.getMsgVarsLoggedInUser()) + .call(ApiMessages.getMsgVarsLoggedInUser()) .then(result => { this.fieldsUser = result.data; const user = this.fieldsUser; @@ -311,21 +283,18 @@ export default { .catch(this.$fhcAlert.handleSystemError); this.$api - .call(this.endpoint.getNameOfDefaultRecipient({ - id: this.id, - type_id: this.typeId})) + .call(ApiMessages.getNameOfDefaultRecipients(this.id, this.typeId)) .then(result => { - this.defaultRecipient = result.data; - this.recipientsArray.push({ - 'uid': this.uid, - 'details': this.defaultRecipient}); + this.defaultRecipients = result.data; + this.defaultRecipientString = Object.values(this.defaultRecipients).join("; "); + }) .catch(this.$fhcAlert.handleSystemError); //case of reply if(this.messageId) { this.$api - .call(this.endpoint.getReplyData(this.messageId)) + .call(ApiMessages.getReplyData(this.messageId)) .then(result => { this.replyData = result.data; this.formData.subject = this.replyData[0].replySubject; @@ -381,7 +350,7 @@ export default { type="text" name="recipient" :label="$p.t('messages/recipient')" - v-model="defaultRecipient" + v-model="defaultRecipientString" disabled > @@ -502,17 +471,17 @@ export default { >