diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js index 78df8ad2d..8cef52f3c 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js @@ -1,13 +1,11 @@ import BsModal from "../../../../Bootstrap/Modal.js"; -import CoreForm from '../../../../Form/Form.js'; -import FormValidation from '../../../../Form/Validation.js'; +import BsConfirm from "../../../../Bootstrap/Confirm.js"; +import BsPrompt from "../../../../Bootstrap/Prompt.js"; import FormInput from '../../../../Form/Input.js'; export default { components: { BsModal, - CoreForm, - FormValidation, FormInput }, inject: { @@ -46,7 +44,6 @@ export default { //TODO(Manu) get from config statiInteressent: ["Bewerber", "Aufgenommener", "Student" , "Wartender", "Abgewiesener"], statiStudent: ["Abbrecher", "Unterbrecher", "Student" , "Diplomand", "Absolvent"], - selectedStatus: 'default', actionButton: {}, actionStatusText: {}, actionSem: null @@ -73,7 +70,7 @@ export default { const defaultObject = { status_kurzbz: status, statusgrund_id: null, - link: `changeStatusTo${status}`, + link: this['changeStatusTo' + status], children: [] }; @@ -88,11 +85,11 @@ export default { status_kurzbz: item.status_kurzbz, statusgrund_id: item.statusgrund_id, beschreibung: item.beschreibung, - link: `changeStatusTo${item.status_kurzbz}(${item.statusgrund_id})`, + link: () => this['changeStatusTo' + item.status_kurzbz](item.statusgrund_id), }; if (item.status_kurzbz === "Student") { - itemObject.link = `changeInteressentTo${item.status_kurzbz}(${item.statusgrund_id})`; + itemObject.link = () => this['changeInteressentTo' + item.status_kurzbz](item.statusgrund_id); } defaultObject.children.push(itemObject); }); @@ -104,7 +101,7 @@ export default { status_kurzbz: 'Student', statusgrund_id: null, beschreibung: 'Student', - link: 'changeInteressentToStudent' + link: this.changeInteressentToStudent }); } } @@ -117,8 +114,7 @@ export default { const defaultObject = { status_kurzbz: status, statusgrund_id: null, - link: `changeStatusTo${status}`, - dropEntry: null, + link: this['changeStatusTo' + status], children: [] }; result.push(defaultObject); @@ -128,8 +124,7 @@ export default { status_kurzbz: item.status_kurzbz, statusgrund_id: item.statusgrund_id, beschreibung: item.beschreibung, - link: `changeStatusTo${item.status_kurzbz}(${item.statusgrund_id})`, - dropEntry: `[${item.beschreibung}]`, + link: () => this['changeStatusTo' + item.status_kurzbz](item.statusgrund_id) }; defaultObject.children.push(itemObject); }); @@ -142,7 +137,7 @@ export default { status_kurzbz: 'Student', statusgrund_id: null, beschreibung: 'Student', - link: 'changeStatusToStudent' + link: this.changeStatusToStudent }); } }); @@ -153,25 +148,12 @@ export default { } }, methods: { - executeLink(link) { - bootstrap.Dropdown.getInstance(this.$refs.toolbarButton).hide(); - // Split the link string to extract the function name and arguments - const match = link.match(/(\w+)\(([^)]*)\)/); - const functionName = match ? match[1] : link; - const args = match ? match[2].split(',').map(arg => arg.trim()) : []; - - if (typeof this[functionName] === 'function') { - this[functionName](...args); - } else { - console.error(`Method ${functionName} not found`); - } - }, - actionConfirmDialogue(data, statusgrund, statusText){ + actionConfirmDialogue(data, statusgrund, statusText) { this.actionButton = statusgrund; this.actionStatusText = statusText; this.$refs.confirmStatusAction.show(); }, - addStudent(prestudentIds){ + addStudent() { this.resetChangeModals(); let changeData = {}; @@ -179,11 +161,9 @@ export default { let countSuccess = 0; let countError = 0; - const promises = prestudentIds.map(prestudentId => { + const promises = this.newArray.map(changeData => { - changeData = this.newArray.find(item => item.prestudent_id === prestudentId); - - return this.$fhcApi.post('api/frontend/v1/stv/status/addStudent/' + prestudentId, + return this.$fhcApi.post('api/frontend/v1/stv/status/addStudent/' + changeData.prestudent_id, changeData ).then(response => { countSuccess++; @@ -203,40 +183,34 @@ export default { this.newStatus = 'Student'; //Feedback Success als infoalert - if (countSuccess > 0) { - this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { - 'countSuccess': countSuccess, - 'status': this.newStatus, - 'countError': countError - })); - } + this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { + 'countSuccess': countSuccess, + 'status': this.newStatus, + 'countError': countError + })); - if(this.prestudentIds.length == 1){ + if (this.prestudentIds.length == 1) { this.reload(); - this.$reloadList(); - } - else { - this.$reloadList(); } + this.$reloadList(); this.resetModal(); }); }, - changeStatusToAbbrecher(statusgrund_id){ - this.resetChangeModals(); - let def_date = this.getDefaultDate(); - let abbruchData = - { - status_kurzbz: 'Abbrecher', - datum: def_date, - bestaetigtam: def_date, - statusgrund_id: statusgrund_id - }; - this.newArray = this.updateData.map(objekt => ({ ...objekt, ...abbruchData })); - - this.actionConfirmDialogue(this.updateData, 'studenten','Abbrecher'); - //this.changeStatus(prestudentIds); + changeStatusToAbbrecher(statusgrund_id) { + const data = this.prestudentIds.map(prestudent_id => ({ + prestudent_id, + status_kurzbz: 'Abbrecher', + statusgrund_id + })); + BsConfirm + .popup(this.$p.t('lehre', data.length > 1 ? 'modal_StatusactionPlural' : 'modal_StatusactionSingle', { + count: data.length, + status: 'Abbrecher' + })) + .then(() => this.changeStatusNeu('Abbrecher', data)) + .catch(this.$fhcAlert.handleSystemError); }, - changeStatusToUnterbrecher(){ + changeStatusToUnterbrecher() { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -247,45 +221,26 @@ export default { }; this.newArray = this.updateData.map(objekt => ({ ...objekt, ...deltaData })); - this.actionConfirmDialogue(this.updateData, 'studenten','Unterbrecher'); + this.actionConfirmDialogue(this.updateData, 'studenten', 'Unterbrecher'); }, - changeStatusToStudent(statusgrund_id){ - let def_date = this.getDefaultDate(); - //TODO Manu validation if Bewerber already before asking for ausbildungssemester - //this.checkIfBewerber(); - - this.actionButton = 'student'; - - if(statusgrund_id == 19){ - this.actionStatusText = 'Pre-Abbrecher'; - } - if(statusgrund_id == 15){ - this.actionStatusText = 'Pre-Wiederholer'; - } - if(statusgrund_id == 16){ - this.actionStatusText = 'Wiederholer'; - } - if(!statusgrund_id){ - this.actionStatusText = 'Student'; - } - let deltaData = - { - status_kurzbz: 'Student', - datum: def_date, - bestaetigtam: def_date, - statusgrund_id: statusgrund_id - }; - this.newArray = this.updateData.map(objekt => ({ ...objekt, ...deltaData})); - - if(statusgrund_id == 16 || !statusgrund_id){ - this.$refs.askForAusbildungssemester.show(); - } - else - { - this.actionConfirmDialogue(this.updateData, this.actionButton, this.actionStatusText); - } + changeStatusToStudent(statusgrund_id) { + const data = this.prestudentIds.map(prestudent_id => ({ + prestudent_id, + status_kurzbz: 'Student', + statusgrund_id + })); + BsPrompt + .popup(this.$p.t('lehre', data.length > 1 ? 'modal_askAusbildungssemPlural' : 'modal_askAusbildungssem', { + count: data.length, + status: 'Student' + })) + .then(ausbildungssemester => this.changeStatusNeu('Student', data.map(item => { + item.ausbildungssemester = ausbildungssemester; + return item; + }))) + .catch(this.$fhcAlert.handleSystemError); }, - changeStatusToDiplomand(){ + changeStatusToDiplomand() { let def_date = this.getDefaultDate(); let deltaData = { @@ -297,7 +252,7 @@ export default { this.newArray = this.updateData.map(objekt => ({ ...objekt, ...deltaData})); this.changeStatus(this.prestudentIds); }, - changeStatusToAbsolvent(){ + changeStatusToAbsolvent() { let def_date = this.getDefaultDate(); let deltaData = { @@ -309,7 +264,7 @@ export default { this.newArray = this.updateData.map(objekt => ({ ...objekt, ...deltaData})); this.changeStatus(this.prestudentIds); }, - changeStatusToBewerber(){ + changeStatusToBewerber() { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -325,7 +280,7 @@ export default { ...deltaData})); this.changeStatus(this.prestudentIds); }, - changeStatusToAufgenommener(){ + changeStatusToAufgenommener() { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -340,10 +295,9 @@ export default { ...deltaData, })); - this.actionConfirmDialogue(this.updateData, 'aufgenommener','Aufgenommener'); - + this.actionConfirmDialogue(this.updateData, 'aufgenommener', 'Aufgenommener'); }, - changeInteressentToStudent(statusgrund_id){ + changeInteressentToStudent(statusgrund_id) { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -360,9 +314,8 @@ export default { })); this.addStudent(this.prestudentIds); - }, - changeStatusToAbgewiesener(statusgrund_id){ + changeStatusToAbgewiesener(statusgrund_id) { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -378,9 +331,9 @@ export default { ...deltaData, })); - this.actionConfirmDialogue(this.updateData, 'abgewiesener','Abgewiesener'); + this.actionConfirmDialogue(this.updateData, 'abgewiesener', 'Abgewiesener'); }, - changeStatusToWartender(){ + changeStatusToWartender() { this.resetChangeModals(); let def_date = this.getDefaultDate(); let deltaData = @@ -394,9 +347,29 @@ export default { ...deltaData, })); - this.actionConfirmDialogue(this.updateData, 'wartender','Wartender'); + this.actionConfirmDialogue(this.updateData, 'wartender', 'Wartender'); }, - changeStatus(prestudentIds){ + changeStatusNeu(status_kurzbz, data) { + Promise + .allSettled(data.map(item => this.$fhcApi.post('api/frontend/v1/stv/status/changeStatus/' + item.prestudent_id, item))) + .then(results => { + let successes = results.filter(result => result.status == "fulfilled").length, + errors = results.length - successes; + + //Feedback Success als infoalert + this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { + 'countSuccess': successes, + 'status': status_kurzbz, + 'countError': errors + })); + + if(results.length == 1 && successes > 0){ + this.reload(); + } + this.$reloadList(); + }); + }, + changeStatus() { this.resetChangeModals(); let changeData = {}; @@ -406,7 +379,7 @@ export default { // Check if ausbildungssemester is already in this.newArray const existingEntry = this.newArray.find( - (entry) => entry.ausbildungssemester === this.actionSem + (entry) => entry.ausbildungssemester ); // If the entry doesn't exist, add a new object with ausbildungssemester @@ -414,11 +387,9 @@ export default { this.newArray.push({ ausbildungssemester: this.actionSem }); } - const promises = prestudentIds.map(prestudentId => { + const promises = this.newArray.map(changeData => { - changeData = this.newArray.find(item => item.prestudent_id === prestudentId); - - return this.$fhcApi.post('api/frontend/v1/stv/status/changeStatus/' + prestudentId, + return this.$fhcApi.post('api/frontend/v1/stv/status/changeStatus/' + changeData.prestudent_id, changeData ).then(response => { countSuccess++; @@ -435,56 +406,34 @@ export default { Promise .allSettled(promises) .then(values => { - /* if (this.abbruchData.length < 1) { - } - else{*/ if(this.newArray.length > 0) { this.newStatus = this.newArray[0].status_kurzbz; } else { this.newStatus = this.statusData.status_kurzbz; } - // } //Feedback Success als infoalert - if (countSuccess > 0 || countError > 0 ) { - this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { - 'countSuccess': countSuccess, - 'status': this.newStatus, - 'countError': countError - })); - } + this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { + 'countSuccess': countSuccess, + 'status': this.newStatus, + 'countError': countError + })); if(this.prestudentIds.length == 1 && countSuccess > 0){ this.reload(); - //necessary to see new status in List - this.$reloadList(); - //to change ToolbarInteressent to ToolbarStudent - - - } - else { - this.$reloadList(); } + this.$reloadList(); + //to change ToolbarInteressent to ToolbarStudent this.resetModal(); }); }, - checkIfErsterStudent(prestudent_id){ - return this.$fhcApi - .get('api/frontend/v1/stv/status/isErsterStudent/' + prestudent_id) - .then( - result => { - this.isErsterStudent = result.data.retval == 0 ? 1 : 0; - return result; - }) - .catch(this.$fhcAlert.handleSystemError); - }, getDefaultDate() { const today = new Date(); return today; }, - hideModal(modalRef){ + hideModal(modalRef) { this.$refs[modalRef].hide(); this.statusNew = true; }, @@ -494,7 +443,7 @@ export default { reloadList() { this.$emit('reload-list'); }, - resetChangeModals(){ + resetChangeModals() { this.hideModal('confirmStatusAction'); this.hideModal('askForAusbildungssemester'); }, @@ -505,12 +454,10 @@ export default { this.actionStatusText = {}; this.actionSem = null; }, - saveNewAusbildungssemester(){ + saveNewAusbildungssemester() { this.newArray = this.newArray.map(objekt => ({ ...objekt, ausbildungssemester: this.actionSem})); - console.log("ausbildungssem" + this.actionSem); this.changeStatus(this.prestudentIds); - }, - + } }, created() { this.$fhcApi @@ -612,14 +559,14 @@ export default {