mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
- New issue, Create estimate, Create payment and Edit now sit in Redmine's top-right contextual area (icons, like issue pages) instead of an "Actions" column next to the customer details - New view hook :view_customers_show_contextual (context: customer) for plugins to add their own action links there; replaces customer_actions_top / customer_actions_bottom (README updated) - The New issue link still picks up the estimate / vehicle ticked on the page (script moved to customers/_new_issue_link_script) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
60 lines
1.9 KiB
ERB
60 lines
1.9 KiB
ERB
<%#
|
|
Adds the estimate and vehicle ticked on the customer page to the "New issue" link
|
|
(#dynamic-new-issue-link in the contextual area). One of each can be ticked.
|
|
%>
|
|
<script>
|
|
function handleSingleSelect(event, className) {
|
|
if (event.target.checked) {
|
|
// Uncheck all other checkboxes of the same type
|
|
document.querySelectorAll('.' + className).forEach(cb => {
|
|
if (cb !== event.target) {
|
|
cb.checked = false;
|
|
}
|
|
});
|
|
}
|
|
updateLink();
|
|
}
|
|
|
|
// Bind single-select behavior to checkboxes once the DOM is loaded
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.querySelectorAll('.estimate-checkbox').forEach(cb => {
|
|
cb.addEventListener('change', (e) => handleSingleSelect(e, 'estimate-checkbox'));
|
|
});
|
|
document.querySelectorAll('.vehicle-checkbox').forEach(cb => {
|
|
cb.addEventListener('change', (e) => handleSingleSelect(e, 'vehicle-checkbox'));
|
|
});
|
|
});
|
|
|
|
function updateLink() {
|
|
const link = document.getElementById('dynamic-new-issue-link');
|
|
if (!link) return;
|
|
|
|
// Cache the pristine base URL on first run
|
|
if (!link.dataset.baseUrl) {
|
|
link.dataset.baseUrl = link.getAttribute('href');
|
|
}
|
|
|
|
// Build base URL object
|
|
let url = new URL(link.dataset.baseUrl, window.location.origin);
|
|
|
|
// 1. Handle Single Estimate
|
|
const checkedEstimate = document.querySelector('.estimate-checkbox:checked');
|
|
if (checkedEstimate) {
|
|
url.searchParams.set('issue[estimate_id]', checkedEstimate.value);
|
|
} else {
|
|
url.searchParams.delete('issue[estimate_id]');
|
|
}
|
|
|
|
// 2. Handle Single Vehicle
|
|
const checkedVehicle = document.querySelector('.vehicle-checkbox:checked');
|
|
if (checkedVehicle) {
|
|
url.searchParams.set('issue[vehicle_id]', checkedVehicle.value);
|
|
} else {
|
|
url.searchParams.delete('issue[vehicle_id]');
|
|
}
|
|
|
|
// Update the link's href attribute
|
|
link.setAttribute('href', url.toString());
|
|
}
|
|
</script>
|