Feature 4: Implement Ticket Templates
Add ticket template system for quick ticket creation: - Created TemplateModel.php with full CRUD operations for templates - Added get_template.php API endpoint to fetch template data - Updated TicketController to load templates in create() method - Modified CreateTicketView.php to include template selector dropdown - Added loadTemplate() JavaScript function to populate form fields - Templates include: title, description, category, type, and default priority - Database already seeded with default templates (Hardware Failure, Software Installation, Network Issue, Maintenance Request) Users can now select from predefined templates when creating tickets, speeding up common ticket creation workflows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -851,4 +851,65 @@ function saveTicket() {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Load template data into the create ticket form
|
||||
*/
|
||||
function loadTemplate() {
|
||||
const templateSelect = document.getElementById('templateSelect');
|
||||
const templateId = templateSelect.value;
|
||||
|
||||
if (!templateId) {
|
||||
// Clear form when "No Template" is selected
|
||||
document.getElementById('title').value = '';
|
||||
document.getElementById('description').value = '';
|
||||
document.getElementById('priority').value = '4';
|
||||
document.getElementById('category').value = 'General';
|
||||
document.getElementById('type').value = 'Issue';
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch template data
|
||||
fetch(`/api/get_template.php?template_id=${templateId}`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch template');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success && data.template) {
|
||||
const template = data.template;
|
||||
|
||||
// Populate form fields with template data
|
||||
if (template.title_template) {
|
||||
document.getElementById('title').value = template.title_template;
|
||||
}
|
||||
|
||||
if (template.description_template) {
|
||||
document.getElementById('description').value = template.description_template;
|
||||
}
|
||||
|
||||
if (template.category) {
|
||||
document.getElementById('category').value = template.category;
|
||||
}
|
||||
|
||||
if (template.type) {
|
||||
document.getElementById('type').value = template.type;
|
||||
}
|
||||
|
||||
if (template.default_priority) {
|
||||
document.getElementById('priority').value = template.default_priority;
|
||||
}
|
||||
|
||||
console.log('Template loaded:', template.template_name);
|
||||
} else {
|
||||
console.error('Failed to load template:', data.error);
|
||||
alert('Failed to load template: ' + (data.error || 'Unknown error'));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading template:', error);
|
||||
alert('Error loading template: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user