import VueDatePicker from '../vueDatepicker.js.php'; import FormUploadDms from '../Form/Upload/Dms.js'; import {CoreFilterCmpt} from "../filter/Filter.js"; import BsModal from "../Bootstrap/Modal.js"; import FormForm from '../Form/Form.js'; import FormInput from '../Form/Input.js'; export default { components: { CoreFilterCmpt, VueDatePicker, FormUploadDms, FormForm, FormInput, BsModal }, props: { endpoint: { type: Object, required: true }, typeId: String, id: { type: [Number, String], required: true }, notizLayout: { type: String, default: 'popupModal', validator(value) { return [ 'classicFas', 'twoColumnsFormRight', 'twoColumnsFormLeft', 'popupModal' ].includes(value) } }, showErweitert: Boolean, showDocument: Boolean, showTinyMce: Boolean, visibleColumns: Array, tabulatorPersistenceId: { type: String, default: 'core-notiz' } }, data() { return { notizen: [], multiupload: true, mitarbeiter: [], filteredMitarbeiter: [], zwischenvar: '', editorInitialized: false, editor: null, notizData: { typeId: this.typeId, id: this.id, titel: null, statusNew: true, text: '', lastUpdate: null, von: null, bis: null, document: null, erledigt: false, verfasser: null, bearbeiter: null, anhang: [] }, showVariables: { showTitel: false, showText: false, showVerfasser: false, showBearbeiter: false, showVon: false, showBis: false, showDokumente: false, showErledigt: false, showNotiz_id: false, showNotizzuordnung_id: false, showType_id: false, showId: false, showLastupdate: false }, currentVerfasserUid: null } }, computed: { tabulatorOptions: function() { return { ajaxURL: 'dummy', ajaxRequestFunc: () => this.$api.call(this.endpoint.getNotizen(this.id, this.typeId)), ajaxParams: () => { return { id: this.id, type: this.typeId }; }, ajaxResponse: (url, params, response) => response.data, columns: [ { title: "Titel", field: "titel", width: 100, visible: this.showVariables.showTitel, tooltip:function(e, cell, onRendered){ var el = document.createElement("div"); el.style.backgroundColor = "white"; el.style.color = "black"; el.style.fontWeight = "bold"; el.style.padding = "5px"; el.style.border = "1px solid black"; el.style.borderRadius = "5px"; el.innerText = cell.getValue(); el.innerText = cell.getColumn().getField() + " - " + cell.getValue(); return el; }, }, { title: "Text", field: "text_stripped", width: 250, formatter: "html", //clipContents: true, visible: this.showVariables.showText, tooltip:function(e, cell, onRendered){ var el = document.createElement("div"); el.style.backgroundColor = "white"; el.style.color = "black"; el.style.fontWeight = "bold"; el.style.padding = "5px"; el.style.border = "1px solid black"; el.style.borderRadius = "5px"; el.innerText = cell.getValue(); return el; }, }, {title: "VerfasserIn", field: "verfasser", width: 124, visible: this.showVariables.showVerfasser}, {title: "BearbeiterIn", field: "bearbeiter", width: 126, visible: this.showVariables.showBearbeiter}, {title: "Verfasser UID", field: "verfasser_uid", width: 124, visible: false}, {title: "Bearbeiter UID", field: "bearbeiter_uid", width: 126, visible: false}, {title: "Start", field: "start_format", width: 86, visible: this.showVariables.showVon}, {title: "Ende", field: "ende_format", width: 86, visible: this.showVariables.showBis}, {title: "Dokumente", field: "countdoc", width: 100, visible: this.showVariables.showDokumente}, { title: "Erledigt", field: "erledigt", width: 97, visible: this.showVariables.showErledigt, formatter:"tickCross", hozAlign:"center", formatterParams: { tickElement: '', crossElement: '' } }, {title: "Notiz_id", field: "notiz_id", width: 92, visible: this.showVariables.showNotiz_id}, {title: "Notizzuordnung_id", field: "notizzuordnung_id", width: 164, visible: this.showVariables.showNotizzuordnung_id}, {title: "type_id", field: "type_id", width: 164, visible: this.showVariables.showType_id}, {title: "extension_id", field: "id", width: 135, visible: this.showVariables.showId}, { title: "letzte Änderung", field: "lastupdate", width: 146, visible: this.showVariables.showLastupdate, formatter: function (cell) { const dateStr = cell.getValue(); if (!dateStr) return ""; const date = new Date(dateStr); return date.toLocaleString("de-DE", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false }); } }, { title: 'Aktionen', field: 'actions', width: 100, formatter: (cell, formatterParams, onRendered) => { 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.title = this.$p.t('notiz', 'notiz_edit'); button.innerHTML = ''; button.addEventListener( 'click', (event) => this.actionEditNotiz(cell.getData().notiz_id) ); container.append(button); button = document.createElement('button'); button.className = 'btn btn-outline-secondary btn-action'; button.title = this.$p.t('notiz', 'notiz_delete'); button.innerHTML = ''; button.addEventListener( 'click', () => this.actionDeleteNotiz(cell.getData().notiz_id) ); container.append(button); return container; }, frozen: true }], layout: 'fitDataStretchFrozen', layoutColumnsOnNewData: false, //responsiveLayout: "collapse", maxHeight: '200px', index: 'notiz_id', persistenceID: this.tabulatorPersistenceId, persistence: { sort: true, columns: ["width", "visible", "frozen"], filter: false, headerFilter: false, group: false, page: false, } }; }, tabulatorEvents: function () { return [ { event: 'tableBuilt', handler: async () => { //to avoid js error if (!this.$refs.table) return; await this.$p.loadCategory(['notiz', 'global', 'ui']); const setHeader = (field, text) => { const col = this.$refs.table.tabulator.getColumn(field); if (!col) return; const el = col.getElement(); if (!el || !el.querySelector) return; const titleEl = el.querySelector('.tabulator-col-title'); if (titleEl) { titleEl.textContent = text; } }; setHeader('verfasser', this.$p.t('notiz', 'verfasser')); setHeader('verfasser_uid', this.$p.t('ui', 'verfasser_uid')); setHeader('titel', this.$p.t('global', 'titel')); setHeader('bearbeiter', this.$p.t('notiz', 'bearbeiter')); setHeader('bearbeiter_uid', this.$p.t('ui', 'bearbeiter_uid')); setHeader('start_format', this.$p.t('global', 'gueltigVon')); setHeader('ende_format', this.$p.t('global', 'gueltigBis')); setHeader('countdoc', this.$p.t('notiz', 'document')); setHeader('erledigt', this.$p.t('notiz', 'erledigt')); setHeader('lastupdate', this.$p.t('notiz', 'letzte_aenderung')); setHeader('notiz_id', this.$p.t('ui', 'notiz_id')); setHeader('notizzuordnung_id', this.$p.t('ui', 'notizzuordnung_id')); setHeader('type_id', this.$p.t('ui', 'type_id')); setHeader('id', this.$p.t('ui', 'extension_id')); setHeader('text_stripped', this.$p.t('global', 'text')); // Force layout recalculation for handling overflow text this.$refs.table.tabulator.redraw(true); } } ]; } }, methods: { actionDeleteNotiz(notiz_id) { this.loadNotiz(notiz_id); this.$fhcAlert .confirmDelete() .then(result => result ? notiz_id : Promise.reject({handled: true})) .then(this.deleteNotiz) .catch(this.$fhcAlert.handleSystemError); }, actionEditNotiz(notiz_id) { this.loadNotiz(notiz_id).then(() => { if (this.notizen.notiz_id) { this.notizData.typeId = this.typeId; this.notizData.titel = this.notizen.titel; this.notizData.statusNew = false; this.notizData.text = this.notizen.text; this.notizData.intText = this.notizen.text || ''; this.notizData.lastupdate = this.notizen.lastupdate; this.notizData.von = this.notizen.start; this.notizData.bis = this.notizen.ende; this.notizData.document = this.notizen.dms_id; this.notizData.erledigt = this.notizen.erledigt; this.notizData.intBearbeiter = this.notizen.bearbeiter_uid; this.notizData.bearbeiter = this.notizen.bearbeiter_uid; } }) .then(() => { if(this.notizLayout == 'popupModal') { this.$refs.NotizModal.show(); } if (this.notizData.dms_id) { this.loadDocEntries(this.notizData.notiz_id); } else this.notizData.anhang = []; }); }, actionNewNotiz() { this.resetFormData(); if(this.notizLayout == 'popupModal') { this.$refs.NotizModal.show(); } }, addNewNotiz() { const formData = new FormData(); this.notizData.id = this.id; formData.append('data', JSON.stringify(this.notizData)); Object.entries(this.notizData.anhang).forEach(([k, v]) => formData.append(k, v)); this.$refs.formNotiz.clearValidation(); return this.$refs.formNotiz .call(this.endpoint.addNewNotiz(this.id, formData)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.resetFormData(); if(this.notizLayout == 'popupModal') { this.$refs.NotizModal.hide(); } this.reload(); this.$emit('reload'); }) .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); }); }, deleteNotiz(notiz_id) { return this.$api .call(this.endpoint.deleteNotiz(notiz_id, this.typeId, this.id)) .then(result => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); this.reload(); this.$emit('reload'); this.resetFormData(); }) .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); }); }, loadNotiz(notiz_id) { return this.$api .call(this.endpoint.loadNotiz(notiz_id)) .then(result => { this.notizData = result.data; this.notizData.typeId = this.typeId; this.notizData.anhang = []; this.currentVerfasserUid = result.data.verfasser_uid; return result; }) .catch(this.$fhcAlert.handleSystemError); }, loadDocEntries(notiz_id) { return this.$api .call(this.endpoint.loadDokumente(notiz_id)) .then( result => { this.notizData.anhang = result.data; return result; }) .catch(this.$fhcAlert.handleSystemError); }, updateNotiz(notiz_id) { const formData = new FormData(); formData.append('data', JSON.stringify(this.notizData)); Object.entries(this.notizData.anhang).forEach(([k, v]) => formData.append(k, v)); this.$refs.formNotiz.clearValidation(); return this.$refs.formNotiz .call(this.endpoint.updateNotiz(notiz_id, formData)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.resetFormData(); if(this.notizLayout == 'popupModal') { this.$refs.NotizModal.hide(); } this.reload(); this.$emit('reload'); }) .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); }); }, reload() { this.$refs.table.reloadTable(); }, resetFormData() { //TODO(Manu) check ref, needed here? //this.$refs.formNotiz.reset(); //this.$refs.formc.reset(); this.notizData = { typeId: this.typeId, titel: null, statusNew: true, text: '', lastUpdate: null, von: null, bis: null, document: null, erledigt: false, bearbeiter: null, anhang: [], }; this.currentVerfasserUid = this.uid }, getUid() { return this.$api .call(this.endpoint.getUid()) .then(result => { this.currentVerfasserUid = result.data; this.uid = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, search(event) { return this.$api .call(this.endpoint.getMitarbeiter(event.query)) .then(result => { this.filteredMitarbeiter = result.data.retval; }); }, 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: " blocks | bold italic underline | alignleft aligncenter alignright alignjustify", 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.notizData.text = newContent; }); }, }); }, updateText(value) { this.notizData.text = value; }, initializeShowVariables() { this.visibleColumns.forEach(column => { const columnToShow = "show" + column.charAt(0).toUpperCase() + column.slice(1); this.showVariables[columnToShow] = true; }); } }, created() { this.initializeShowVariables(); this.getUid(); }, async mounted() { if (this.showTinyMce) { await this.initTinyMCE(); } }, watch: { //watcher für Tinymce-Textfeld 'notizData.text': { handler(newVal) { if (this.showTinyMce) { const tinymcsVal = this.editor.getContent(); if (tinymcsVal != newVal) { //Inhalt des Editors aktualisieren this.editor.setContent(newVal); } } } }, //Watcher für autocomplete Bearbeiter und Verfasser 'notizData.intBearbeiter': { handler(newVal) { if (typeof newVal === 'object') { this.notizData.bearbeiter = newVal.mitarbeiter_uid; } }, deep: true }, id() { this.reload(); } }, beforeUnmount() { if (this.editor && tinymce.get(this.editor.id)) { tinymce.get(this.editor.id).remove(); this.editor = null; } }, template: `
{{$p.t('notiz','notiz_new')}} {{$p.t('notiz','notiz_edit')}} [{{notizData.typeId}}]
{{notizData.lastupdate}}
{{$p.t('notiz','notiz_new')}} [{{notizData.typeId}}]
{{$p.t('notiz','notiz_edit')}} [{{notizData.typeId}}]
{{notizData.lastupdate}}
{{$p.t('notiz','notiz_new')}} [{{notizData.typeId}}]
{{$p.t('notiz','notiz_edit')}} [{{notizData.typeId}}]
{{notizData.lastupdate}}
{{$p.t('notiz','notiz_new')}} [{{notizData.typeId}}]
{{$p.t('notiz','notiz_edit')}} [{{notizData.typeId}}]
{{notizData.lastupdate}}
Falsches Layout übergeben: {{notizLayout}}
Kein Layout übergeben