Files
redmine_qbo/app/views/customers/_new_issue_link_script.html.erb
T
rickyandClaude Opus 5.5 ae0ffc7c1c Leave other plugins' features to hooks
Refund emails and PDFs take the shop name and mail settings from
:qbo_mail_settings instead of reading redmine_qbo_reminders' settings; the
customer page's ticked boxes use generic data-ticked-field/data-ticked-params
instead of knowing redmine_qbo_calendar's Add appointment link; and Create
issues carries the params plugins name in :qbo_billing_issue_carry_params
instead of appointment_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 07:37:57 -05:00

52 lines
2.1 KiB
ERB

<%#
Adds what's ticked on the customer page to its links. A checkbox takes part with data-ticked-field="field"
(one is ticked per field), e.g. this plugin's estimates (estimate_id) and other plugins' lists. A link takes
part with data-ticked-params, how each field is named in its URL: "issue[%s]" for New issue
(#dynamic-new-issue-link), "%s" for a plain param. Other plugins' links on the page work the same way.
%>
<script>
(function () {
var BOX = 'input[data-ticked-field]';
function boxes(field) {
return Array.prototype.filter.call(document.querySelectorAll(BOX), function (cb) {
return !field || cb.getAttribute('data-ticked-field') === field;
});
}
function fields() {
return boxes().map(function (cb) { return cb.getAttribute('data-ticked-field'); })
.filter(function (field, i, all) { return all.indexOf(field) === i; });
}
function updateLinks() {
Array.prototype.forEach.call(document.querySelectorAll('a[data-ticked-params]'), function (link) {
// 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);
var format = link.getAttribute('data-ticked-params');
fields().forEach(function (field) {
var param = format.replace('%s', field);
var ticked = boxes(field).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(BOX)) return;
if (box.checked) {
boxes(box.getAttribute('data-ticked-field')).forEach(function (cb) { if (cb !== box) cb.checked = false; });
}
updateLinks();
});
})();
</script>