feat: prefill calendar form when setting workorder appointment
When a WorkorderCompany user sets or reschedules an appointment date, the calendar is now opened in a new tab pre-filled with workorder data (subject, type, location, times, description, customer contact, Pusnik as calendar user, Ziga Harc as attendee). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1474,6 +1474,31 @@ $(document).ready(function () {
|
|||||||
{
|
{
|
||||||
$('#customer-info-type').val('1').trigger('change');
|
$('#customer-info-type').val('1').trigger('change');
|
||||||
}
|
}
|
||||||
|
if (localsorageEvent.calendar_user_name) {
|
||||||
|
const calUserName = localsorageEvent.calendar_user_name.toLowerCase();
|
||||||
|
const calUserOption = $('#calendar-users option').filter(function () {
|
||||||
|
return $(this).text().trim().toLowerCase().includes(calUserName);
|
||||||
|
}).first();
|
||||||
|
if (calUserOption.length) {
|
||||||
|
$('#calendar-users').val(calUserOption.val()).trigger('change');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (localsorageEvent.attendee_names && localsorageEvent.attendee_names.length) {
|
||||||
|
const attendeeValues = [];
|
||||||
|
localsorageEvent.attendee_names.forEach(function (attendeeName) {
|
||||||
|
const nameLower = attendeeName.toLowerCase();
|
||||||
|
const opt = $('#calendar-attendees option').filter(function () {
|
||||||
|
return $(this).text().trim().toLowerCase().includes(nameLower);
|
||||||
|
}).first();
|
||||||
|
if (opt.length) {
|
||||||
|
attendeeValues.push(opt.val());
|
||||||
|
} else {
|
||||||
|
$('#calendar-attendees').append(new Option(attendeeName, attendeeName, true, true));
|
||||||
|
attendeeValues.push(attendeeName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#calendar-attendees').val(attendeeValues).trigger('change');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -130,6 +130,48 @@ Vue.component('workorder-company', {
|
|||||||
if (!timestamp) return '–';
|
if (!timestamp) return '–';
|
||||||
return window.moment.unix(timestamp).format(withTime ? 'DD.MM.YYYY HH:mm' : 'DD.MM.YYYY');
|
return window.moment.unix(timestamp).format(withTime ? 'DD.MM.YYYY HH:mm' : 'DD.MM.YYYY');
|
||||||
},
|
},
|
||||||
|
getCalendarType(networkOwnerName) {
|
||||||
|
if (!networkOwnerName) return '1';
|
||||||
|
const name = networkOwnerName.toLowerCase();
|
||||||
|
if (name.includes('xinon')) return '2';
|
||||||
|
if (name.includes('sbidi')) return '7';
|
||||||
|
if (name.includes('estmk')) return '3';
|
||||||
|
return '1';
|
||||||
|
},
|
||||||
|
getCampaignName(preordercampaignId) {
|
||||||
|
const col = this.crudConfig.columns.find(c => c.key === 'preordercampaign_id');
|
||||||
|
const opt = col?.table?.filterOptions?.find(o => o.value == preordercampaignId);
|
||||||
|
return opt?.text || '';
|
||||||
|
},
|
||||||
|
openCalendarWithPrefill(workorder, dateUnix) {
|
||||||
|
const m = window.moment.unix(dateUnix);
|
||||||
|
const zeitraum = m.hour() < 12 ? 'VM' : 'NM';
|
||||||
|
const campaignName = this.getCampaignName(workorder.preordercampaign_id);
|
||||||
|
const locationParts = [workorder.street, workorder.hausnummer];
|
||||||
|
if (workorder.stiege) locationParts.push('/' + workorder.stiege);
|
||||||
|
const location = locationParts.join(' ') + ', ' + workorder.plz + ' ' + workorder.city;
|
||||||
|
const descLines = [];
|
||||||
|
if (workorder.oaid || campaignName || workorder.city) {
|
||||||
|
descLines.push([workorder.oaid, campaignName, workorder.city].filter(Boolean).join(' - '));
|
||||||
|
}
|
||||||
|
descLines.push('Zeitraum: ' + zeitraum);
|
||||||
|
if (workorder.phone) descLines.push('Tel.: ' + workorder.phone);
|
||||||
|
if (workorder.additionalInfo) descLines.push(workorder.additionalInfo);
|
||||||
|
const calendarData = {
|
||||||
|
type: this.getCalendarType(workorder.networkOwnerName),
|
||||||
|
subject: workorder.customerCompany || workorder.customerName || '',
|
||||||
|
location: location,
|
||||||
|
cstart: m.format('DD.MM.YYYY HH:mm'),
|
||||||
|
cend: m.clone().add(90, 'minutes').format('DD.MM.YYYY HH:mm'),
|
||||||
|
description: descLines.join('<br>'),
|
||||||
|
customer_phone: workorder.phone || null,
|
||||||
|
customer_email: workorder.email || null,
|
||||||
|
calendar_user_name: 'Pusnik',
|
||||||
|
attendee_names: ['Ziga Harc'],
|
||||||
|
};
|
||||||
|
localStorage.setItem('Calendar_create', JSON.stringify(calendarData));
|
||||||
|
window.open('/Calendar/View', '_blank');
|
||||||
|
},
|
||||||
async setAppointment(workorder, date) {
|
async setAppointment(workorder, date) {
|
||||||
if (!date) return;
|
if (!date) return;
|
||||||
if (moment.unix(date).hour() >= 23 || moment.unix(date).hour() < 1) {
|
if (moment.unix(date).hour() >= 23 || moment.unix(date).hour() < 1) {
|
||||||
@@ -142,6 +184,7 @@ Vue.component('workorder-company', {
|
|||||||
if (data.success) {
|
if (data.success) {
|
||||||
window.notify('success', data.message);
|
window.notify('success', data.message);
|
||||||
this.$refs.table.$refs.table.refreshTable();
|
this.$refs.table.$refs.table.refreshTable();
|
||||||
|
this.openCalendarWithPrefill(workorder, date);
|
||||||
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
|
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
|
||||||
},
|
},
|
||||||
openRescheduleModal(row) {
|
openRescheduleModal(row) {
|
||||||
@@ -157,6 +200,7 @@ Vue.component('workorder-company', {
|
|||||||
if (data.success) {
|
if (data.success) {
|
||||||
window.notify('success', data.message);
|
window.notify('success', data.message);
|
||||||
this.$refs.table.$refs.table.refreshTable();
|
this.$refs.table.$refs.table.refreshTable();
|
||||||
|
this.openCalendarWithPrefill(workorder, newDate);
|
||||||
this.rescheduleModalData = null;
|
this.rescheduleModalData = null;
|
||||||
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
|
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user