From cc0572b386e54f03c822d0b5dc3c46153cd27b0e Mon Sep 17 00:00:00 2001 From: ma0068 Date: Mon, 28 Jul 2025 11:44:06 +0200 Subject: [PATCH] use endpoint for Messages, refactor component Vorlagendropdown to fhcapi --- public/js/api/factory/vorlagen.js | 32 +++++++++++++++++++ .../Messages/Details/NewMessage/Modal.js | 24 +++++++------- .../Messages/Details/NewMessage/NewDiv.js | 21 ++++++------ .../Messages/Details/TableMessages.js | 10 +++--- public/js/components/Messages/Messages.js | 2 +- .../Studentenverwaltung/Details/Messages.js | 8 ++++- .../VorlagenDropdown/VorlagenDropdown.js | 8 +++-- 7 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 public/js/api/factory/vorlagen.js diff --git a/public/js/api/factory/vorlagen.js b/public/js/api/factory/vorlagen.js new file mode 100644 index 000000000..f62f65e47 --- /dev/null +++ b/public/js/api/factory/vorlagen.js @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2025 fhcomplete.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +export default { + getVorlagen() { + return { + method: 'get', + url: 'api/frontend/v1/vorlagen/vorlagen/getVorlagen/' + }; + }, + getVorlagenByLoggedInUser() { + return { + method: 'get', + url: 'api/frontend/v1/vorlagen/vorlagen/getVorlagenByLoggedInUser/' + }; + }, + +}; diff --git a/public/js/components/Messages/Details/NewMessage/Modal.js b/public/js/components/Messages/Details/NewMessage/Modal.js index 57573a9ba..24c282cb4 100644 --- a/public/js/components/Messages/Details/NewMessage/Modal.js +++ b/public/js/components/Messages/Details/NewMessage/Modal.js @@ -4,8 +4,6 @@ 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: { @@ -17,7 +15,7 @@ export default { }, props: { endpoint: { - type: String, + type: Object, required: true }, typeId: String, @@ -124,7 +122,7 @@ export default { data.append('data', JSON.stringify(merged)); return this.$refs.formMessage - .call(ApiMessages.sendMessageFromModalContext(this.uid, data)) + .call(this.endpoint.sendMessageFromModalContext(this.uid, data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideModal('modalNewMessage'); @@ -140,7 +138,7 @@ export default { }, getVorlagentext(vorlage_kurzbz){ return this.$api - .call(ApiMessages.getVorlagentext(vorlage_kurzbz)) + .call(this.endpoint.getVorlagentext(vorlage_kurzbz)) .then(response => { this.formData.body = response.data; }).catch(this.$fhcAlert.handleSystemError) @@ -155,7 +153,7 @@ export default { data.append('data', JSON.stringify(this.formData.body)); return this.$api - .call(ApiMessages.getPreviewText({ + .call(this.endpoint.getPreviewText({ id: this.id, type_id: this.typeId}, data)) .then(response => { @@ -214,7 +212,7 @@ export default { type_id: typeId }; this.$api - .call(ApiMessages.getUid(params)) + .call(this.endpoint.getUid(params)) .then(result => { this.uid = result.data; }) @@ -252,7 +250,7 @@ export default { if (!newMessageId) return; try { - const result = await this.$api.call(ApiMessages.getReplyData(newMessageId)); + const result = await this.$api.call(this.endpoint.getReplyData(newMessageId)); this.replyData = result.data; if (this.replyData.length > 0) { @@ -275,7 +273,7 @@ export default { type_id: this.typeId }; this.$api - .call(ApiMessages.getMessageVarsPerson(params)) + .call(this.endpoint.getMessageVarsPerson(params)) .then(result => { this.fieldsPerson = result.data; const person = this.fieldsPerson[0]; @@ -293,7 +291,7 @@ export default { type_id: this.typeId }; this.$api - .call(ApiMessages.getMsgVarsPrestudent(params)) + .call(this.endpoint.getMsgVarsPrestudent(params)) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; @@ -306,7 +304,7 @@ export default { } this.$api - .call(ApiMessages.getMsgVarsLoggedInUser()) + .call(this.endpoint.getMsgVarsLoggedInUser()) .then(result => { this.fieldsUser = result.data; const user = this.fieldsUser; @@ -318,7 +316,7 @@ export default { .catch(this.$fhcAlert.handleSystemError); this.$api - .call(ApiMessages.getNameOfDefaultRecipient({ + .call(this.endpoint.getNameOfDefaultRecipient({ id: this.id, type_id: this.typeId})) .then(result => { @@ -332,7 +330,7 @@ export default { //case of reply if(this.messageId) { this.$api - .call(ApiMessages.getReplyData(this.messageId)) + .call(this.endpoint.getReplyData(this.messageId)) .then(result => { this.replyData = result.data; this.formData.subject = this.replyData[0].replySubject; diff --git a/public/js/components/Messages/Details/NewMessage/NewDiv.js b/public/js/components/Messages/Details/NewMessage/NewDiv.js index d070ff379..7622f0928 100644 --- a/public/js/components/Messages/Details/NewMessage/NewDiv.js +++ b/public/js/components/Messages/Details/NewMessage/NewDiv.js @@ -2,7 +2,6 @@ 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'; -import ApiMessages from "../../../../api/factory/messages/messages.js"; export default { name: "ComponentNewMessages", @@ -14,7 +13,7 @@ export default { }, props: { endpoint: { - type: String, + type: Object, required: true }, openMode: String, @@ -119,7 +118,7 @@ export default { }; data.append('data', JSON.stringify(merged)); return this.$api - .call(ApiMessages.sendMessage(this.uid, data)) + .call(this.endpoint.sendMessage(this.uid, data)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); this.hideTemplate(); @@ -139,7 +138,7 @@ export default { }, getVorlagentext(vorlage_kurzbz){ return this.$api - .call(ApiMessages.getVorlagentext(vorlage_kurzbz)) + .call(this.endpoint.getVorlagentext(vorlage_kurzbz)) .then(response => { this.formData.body = response.data; }).catch(this.$fhcAlert.handleSystemError) @@ -152,7 +151,7 @@ export default { data.append('data', JSON.stringify(this.formData.body)); return this.$api - .call(ApiMessages.getPreviewText({ + .call(this.endpoint.getPreviewText({ id: this.id, type_id: this.typeId}, data)) .then(response => { @@ -226,7 +225,7 @@ export default { type_id: typeId }; this.$api - .call(ApiMessages.getUid(params)) + .call(this.endpoint.getUid(params)) .then(result => { this.uid = result.data; }) @@ -264,7 +263,7 @@ export default { }; this.$api - .call(ApiMessages.getMessageVarsPerson(params)) + .call(this.endpoint.getMessageVarsPerson(params)) .then(result => { this.fieldsPerson = result.data; const person = this.fieldsPerson[0]; @@ -282,7 +281,7 @@ export default { type_id: this.typeId }; this.$api - .call(ApiMessages.getMsgVarsPrestudent(params)) + .call(this.endpoint.getMsgVarsPrestudent(params)) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; @@ -296,7 +295,7 @@ export default { } this.$api - .call(ApiMessages.getMsgVarsLoggedInUser()) + .call(this.endpoint.getMsgVarsLoggedInUser()) .then(result => { this.fieldsUser = result.data; const user = this.fieldsUser; @@ -308,7 +307,7 @@ export default { .catch(this.$fhcAlert.handleSystemError); this.$api - .call(ApiMessages.getNameOfDefaultRecipient({ + .call(this.endpoint.getNameOfDefaultRecipient({ id: this.id, type_id: this.typeId})) .then(result => { @@ -322,7 +321,7 @@ export default { //case of reply if(this.messageId != null) { this.$api - .call(ApiMessages.getReplyData(this.messageId)) + .call(this.endpoint.getReplyData(this.messageId)) .then(result => { this.replyData = result.data; this.formData.subject = this.replyData[0].replySubject; diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index a21073855..8d539983f 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -1,8 +1,6 @@ import {CoreFilterCmpt} from "../../filter/Filter.js"; import FormForm from '../../Form/Form.js'; -import ApiMessages from '../../../api/factory/messages/messages.js'; - export default { name: "TableMessages", components: { @@ -16,7 +14,7 @@ export default { }, props: { endpoint: { - type: String, + type: Object, required: true }, typeId: String, @@ -257,7 +255,7 @@ export default { }, deleteMessage(message_id){ return this.$api - .call(ApiMessages.deleteMessage(message_id)) + .call(this.endpoint.deleteMessage(message_id)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); }).catch(this.$fhcAlert.handleSystemError) @@ -318,7 +316,7 @@ export default { }, loadAjaxCall(url, config, params){ return this.$api.call( - ApiMessages.getMessages(params) + this.endpoint.getMessages(params) ); } }, @@ -349,7 +347,7 @@ export default { type_id: this.typeId }; this.$api - .call(ApiMessages.getPersonId(params)) + .call(this.endpoint.getPersonId(params)) .then(result => { this.personId = result.data; }) diff --git a/public/js/components/Messages/Messages.js b/public/js/components/Messages/Messages.js index 337883be3..176c05b6b 100644 --- a/public/js/components/Messages/Messages.js +++ b/public/js/components/Messages/Messages.js @@ -15,7 +15,7 @@ export default { }, props: { endpoint: { - type: String, + type: Object, required: true }, typeId: { diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Messages.js b/public/js/components/Stv/Studentenverwaltung/Details/Messages.js index 49600fe20..59650eaab 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Messages.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Messages.js @@ -1,4 +1,5 @@ import CoreMessages from "../../../Messages/Messages.js"; +import ApiMessages from "../../../../api/factory/messages/messages.js"; export default { name: "TabMessages", @@ -8,13 +9,18 @@ export default { props: { modelValue: Object }, + data(){ + return { + endpoint: ApiMessages + }; + }, template: `