diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index adf1d52e9..ac107f687 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -9,6 +9,14 @@ class Messages extends FHCAPI_Controller { parent::__construct([ 'getMessages' => ['admin:r', 'assistenz:r'], + 'getVorlagen' => ['admin:r', 'assistenz:r'], + 'getMessageVarsPerson' => ['admin:r', 'assistenz:r'], + 'getMsgVarsPrestudent' => ['admin:r', 'assistenz:r'], + 'getMsgVarsLoggedInUser' => ['admin:r', 'assistenz:r'], + 'getNameOfDefaultRecipient' => ['admin:r', 'assistenz:r'], + 'sendMessage' => ['admin:r', 'assistenz:r'], + 'deleteMessage' => ['admin:r', 'assistenz:r'], + 'getVorlagentext' => ['admin:r', 'assistenz:r'], ]); //Load Models @@ -20,6 +28,7 @@ class Messages extends FHCAPI_Controller // Load Libraries $this->load->library('VariableLib', ['uid' => getAuthUID()]); $this->load->library('form_validation'); + $this->load->library('MessageLib'); // Load language phrases $this->loadPhrases([ @@ -29,11 +38,17 @@ class Messages extends FHCAPI_Controller public function getMessages($id, $type_id) { - //$this->terminateWithError("in backend " . $type_id . ": " . $id, self::ERROR_TYPE_GENERAL); - - if ($type_id != "person_id") + switch($type_id) { - $this->terminateWithError("logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); + case 'uid': + $id = $this->_getPersonIdFromUid($id); + break; + case 'person_id': + $id = $id; + break; + default: + $this->terminateWithError("MESSAGES::getMessages logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); + break; } $result = $this->MessageModel->getMessagesForTable($id); @@ -42,4 +57,227 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($data); } + + public function getVorlagen() + { + //get oe of user + $uid = getAuthUID(); + $this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $result = $this->BenutzerfunktionModel->getBenutzerfunktionByUid($uid, 'oezuordnung'); + + $data = $this->getDataOrTerminateWithError($result); + $oe_kurzbz = current($data); + + // $this->terminateWithError("oe: ". $oe_kurzbz->oe_kurzbz, self::ERROR_TYPE_GENERAL); + + $this->load->model('system/Vorlage_model', 'VorlageModel'); + + //39 Stück Variante OE + $result = $this->VorlageModel->getAllVorlagenByOe($oe_kurzbz->oe_kurzbz); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + + //IF ADMIN 167 + $this->VorlageModel->addOrder('vorlage_kurzbz', 'ASC'); + //only HTML-vorlagen -> for admin + $result = $this->VorlageModel->loadWhere( + array( + 'mimetype' => 'text/html' + )); + + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getVorlagentext($vorlage_kurzbz) + { + //$this->terminateWithError("vor " . $vorlage_kurzbz, self::ERROR_TYPE_GENERAL); + //$studiengang_kz = 227; //TODO(Manu) check dynamisieren NULL + $studiengang_kz = 0; + $this->load->model('system/Vorlagestudiengang_model', 'VorlagestudiengangModel'); + $this->VorlagestudiengangModel->addOrder('version', 'DESC'); + + $result = $this->VorlagestudiengangModel->loadWhere( + [ + 'vorlage_kurzbz' =>$vorlage_kurzbz, + 'studiengang_kz' => $studiengang_kz + ]); + + $data = $this->getDataOrTerminateWithError($result); + + //not correct with Vorlage + $vorlage = current($data); + + //$this->terminateWithSuccess($data); + $this->terminateWithSuccess($vorlage->text); + } + + public function getMessageVarsPerson() + { + $result = $this->MessageModel->getMessageVarsPerson(); + + $data = $this->getDataOrTerminateWithError($result); + + + $this->terminateWithSuccess($data); + } + + public function getMsgVarsPrestudent($uid) + { + + $prestudent_id = $this-> _getPrestudentIdFromUid($uid); + + // $this->terminateWithError("prestudent_id " . $prestudent_id, self::ERROR_TYPE_GENERAL); + + $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); + + $data = $this->getDataOrTerminateWithError($result); + + + $this->terminateWithSuccess($data); + } + + public function getMsgVarsLoggedInUser() + { + $uid = getAuthUID(); + + $result = $this->MessageModel->getMsgVarsLoggedInUser(); + + $data = $this->getDataOrTerminateWithError($result); + + + $this->terminateWithSuccess($data); + } + + public function getNameOfDefaultRecipient($id, $type_id) + { + switch($type_id) + { + case 'uid': + $id = $this->_getPersonIdFromUid($id); + break; + case 'person_id': + $id = $id; + break; + default: + $this->terminateWithError("MESSAGES::getNameOfDefaultRecipient logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); + break; + } + + $this->load->model('person/Person_model', 'PersonModel'); + + $result = $this->PersonModel->load($id); + //$this->terminateWithSuccess($result); + $data = $this->getDataOrTerminateWithError($result); + $name = current($data); + + $this->terminateWithSuccess($name->vorname . " " . $name->nachname ); + } + + public function sendMessage($recipient_id) + { + //TODO(manu) Problems with Vorlagen... + //TODO(Manu) Problems with VARS + $receiversPersonId = $this->_getPersonIdFromUid($recipient_id); + + $uid = getAuthUID(); + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['uid' => $uid] + ); + + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + if (isset($_POST['data'])) + { + $data = json_decode($_POST['data']); + unset($_POST['data']); + foreach ($data as $k => $v) { + $_POST[$k] = $v; + } + } + + $subject = $this->input->post('subject'); + + $body = $this->input->post('body'); + + // $this->terminateWithError("rp_id " . $receiversPersonId, self::ERROR_TYPE_GENERAL); + +/* $subject = $this->input->post('subject'); + + $formData = $this->input->post('data');*/ + + //$_POST['subject'] = $formData['subject']; + // $subject = $formData['subject']; + // $body = $formData['body']; + + // $subject = isset($_POST['subject']) ? $_POST['subject'] : null; + // $body = isset($_POST['body']) ? $_POST['body'] : null; + + // $this->terminateWithError("person_id " . $receiversPersonId, self::ERROR_TYPE_GENERAL); + + // $this->terminateWithError("subject " . $subject, self::ERROR_TYPE_GENERAL); + // $this->terminateWithError("body " . $body, self::ERROR_TYPE_GENERAL); + + // $this->terminateWithError("person_id " . $benutzer->person_id, self::ERROR_TYPE_GENERAL); + // $this->terminateWithError("subject " . $subject, self::ERROR_TYPE_GENERAL); + $result = $this->messagelib->sendMessageUser($receiversPersonId, $subject, $body, $benutzer->person_id); + + $this->terminateWithSuccess($result); + } + + public function deleteMessage($messageId) + { + // Start DB transaction + $this->db->trans_begin(); + + $result = $this->MessageModel->deleteMessageRecipient($messageId); + if (isError($result)) { + return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + + $result = $this->MessageModel->deleteMessageStatus($messageId); + if (isError($result)) { + return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + + $result = $this->MessageModel->deleteMessage($messageId); + if (isError($result)) { + return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); + } + + $this->db->trans_commit(); + + $this->terminateWithSuccess($result); + } + + private function _getPersonIdFromUid($uid) + { + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $result = $this->BenutzerModel->loadWhere( + ['uid' => $uid] + ); + + $data = $this->getDataOrTerminateWithError($result); + $benutzer = current($data); + + return $benutzer->person_id; + } + + private function _getPrestudentIdFromUid($uid) + { + $this->load->model('crm/Student_model', 'StudentModel'); + $result = $this->StudentModel->loadWhere( + ['student_uid' => $uid] + ); + + $data = $this->getDataOrTerminateWithError($result); + $student = current($data); + + return $student->prestudent_id; + } } \ No newline at end of file diff --git a/application/controllers/api/frontend/v1/vorlagen/Vorlagen.php b/application/controllers/api/frontend/v1/vorlagen/Vorlagen.php new file mode 100644 index 000000000..01edb33d1 --- /dev/null +++ b/application/controllers/api/frontend/v1/vorlagen/Vorlagen.php @@ -0,0 +1,63 @@ + ['admin:r', 'assistenz:r'], + 'getVorlagenByLoggedInUser' => ['admin:r', 'assistenz:r'], + ]); + + //Load Models + $this->load->model('system/Vorlage_model', 'VorlageModel'); + + // Additional Permission Checks + //TODO(manu) check permissions + + // Load Libraries + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + $this->load->library('form_validation'); + $this->load->library('VorlageLib'); + + // Load language phrases + $this->loadPhrases([ + 'ui' + ]); + } + + public function getVorlagen() + { + $this->load->model('system/Vorlage_model', 'VorlageModel'); + + $this->VorlageModel->addOrder('vorlage_kurzbz', 'ASC'); + + $result = $this->VorlageModel->loadWhere( + array( + 'mimetype' => 'text/html' + )); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getVorlagenByLoggedInUser() + { + //get oe of user + $uid = getAuthUID(); + $this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $result = $this->BenutzerfunktionModel->getBenutzerfunktionByUid($uid, 'oezuordnung'); + + $data = $this->getDataOrTerminateWithError($result); + $oe_kurzbz = current($data); + + $result = $this->VorlageModel->getAllVorlagenByOe($oe_kurzbz->oe_kurzbz); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + +} \ No newline at end of file diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 1b201fc1b..7ecb54a9e 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -282,4 +282,46 @@ class Message_model extends DB_Model return $this->execQuery($sql, $parametersArray); } + + /** + * Deletes a messages from tableMessages and tbl_msg_recipient + * TODO(MANU) CHECK IF NECESSARY + * dependency with other tables + * in case of reply... more messages + * maybe anonimize it + * @param $message_id + * @return boolean success + */ + public function deleteMessageRecipient($message_id) + { + $sql = " + DELETE FROM public.tbl_msg_recipient + WHERE message_id = ?; + "; + + return $this->execQuery($sql, array($message_id)); + } + + + public function deleteMessageStatus($message_id) + { + $sql = " + DELETE FROM public.tbl_msg_status + WHERE message_id = ?; + "; + + return $this->execQuery($sql, array($message_id)); + } + + public function deleteMessage($message_id) + { + $sql = " + DELETE FROM public.tbl_msg_message + WHERE message_id = ?; + "; + + return $this->execQuery($sql, array($message_id)); + } + + } diff --git a/application/models/system/Vorlage_model.php b/application/models/system/Vorlage_model.php index 8022e71fc..69aa0aa3f 100644 --- a/application/models/system/Vorlage_model.php +++ b/application/models/system/Vorlage_model.php @@ -21,4 +21,120 @@ class Vorlage_model extends DB_Model return $this->execQuery($query); } + + /** + * Returns all Vorlagen + * that belongs to the organisation units of the user + * and the parents of those organisation units until the root of the + * @param Array Array of $oe_kurzbz + * @return object Array of Vorlagen + */ + public function getAllVorlagenByOe($oe_kurzbz) + { + // Loads library OrganisationseinheitLib + $this->load->library('OrganisationseinheitLib'); + + $vorlage = success(array()); // Default value + + $table = '( + SELECT v.vorlage_kurzbz, + v.bezeichnung, + vs.version, + vs.oe_kurzbz, + vs.aktiv, + vs.subject, + vs.text, + v.mimetype + FROM tbl_vorlagestudiengang vs + JOIN tbl_vorlage v USING(vorlage_kurzbz) + ) templates'; + + $alias = 'templates'; + + $fields = array( + 'templates.vorlage_kurzbz AS id', + 'templates.bezeichnung || \' (\' || UPPER(templates.oe_kurzbz) || \')\' AS description' + ); + + $where = 'templates.aktiv = TRUE + AND templates.subject IS NOT NULL + AND templates.text IS NOT NULL + AND templates.mimetype = \'text/html\' + GROUP BY 1, 2, 3'; + + $order_by = 'description ASC'; + + if (!is_array($oe_kurzbz)) + { + $vorlage = $this->organisationseinheitlib->treeSearchEntire( + $table, + $alias, + $fields, + $where, + $order_by, + $oe_kurzbz + ); + } + else // is an array + { + // Get the vorlage for each organisation unit + foreach($oe_kurzbz as $val) + { + $tmpVorlage = $this->organisationseinheitlib->treeSearchEntire( + $table, + $alias, + $fields, + $where, + $order_by, + $val + ); + + // Everything is ok and data are inside + if (hasData($tmpVorlage)) + { + // If it's the first vorlage copy it + if (!hasData($vorlage)) + { + for ($j = 0; $j < count(getData($tmpVorlage)); $j++) + { + if (getData($tmpVorlage)[$j]->id != '') + { + array_push($vorlage->retval, getData($tmpVorlage)[$j]); + } + } + } + else // checks for duplicates, if it's not already present push it into the array getData($vorlage) + { + for ($j = 0; $j < count(getData($tmpVorlage)); $j++) + { + $found = false; + $currentTmpVorlageData = null; + + for ($i = 0; $i < count(getData($vorlage)); $i++) + { + $currentTmpVorlageData = getData($tmpVorlage)[$j]; + + if (getData($vorlage)[$i]->id == getData($tmpVorlage)[$j]->id + && getData($vorlage)[$i]->_pk == getData($tmpVorlage)[$j]->_pk + && getData($vorlage)[$i]->_ppk == getData($tmpVorlage)[$j]->_ppk + && getData($vorlage)[$i]->_jtpk == getData($tmpVorlage)[$j]->_jtpk) + { + $found = true; + break; + } + } + + if (!$found && $currentTmpVorlageData->id != '') + { + array_push($vorlage->retval, $currentTmpVorlageData); + } + } + } + } + } + } + + return $vorlage; + } + } diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 7bc510b6e..8a4a2132a 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -34,6 +34,7 @@ import cms from "./cms.js"; import lehre from "./lehre.js"; import addons from "./addons.js"; import messages from "./messages.js"; +import vorlagen from "./vorlagen.js"; export default { search, @@ -54,5 +55,6 @@ export default { cms, lehre, addons, - messages + messages, + vorlagen }; diff --git a/public/js/api/messages/person.js b/public/js/api/messages/person.js index baf8bd39f..6a0ac8c7c 100644 --- a/public/js/api/messages/person.js +++ b/public/js/api/messages/person.js @@ -2,4 +2,33 @@ export default { getMessages(url, config, params){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessages/' + params.id + '/' + params.type); }, + getVorlagen(){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getVorlagen/'); + }, + getMsgVarsLoggedInUser(){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsLoggedInUser/'); + }, + getMessageVarsPerson(){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessageVarsPerson/'); + }, + getMsgVarsPrestudent(uid){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + uid); + }, + getVorlagentext(vorlage_kurzbz){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getVorlagentext/' + vorlage_kurzbz); + }, + getNameOfDefaultRecipient(params){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getNameOfDefaultRecipient/' + params.id + '/' + params.type_id); + }, + sendMessage(form, id, data) { + console.log("factory " + id); + console.log(JSON.stringify(data)); + + return this.$fhcApi.post(form, 'api/frontend/v1/messages/messages/sendMessage/' + id, + data + ); + }, + deleteMessage(messageId){ + return this.$fhcApi.post('api/frontend/v1/messages/messages/deleteMessage/' + messageId); + } } \ No newline at end of file diff --git a/public/js/api/vorlagen.js b/public/js/api/vorlagen.js new file mode 100644 index 000000000..2933ccf97 --- /dev/null +++ b/public/js/api/vorlagen.js @@ -0,0 +1,8 @@ +export default { + getVorlagen() { + return this.$fhcApi.get('api/frontend/v1/vorlagen/vorlagen/getVorlagen/'); + }, + getVorlagenByLoggedInUser() { + return this.$fhcApi.get('api/frontend/v1/vorlagen/vorlagen/getVorlagenByLoggedInUser/'); + } +} \ No newline at end of file diff --git a/public/js/components/Messages/Details/NewMessage.js b/public/js/components/Messages/Details/NewMessage.js index bf60842d2..2d85c8e00 100644 --- a/public/js/components/Messages/Details/NewMessage.js +++ b/public/js/components/Messages/Details/NewMessage.js @@ -1,12 +1,448 @@ +import FormForm from '../../Form/Form.js'; +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'; + + export default { + components: { + FormForm, + FormInput, + ListBox, + DropdownComponent + }, + props: { + endpoint: { + type: String, + required: true + }, + typeId: String, + id: { + type: [Number, String], + required: true + }, + }, data(){ return { - + formData: { + recipient: this.id, + subject: null, + body: null, + vorlage_kurzbz: null, + selectedValue: '', + }, + statusNew: true, + vorlagen: [], + defaultRecipient: null, + editor: null, + isVisible: true, + fieldsUser: [], + fieldsPerson: [], + fieldsPrestudent: [], + selectedFieldPrestudent: null, + selectedFieldUser: null, + selectedFieldPerson: null, + itemsPrestudent: [], + itemsPerson: [], + itemsUser: [], + selectedFieldStudent: null, + itemsStudent: [ + { label: "Variable 1", value: "var1" }, + { label: "Variable 2", value: "var2" }, + { label: "Variable 3", value: "var3" } + ] } }, + methods: { + initTinyMCE() { + const vm = this; + tinymce.init({ + target: this.$refs.editor.$refs.input, //Important: not selector: to enable multiple import of component + //height: 800, + //plugins: ['lists'], + toolbar: 'styleselect | bold italic underline | alignleft aligncenter alignright alignjustify', + style_formats: [ + {title: 'Blocks', block: 'div'}, + {title: 'Paragraph', block: 'p'}, + {title: 'Heading 1', block: 'h1'}, + {title: 'Heading 2', block: 'h2'}, + {title: 'Heading 3', block: 'h3'}, + {title: 'Heading 4', block: 'h4'}, + {title: 'Heading 5', block: 'h5'}, + {title: 'Heading 6', block: 'h6'}, + ], + autoresize_bottom_margin: 16, + + setup: (editor) => { + vm.editor = editor; + + editor.on('input', () => { + const newContent = editor.getContent(); + vm.formData.body = newContent; + }); + }, + }); + }, + updateText(value) { + this.formData.body = value; + }, + sendMessage(){ + //TODO(Manu) check default recipient(s) + const data = new FormData(); + + data.append('data', JSON.stringify(this.formData)); + return this.$fhcApi.factory.messages.person.sendMessage(this.$refs.formVorlage, this.id, data) + .then(response => { + this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); + //this.hideModal('messageModal'); + this.resetForm(); + }).catch(this.$fhcAlert.handleSystemError) + .finally(() => { + //this.resetForm(); + //closeModal + //closewindwo + } + ); + }, + getVorlagentext(vorlage_kurzbz){ + //console.log(typeof vorlage_kurzbz); + return this.$fhcApi.factory.messages.person.getVorlagentext(vorlage_kurzbz) + .then(response => { + //this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); + //this.hideModal('messageModal'); + //this.resetForm(); + //TODO(Manu) CHECK + this.formData.body = response.data; + }).catch(this.$fhcAlert.handleSystemError) + .finally(() => { + //this.resetForm(); + //closeModal + //closewindwo + }); + }, + insertVariable(selectedItem){ + if (this.editor) { + this.editor.insertContent(selectedItem.value + " "); + } else { + console.error("Editor instance is not available."); + } + }, + //TODO(Manu) refactor +/* insertVariablePrestudent() { + if (this.editor) { + //const lastVariable = this.selectedFieldsPrestudent[this.selectedFieldsPrestudent.length - 1].value; + const lastVariable = this.selectedFieldPrestudent.value; + + //Use insertContent method + this.editor.insertContent(lastVariable + " "); + } else { + console.error("Editor instance is not available."); + } + },*/ +/* insertVariablePrestudentByClick(selectedItem) { + + if (selectedItem) { + this.editor.insertContent(selectedItem.value + " "); + console.log("Eingefügte Variable:", selectedItem); + } else { + console.warn("Keine Variable ausgewählt!"); + } + }, + + insertVariablePerson() { + if (this.editor) { + //const lastVariable = this.selectedFieldsPrestudent[this.selectedFieldsPrestudent.length - 1].value; + const lastVariable = this.selectedFieldPerson.value; + + //Use insertContent method + this.editor.insertContent(lastVariable + " "); + } else { + console.error("Editor instance is not available."); + } + }, + insertVariableUser() { + if (this.editor) { + console.log(this.selectedFieldUser.value); + const lastVariable = this.selectedFieldUser.value; + + //Multiple + //const lastVariable = this.selectedFieldsPrestudent[this.selectedFieldsPrestudent.length - 1].value; + + //Use insertContent method + this.editor.insertContent(lastVariable + " "); + this.selectedFieldUser = null; + } else { + console.error("Editor instance is not available."); + } + }, + insertVariableStudent(selectedItem) { + if (selectedItem) { + console.log("Eingefügte Variable:", selectedItem); + this.editor.insertContent(selectedItem.value + " "); + } else { + console.warn("Keine Variable ausgewählt!"); + } + },*/ + replyMessage(message_id){ + console.log("auf message " + message_id + " antworten"); + }, + resetForm(){ + this.formData = { + vorlage_kurzbz: null, + body: null, + subject: null, + }; + if (this.editor) { + this.editor.setContent(""); + } + this.$refs.dropdownComp.setValue(null); + + }, + toggleDivNewMessage(){ + this.isVisible = !this.isVisible; + }, + handleSelectedVorlage(vorlage_kurzbz) { + if (typeof vorlage_kurzbz === "string") { + this.getVorlagentext(vorlage_kurzbz); + this.formData.subject = vorlage_kurzbz; + } + }, + }, + watch: { + 'formData.body': { + handler(newVal) { + const tinymcsVal = this.editor.getContent(); + + if (newVal && tinymcsVal != newVal) { + //Inhalt des Editors aktualisieren + this.editor.setContent(newVal); + } + } + }, + 'formData.vorlage_kurzbz': { + handler(newVal){ + // console.log("Vorlage: " + newVal); + + if (newVal && newVal != null) { + this.formData.subject = newVal; + return this.getVorlagentext(newVal); + } + //TODO(Manu) own function or retval to getVorlagentext + //component VorlagenComponent + + } + } + }, + created(){ + + if(this.typeId == 'person_id'){ + this.$fhcApi.factory.messages.person.getMessageVarsPerson() + .then(result => { + this.fieldsPerson = result.data; + this.itemsPerson = Object.entries(this.fieldsPerson).map(([key, value]) => ({ + label: value, + value: '{' + value + '}' + })); + }) + .catch(this.$fhcAlert.handleSystemError); + } + + if(this.typeId == 'uid') { + this.$fhcApi.factory.messages.person.getMsgVarsPrestudent(this.id) + .then(result => { + this.fieldsPrestudent = result.data; + const prestudent = this.fieldsPrestudent[0]; + //Just for testing with inserting values +/* this.itemsPrestudent = Object.entries(prestudent).map(([key, value]) => ({ + label: key, + value: value + }));*/ + this.itemsPrestudent = Object.entries(prestudent).map(([key, value]) => ({ + label: key, + value: '{' + key + '}' + })); + }) + .catch(this.$fhcAlert.handleSystemError); + } + + this.$fhcApi.factory.messages.person.getMsgVarsLoggedInUser() + .then(result => { + this.fieldsUser = result.data; + const user = this.fieldsUser; + this.itemsUser = Object.entries(user).map(([key, value]) => ({ + label: value, + value: '{' + value + '}' + })); + }) + .catch(this.$fhcAlert.handleSystemError); + + this.$fhcApi.factory.messages.person.getNameOfDefaultRecipient({ + id: this.id, + type_id: this.typeId}) + .then(result => { + this.defaultRecipient = result.data; + }) + .catch(this.$fhcAlert.handleSystemError); + }, + async mounted() { + this.initTinyMCE(); + }, + beforeDestroy() { + this.editor.destroy(); + }, template: `
` diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index c4fd4d4d7..0025d7b47 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -1,12 +1,15 @@ import {CoreFilterCmpt} from "../../filter/Filter.js"; import FormForm from '../../Form/Form.js'; -//import FormInput from '../../Form/Input.js'; export default { components: { CoreFilterCmpt, FormForm, - // FormInput + }, + inject: { + cisRoot: { + from: 'cisRoot' + }, }, props: { endpoint: { @@ -121,7 +124,7 @@ export default { button.addEventListener( 'click', () => - this.deleteMessage(cell.getData().message_id) + this.actionDeleteMessage(cell.getData().message_id) ); container.append(button); @@ -197,7 +200,6 @@ export default { const selectedMessage = row.getData().message_id; const body = row.getData().body; this.previewBody = body; - console.log(selectedMessage); } }, ], @@ -209,11 +211,45 @@ export default { reply(message_id){ console.log("in reply " + message_id); }, + actionDeleteMessage(message_id){ + this.$fhcAlert + .confirmDelete() + .then(result => result + ? message_id + : Promise.reject({handled: true})) + .then(this.deleteMessage) + .catch(this.$fhcAlert.handleSystemError); + }, deleteMessage(message_id){ - console.log("deleteMessage " + message_id); + // console.log("deleteMessage " + message_id); + return this.$fhcApi.factory.messages.person.deleteMessage(message_id) + .then(response => { + this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); + }).catch(this.$fhcAlert.handleSystemError) + .finally(()=> { + window.scrollTo(0, 0); + this.reload(); + }); }, actionNewMessage(){ - console.log("action new message"); + //console.log("action new message"); + if (this.openMode == "window") { + console.log("openInNewWindow") + const linkWindowNewMessage = this.cisRoot + '/public/js/components/Messages/Details/NewMessage.js'; + window.open(linkWindowNewMessage, '_blank'); + } + else if (this.openmode == "modal"){ + console.log("open with bootstrap Modal"); + } + else if (this.openmode == "showDiv"){ + console.log("open div in NewMessage.js"); + //emit to NewMessage.js + } + else + console.log("no valid openmode: yet to be developed"); + }, + reload() { + this.$refs.table.reloadTable(); }, }, computed: { @@ -238,8 +274,9 @@ export default { }, template: `