category, status, and priority are editable on tickets.
This commit is contained in:
@@ -233,6 +233,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
// Initialize assignment handling
|
||||
handleAssignmentChange();
|
||||
|
||||
// Initialize metadata field handlers (priority, category, type)
|
||||
handleMetadataChanges();
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -267,6 +270,81 @@ function handleAssignmentChange() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle metadata field changes (priority, category, type)
|
||||
*/
|
||||
function handleMetadataChanges() {
|
||||
const prioritySelect = document.getElementById('prioritySelect');
|
||||
const categorySelect = document.getElementById('categorySelect');
|
||||
const typeSelect = document.getElementById('typeSelect');
|
||||
|
||||
// Helper function to update ticket field
|
||||
function updateTicketField(fieldName, newValue) {
|
||||
const ticketId = window.ticketData.id;
|
||||
|
||||
fetch('/api/update_ticket.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
ticket_id: ticketId,
|
||||
[fieldName]: fieldName === 'priority' ? parseInt(newValue) : newValue
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert(`Error updating ${fieldName}`);
|
||||
console.error(data.error);
|
||||
} else {
|
||||
console.log(`${fieldName} updated successfully to:`, newValue);
|
||||
|
||||
// Update window.ticketData
|
||||
window.ticketData[fieldName] = fieldName === 'priority' ? parseInt(newValue) : newValue;
|
||||
|
||||
// For priority, also update the priority indicator if it exists
|
||||
if (fieldName === 'priority') {
|
||||
const priorityIndicator = document.querySelector('.priority-indicator');
|
||||
if (priorityIndicator) {
|
||||
priorityIndicator.className = `priority-indicator priority-${newValue}`;
|
||||
priorityIndicator.textContent = 'P' + newValue;
|
||||
}
|
||||
|
||||
// Update ticket container priority attribute
|
||||
const ticketContainer = document.querySelector('.ticket-container');
|
||||
if (ticketContainer) {
|
||||
ticketContainer.setAttribute('data-priority', newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(`Error updating ${fieldName}:`, error);
|
||||
alert(`Error updating ${fieldName}: ` + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
// Priority change handler
|
||||
if (prioritySelect) {
|
||||
prioritySelect.addEventListener('change', function() {
|
||||
updateTicketField('priority', this.value);
|
||||
});
|
||||
}
|
||||
|
||||
// Category change handler
|
||||
if (categorySelect) {
|
||||
categorySelect.addEventListener('change', function() {
|
||||
updateTicketField('category', this.value);
|
||||
});
|
||||
}
|
||||
|
||||
// Type change handler
|
||||
if (typeSelect) {
|
||||
typeSelect.addEventListener('change', function() {
|
||||
updateTicketField('type', this.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateTicketStatus() {
|
||||
const statusSelect = document.getElementById('statusSelect');
|
||||
const selectedOption = statusSelect.options[statusSelect.selectedIndex];
|
||||
|
||||
Reference in New Issue
Block a user