Files
redmine_qbo/app/views/customers/_new_issue_link_script.html.erb
T
rickyandClaude Opus 5.5 92f9eb1bc7 Customer page lists: short paid badge, aligned icons, appointment link
* The invoice list's paid badge is short so each invoice stays on one
  line: "Paid", or "Paid +3d" when it was paid in full 3 days after
  its date, with the day on hover. The invoice page keeps the date.
* The estimate and invoice lists are laid out in columns (checkbox,
  number, date, status, actions), so the edit/view icons line up.
* Ticked estimates (and redmine_qbo_vehicles' vehicles) fill in
  redmine_qbo_calendar's Add appointment link (estimate_id,
  vehicle_id) as well as New issue. Estimate checkboxes are only on
  the customer page, where they're used.
* application.js is gone: it only carried the old Google Calendar
  link code, which threw an error when a box was ticked on a vehicle
  page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 19:39:08 -05:00

59 lines
2.3 KiB
ERB

<%#
Adds what's ticked on the customer page to its links: "New issue" (#dynamic-new-issue-link in the contextual area)
and redmine_qbo_calendar's "Add appointment" (#appointment_link). A checkbox takes part with
data-new-issue-param="issue[field]" (New issue) and data-appointment-param="field" (Add appointment); one is
ticked per field: this plugin's estimates (estimate_id), and other plugins' lists (e.g. redmine_qbo_vehicles'
vehicle_id).
%>
<script>
(function () {
var LINKS = [['dynamic-new-issue-link', 'data-new-issue-param'], ['appointment_link', 'data-appointment-param']];
var ANY = 'input[data-new-issue-param], input[data-appointment-param]';
function boxes(attr, param) {
return Array.prototype.filter.call(document.querySelectorAll('input[' + attr + ']'), function (cb) {
return !param || cb.getAttribute(attr) === param;
});
}
// Boxes for the same field (the same estimate list, the same vehicle list)
function sameField(box) {
for (var i = 0; i < LINKS.length; i++) {
var attr = LINKS[i][1], param = box.getAttribute(attr);
if (param) return boxes(attr, param);
}
return [box];
}
function updateLinks() {
LINKS.forEach(function (pair) {
var link = document.getElementById(pair[0]);
if (!link) return;
// Cache the pristine base URL on first run
if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
var url = new URL(link.dataset.baseUrl, window.location.origin);
boxes(pair[1]).forEach(function (cb) {
var param = cb.getAttribute(pair[1]);
var ticked = boxes(pair[1], param).filter(function (b) { return b.checked; })[0];
if (ticked) {
url.searchParams.set(param, ticked.value);
} else {
url.searchParams.delete(param);
}
});
link.setAttribute('href', url.toString());
});
}
// One box per field: ticking one unticks the others for the same field
document.addEventListener('change', function (event) {
var box = event.target;
if (!box.matches || !box.matches(ANY)) return;
if (box.checked) {
sameField(box).forEach(function (cb) { if (cb !== box) cb.checked = false; });
}
updateLinks();
});
})();
</script>