Files
itflow/agent/js/ticket_change_client.js
johnnyq 234afd25fb Contacts overhaul: rebuilt contacts list with role tabs and counts, avatars, flag pills, hover copy on phone/mobile/email, inline location picker, linked asset/credential/license/ticket chips and tag filter; contact page rebuilt to match the asset page with header actions, Reach/Details/Quick notes cards and tabbed Assets, Credentials, Tickets, Recurring, Licenses, Documents, Files, Services and Notes; add and edit contact share one tabbed form (Details, Roles, Access, Notes) with field icons, role switches, password generator, duplicate email check and photo removal; contact quick look redone to match the asset quick look; contact avatars now used everywhere a contact appears - contact pickers, ticket header, contact card, client replies, ticket list, kanban, assets, clients list, client header, overview key contacts, credentials, documents, services, invoice/quote/statement recipients, license users and global search - with each contact keeping the same colour throughout; ticket contact pickers show the name with title and role underneath; fixes: permission checks on the add contact modal and contact page/list actions, contact location limited to the contact's own client on add/edit/bulk assign, contacts list no longer selects user account columns, archived assets and credentials left off the contact page and quick look, saving a contact with the client portal disabled no longer clears their portal login method, replacing a photo no longer tries to delete a directory, sort column whitelisted, list counts and tags batched instead of per row, recurring ticket menu markup, undefined index notices, contacts list no longer scrolls sideways on phones, Edit Service shows avatars on unselected contacts and assets, license user labels toggle their checkbox; new functions/contact.php helpers (contactAvatar, contactLink, contactFlagPills, contactPhoneLink, contactAvatarData, contactOptionDescription), shared contact_form.php, contact_location quick pick, removed unused assetContactAvatar and clientOverviewPersonInitials
2026-10-14 18:33:18 -04:00

75 lines
3.0 KiB
JavaScript

itflowReady(function () {
// Function to load contacts for a given client
function loadContacts(clientId) {
if (!clientId) {
return;
}
const contactSelect = document.getElementById('contact_select');
if (!contactSelect) {
return;
}
contactSelect.innerHTML = '<option value="">Loading...</option>';
const query = new URLSearchParams({
get_client_contacts: 1,
client_id: clientId
});
fetch('ajax.php?' + query.toString(), {
method: 'GET',
headers: { 'Accept': 'application/json' },
credentials: 'same-origin'
})
.then(function (res) {
if (!res.ok) {
throw new Error('HTTP ' + res.status);
}
return res.json();
})
.then(function (response) {
contactSelect.innerHTML = '';
if (response.contacts && response.contacts.length > 0) {
contactSelect.appendChild(new Option('Select a contact', ''));
response.contacts.forEach(function (contact) {
// new Option() sets text content, so contact names are
// never parsed as markup. The picker draws their avatar
// from the data-* extras, as on every other contact field.
const option = new Option(contact.contact_name, contact.contact_id);
// Title, then Primary or Technical - contactOptionDescription() server side
const role = contact.contact_primary == '1' ? 'Primary' : (contact.contact_technical == '1' ? 'Technical' : '');
option.dataset.description = [contact.contact_title, role].filter(Boolean).join(' · ');
option.dataset.initials = contact.contact_initials || '';
option.dataset.shape = 'circle';
option.dataset.tone = contact.contact_tone || 'secondary';
option.dataset.soft = '1';
if (contact.contact_photo_url) {
option.dataset.image = contact.contact_photo_url;
}
contactSelect.appendChild(option);
});
} else {
contactSelect.appendChild(new Option('No contacts found', ''));
}
})
.catch(function (error) {
console.error('AJAX Error:', error);
contactSelect.innerHTML = '<option value="">Failed to load contacts</option>';
});
}
const clientSelect = document.getElementById('client_select');
if (!clientSelect) {
return;
}
// Load contacts for the currently selected client when modal opens
loadContacts(clientSelect.value);
// Load contacts when client changes
clientSelect.addEventListener('change', function () {
loadContacts(this.value);
});
});