mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
78 lines
3.0 KiB
JavaScript
78 lines
3.0 KiB
JavaScript
// Tickets > Unprocessed Email > Make a Ticket (agent/modals/email_unprocessed/email_unprocessed_ticket.php): the contact
|
|
// picker follows the client picked - the one in data-selected picked when it is theirs - and "make the sender a contact"
|
|
// shows only while the contact is Nobody.
|
|
//
|
|
// Wrapped in an IIFE because a modal can be opened, closed and opened again in one page load, which re-runs this file.
|
|
|
|
(function () {
|
|
|
|
const clientSelect = document.getElementById('unprocessedClientSelect');
|
|
const contactSelect = document.getElementById('unprocessedContactSelect');
|
|
const addBox = document.getElementById('unprocessedAddContact');
|
|
|
|
function syncAdd() {
|
|
if (addBox && contactSelect) {
|
|
addBox.hidden = contactSelect.value !== '' && contactSelect.value !== '0';
|
|
}
|
|
}
|
|
|
|
function loadContacts(clientId) {
|
|
if (!contactSelect) {
|
|
return;
|
|
}
|
|
const wanted = contactSelect.dataset.selected || '0';
|
|
contactSelect.dataset.selected = '0';
|
|
contactSelect.innerHTML = '';
|
|
contactSelect.add(new Option('- Nobody -', '0'));
|
|
contactSelect.value = '0';
|
|
syncAdd();
|
|
if (!clientId || clientId === '0') {
|
|
return;
|
|
}
|
|
itflowGet('ajax.php', {get_client_contacts: 'true', client_id: clientId}, function (data) {
|
|
let contacts = [];
|
|
try {
|
|
contacts = JSON.parse(data).contacts || [];
|
|
} catch (e) {
|
|
contacts = [];
|
|
}
|
|
contacts.forEach(function (contact) {
|
|
const option = new Option(contact.contact_name, contact.contact_id);
|
|
const details = [];
|
|
if (contact.contact_email) {
|
|
details.push(contact.contact_email);
|
|
}
|
|
if (contact.contact_primary == '1') {
|
|
details.push('Primary');
|
|
}
|
|
option.dataset.description = details.join(' · ');
|
|
option.dataset.keywords = contact.contact_email || '';
|
|
if (contact.contact_photo_url) {
|
|
option.dataset.image = contact.contact_photo_url;
|
|
} else {
|
|
option.dataset.initials = contact.contact_initials;
|
|
option.dataset.shape = 'circle';
|
|
option.dataset.tone = contact.contact_tone || 'secondary';
|
|
option.dataset.soft = '1';
|
|
}
|
|
contactSelect.add(option);
|
|
});
|
|
if (contacts.some(function (contact) { return String(contact.contact_id) === wanted; })) {
|
|
contactSelect.value = wanted;
|
|
}
|
|
syncAdd();
|
|
});
|
|
}
|
|
|
|
if (clientSelect) {
|
|
clientSelect.addEventListener('change', function () {
|
|
loadContacts(clientSelect.value);
|
|
});
|
|
loadContacts(clientSelect.value);
|
|
}
|
|
if (contactSelect) {
|
|
contactSelect.addEventListener('change', syncAdd);
|
|
}
|
|
|
|
})();
|