Migrate all raw fetch() calls to lt.api, fix CSS fallback values
- Replace all 23 raw fetch() calls in dashboard.js and ticket.js with lt.api.get/post/delete — removes manual CSRF header injection, manual JSON parsing boilerplate, and response.ok checks throughout - dashboard.js: 10 calls (inline save x2, template GET, 5x bulk ops, quick-status, quick-assign) - ticket.js: 13 calls (main save, add/update/delete comment x3, reply, assign, metadata update, status change, deps GET/POST/DELETE, attachments GET, delete attachment) - Remove stale csrf_token from deleteAttachment body (lt.api sends the X-CSRF-Token header automatically) - Fix CSS variable fallbacks in ticket.css: replace var(--text-primary, #f7fafc) and var(--bg-secondary, #1a202c) with plain var(--text-primary) and var(--bg-secondary) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -522,24 +522,7 @@ function quickSave() {
|
||||
priority: parseInt(prioritySelect.value)
|
||||
};
|
||||
|
||||
fetch('/api/update_ticket.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => {
|
||||
return response.text().then(text => {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (e) {
|
||||
throw new Error('Invalid JSON response: ' + text);
|
||||
}
|
||||
});
|
||||
})
|
||||
lt.api.post('/api/update_ticket.php', data)
|
||||
.then(result => {
|
||||
if (result.success) {
|
||||
// Update the hamburger menu display
|
||||
@@ -589,19 +572,7 @@ function saveTicket() {
|
||||
}
|
||||
});
|
||||
|
||||
fetch('/api/update_ticket.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ticket_id: ticketId,
|
||||
...data
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
lt.api.post('/api/update_ticket.php', { ticket_id: ticketId, ...data })
|
||||
.then(data => {
|
||||
if(data.success) {
|
||||
const statusDisplay = document.getElementById('statusDisplay');
|
||||
@@ -640,15 +611,7 @@ function loadTemplate() {
|
||||
}
|
||||
|
||||
// Fetch template data
|
||||
fetch(`/api/get_template.php?template_id=${templateId}`, {
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch template');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
lt.api.get(`/api/get_template.php?template_id=${templateId}`)
|
||||
.then(data => {
|
||||
if (data.success && data.template) {
|
||||
const template = data.template;
|
||||
@@ -770,19 +733,10 @@ function bulkClose() {
|
||||
|
||||
function performBulkCloseAction(ticketIds) {
|
||||
|
||||
fetch('/api/bulk_operation.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_type: 'bulk_close',
|
||||
ticket_ids: ticketIds
|
||||
})
|
||||
lt.api.post('/api/bulk_operation.php', {
|
||||
operation_type: 'bulk_close',
|
||||
ticket_ids: ticketIds
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (data.failed > 0) {
|
||||
@@ -866,20 +820,11 @@ function performBulkAssign() {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/bulk_operation.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_type: 'bulk_assign',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { assigned_to: parseInt(userId) }
|
||||
})
|
||||
lt.api.post('/api/bulk_operation.php', {
|
||||
operation_type: 'bulk_assign',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { assigned_to: parseInt(userId) }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeBulkAssignModal();
|
||||
@@ -951,20 +896,11 @@ function performBulkPriority() {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/bulk_operation.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_type: 'bulk_priority',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { priority: parseInt(priority) }
|
||||
})
|
||||
lt.api.post('/api/bulk_operation.php', {
|
||||
operation_type: 'bulk_priority',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { priority: parseInt(priority) }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeBulkPriorityModal();
|
||||
@@ -1067,20 +1003,11 @@ function performBulkStatusChange() {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/bulk_operation.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_type: 'bulk_status',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { status: status }
|
||||
})
|
||||
lt.api.post('/api/bulk_operation.php', {
|
||||
operation_type: 'bulk_status',
|
||||
ticket_ids: ticketIds,
|
||||
parameters: { status: status }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
closeBulkStatusModal();
|
||||
if (data.success) {
|
||||
@@ -1140,19 +1067,10 @@ function closeBulkDeleteModal() {
|
||||
function performBulkDelete() {
|
||||
const ticketIds = getSelectedTicketIds();
|
||||
|
||||
fetch('/api/bulk_operation.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_type: 'bulk_delete',
|
||||
ticket_ids: ticketIds
|
||||
})
|
||||
lt.api.post('/api/bulk_operation.php', {
|
||||
operation_type: 'bulk_delete',
|
||||
ticket_ids: ticketIds
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
closeBulkDeleteModal();
|
||||
if (data.success) {
|
||||
@@ -1341,19 +1259,7 @@ function closeQuickStatusModal() {
|
||||
function performQuickStatusChange(ticketId) {
|
||||
const newStatus = document.getElementById('quickStatusSelect').value;
|
||||
|
||||
fetch('/api/update_ticket.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ticket_id: ticketId,
|
||||
status: newStatus
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
lt.api.post('/api/update_ticket.php', { ticket_id: ticketId, status: newStatus })
|
||||
.then(data => {
|
||||
closeQuickStatusModal();
|
||||
if (data.success) {
|
||||
@@ -1423,19 +1329,7 @@ function closeQuickAssignModal() {
|
||||
function performQuickAssign(ticketId) {
|
||||
const assignedTo = document.getElementById('quickAssignSelect').value || null;
|
||||
|
||||
fetch('/api/assign_ticket.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ticket_id: ticketId,
|
||||
assigned_to: assignedTo
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
lt.api.post('/api/assign_ticket.php', { ticket_id: ticketId, assigned_to: assignedTo })
|
||||
.then(data => {
|
||||
closeQuickAssignModal();
|
||||
if (data.success) {
|
||||
|
||||
Reference in New Issue
Block a user