fix: fix popup blocker and Select2 error when prefilling calendar

- Open window synchronously before await to avoid popup blocker,
  then navigate it to /Calendar/View after successful save; close
  it if the save fails
- Guard the #customer Select2 change handler so it bails early
  when #customer has not been initialized as Select2 yet

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 13:46:19 +01:00
parent daf1ce3401
commit a53ff3912c
2 changed files with 16 additions and 6 deletions

View File

@@ -2378,6 +2378,8 @@ $(document).ready(function () {
$('body').on('change', '#customer,#customer-info-type', function () {
if (!$('#customer').hasClass('select2-hidden-accessible')) return;
if ($('#name').val() == "") {
$('#name').val('IBN: ' + $("#customer").select2('data')[0].name);
}

View File

@@ -143,7 +143,7 @@ Vue.component('workorder-company', {
const opt = col?.table?.filterOptions?.find(o => o.value == preordercampaignId);
return opt?.text || '';
},
openCalendarWithPrefill(workorder, dateUnix) {
openCalendarWithPrefill(workorder, dateUnix, win) {
const m = window.moment.unix(dateUnix);
const zeitraum = m.hour() < 12 ? 'VM' : 'NM';
const campaignName = this.getCampaignName(workorder.preordercampaign_id);
@@ -170,7 +170,7 @@ Vue.component('workorder-company', {
attendee_names: ['Ziga Harc'],
};
localStorage.setItem('Calendar_create', JSON.stringify(calendarData));
window.open('/Calendar/View', '_blank');
win.location.href = '/Calendar/View';
},
async setAppointment(workorder, date) {
if (!date) return;
@@ -178,14 +178,18 @@ Vue.component('workorder-company', {
this.$refs.table.$refs.table.refreshTable();
return window.notify('error', 'Bitte Uhrzeit angeben!');
}
const calWin = window.open('about:blank', '_blank');
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderCompany/scheduleAppointment`, {
workorderId: workorder.id, appointmentDate: date
});
if (data.success) {
window.notify('success', data.message);
this.$refs.table.$refs.table.refreshTable();
this.openCalendarWithPrefill(workorder, date);
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
this.openCalendarWithPrefill(workorder, date, calWin);
} else {
if (calWin) calWin.close();
window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
}
},
openRescheduleModal(row) {
this.rescheduleModalData = { workorder: row, newDate: row.appointmentDate, reason: '' };
@@ -194,15 +198,19 @@ Vue.component('workorder-company', {
const { workorder, newDate, reason } = this.rescheduleModalData;
if (!newDate || !reason) return window.notify('error', 'Bitte geben Sie ein neues Datum und einen Grund an.');
if (moment.unix(newDate).hour() >= 23 || moment.unix(newDate).hour() < 1) return window.notify('error', 'Bitte Uhrzeit angeben!');
const calWin = window.open('about:blank', '_blank');
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderCompany/rescheduleAppointment`, {
workorderId: workorder.id, appointmentDate: newDate, reason: reason
});
if (data.success) {
window.notify('success', data.message);
this.$refs.table.$refs.table.refreshTable();
this.openCalendarWithPrefill(workorder, newDate);
this.openCalendarWithPrefill(workorder, newDate, calWin);
this.rescheduleModalData = null;
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
} else {
if (calWin) calWin.close();
window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
}
},
async clearAppointment(workorder) {
if (!confirm('Möchten Sie den Termin wirklich löschen?')) return;