@@ -288,44 +429,184 @@
}
}
- // Lookup employee names by SSO
- var lookupTimeout = null;
+ // Employee autocomplete functionality
+ var searchTimeout = null;
+ var selectedEmployees = []; // Array of {sso, name, picture, isCustom}
+ var EMPLOYEE_PHOTO_BASE = 'https://tsgwp00525.rd.ds.ge.com/EmployeeDBAPP/images/';
+ var GE_LOGO_URL = './shopfloor-dashboard/ge-aerospace-logo.svg';
+
document.addEventListener('DOMContentLoaded', function() {
- var ssoInput = document.getElementById('employeesso');
- ssoInput.addEventListener('input', function() {
- clearTimeout(lookupTimeout);
- lookupTimeout = setTimeout(lookupEmployees, 500);
+ var searchInput = document.getElementById('employeeSearch');
+ var dropdown = document.getElementById('employeeDropdown');
+
+ // Search on input
+ searchInput.addEventListener('input', function() {
+ clearTimeout(searchTimeout);
+ var query = this.value.trim();
+
+ if (query.length < 2) {
+ dropdown.style.display = 'none';
+ return;
+ }
+
+ searchTimeout = setTimeout(function() {
+ searchEmployees(query);
+ }, 300);
+ });
+
+ // Handle Enter key for custom names
+ searchInput.addEventListener('keydown', function(e) {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ var customName = this.value.trim();
+ if (customName.length > 0) {
+ addEmployee(null, customName, null, true);
+ this.value = '';
+ dropdown.style.display = 'none';
+ }
+ }
+ });
+
+ // Close dropdown when clicking outside
+ document.addEventListener('click', function(e) {
+ if (!e.target.closest('.employee-search-container')) {
+ dropdown.style.display = 'none';
+ }
});
});
- function lookupEmployees() {
- var ssoInput = document.getElementById('employeesso');
- var ssos = ssoInput.value.trim();
- var previewDiv = document.getElementById('employeePreview');
- var namesSpan = document.getElementById('employeeNames');
+ function searchEmployees(query) {
+ var dropdown = document.getElementById('employeeDropdown');
- if (!ssos) {
- previewDiv.style.display = 'none';
- return;
- }
-
- // Call AJAX endpoint to lookup names
- fetch('./lookupemployee.asp?sso=' + encodeURIComponent(ssos))
+ fetch('./apiemployeesearch.asp?q=' + encodeURIComponent(query) + '&limit=8')
.then(function(response) { return response.json(); })
.then(function(data) {
- if (data.success && data.names) {
- namesSpan.textContent = data.names;
- previewDiv.style.display = 'block';
+ if (data.success && data.results) {
+ renderDropdown(data.results, query);
} else {
- namesSpan.textContent = data.error || 'Employee not found';
- namesSpan.className = 'badge badge-warning';
- previewDiv.style.display = 'block';
+ renderDropdown([], query);
}
})
.catch(function(err) {
- previewDiv.style.display = 'none';
+ renderDropdown([], query);
});
}
+
+ function renderDropdown(results, query) {
+ var dropdown = document.getElementById('employeeDropdown');
+ var html = '';
+
+ // Show matching employees
+ results.forEach(function(emp) {
+ // Check if already selected
+ var isSelected = selectedEmployees.some(function(s) { return s.sso === emp.sso; });
+ if (isSelected) return;
+
+ var photoHtml;
+ if (emp.picture) {
+ photoHtml = '

';
+ } else {
+ photoHtml = '
';
+ }
+
+ html += '
';
+ html += photoHtml;
+ html += '
';
+ html += '
' + escapeHtml(emp.fullName) + (emp.team ? ' - ' + escapeHtml(emp.team) : '') + '
';
+ html += '
SSO: ' + emp.sso + '
';
+ html += '
';
+ });
+
+ // Always show option to add as custom name
+ if (query.length > 0) {
+ html += '
';
+ html += '
';
+ html += '
';
+ html += '
Add "' + escapeHtml(query) + '" (not in system)
';
+ html += '
';
+ }
+
+ dropdown.innerHTML = html;
+ dropdown.style.display = html ? 'block' : 'none';
+ }
+
+ function selectEmployee(sso, name, picture) {
+ addEmployee(sso, name, picture, false);
+ document.getElementById('employeeSearch').value = '';
+ document.getElementById('employeeDropdown').style.display = 'none';
+ }
+
+ function addCustomEmployee(name) {
+ addEmployee(null, name, null, true);
+ document.getElementById('employeeSearch').value = '';
+ document.getElementById('employeeDropdown').style.display = 'none';
+ }
+
+ function addEmployee(sso, name, picture, isCustom) {
+ // Check for duplicates
+ var isDuplicate = selectedEmployees.some(function(s) {
+ if (sso && s.sso === sso) return true;
+ if (isCustom && s.isCustom && s.name === name) return true;
+ return false;
+ });
+ if (isDuplicate) return;
+
+ selectedEmployees.push({ sso: sso, name: name, picture: picture, isCustom: isCustom });
+ updateSelectedDisplay();
+ updateHiddenFields();
+ }
+
+ function removeEmployee(index) {
+ selectedEmployees.splice(index, 1);
+ updateSelectedDisplay();
+ updateHiddenFields();
+ }
+
+ function updateSelectedDisplay() {
+ var container = document.getElementById('selectedEmployees');
+ var html = '';
+
+ selectedEmployees.forEach(function(emp, index) {
+ var photoHtml;
+ if (emp.picture) {
+ photoHtml = '

';
+ } else {
+ photoHtml = '
';
+ }
+
+ html += '
';
+ html += photoHtml;
+ html += '' + escapeHtml(emp.name);
+ if (emp.isCustom) html += ' (custom)';
+ html += '';
+ html += 'x';
+ html += '
';
+ });
+
+ container.innerHTML = html;
+ }
+
+ function updateHiddenFields() {
+ var values = [];
+
+ selectedEmployees.forEach(function(emp) {
+ if (emp.sso) {
+ // System employee - use SSO
+ values.push(emp.sso);
+ } else if (emp.isCustom) {
+ // Custom name - use NAME: prefix
+ values.push('NAME:' + emp.name);
+ }
+ });
+
+ document.getElementById('employeesso').value = values.join(',');
+ }
+
+ function escapeHtml(text) {
+ var div = document.createElement('div');
+ div.textContent = text;
+ return div.innerHTML;
+ }