mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
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>
This commit is contained in:
1 parent
40eb6205c4
commit
92f9eb1bc7
11 files changed
+117
-72
No files matched your search
@@ -1,45 +1,58 @@
|
||||
<%#
|
||||
Adds what's ticked on the customer page to the "New issue" link (#dynamic-new-issue-link in the contextual
|
||||
area). Any checkbox with data-new-issue-param="issue[field]" takes part, one ticked per field: this plugin's
|
||||
estimates (issue[estimate_id]), and other plugins' lists (e.g. redmine_qbo_vehicles' issue[vehicle_id]).
|
||||
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 newIssueParamBoxes(param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[data-new-issue-param]'), function (cb) {
|
||||
return !param || cb.getAttribute('data-new-issue-param') === param;
|
||||
});
|
||||
}
|
||||
(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]';
|
||||
|
||||
// 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('input[data-new-issue-param]')) return;
|
||||
if (box.checked) {
|
||||
newIssueParamBoxes(box.getAttribute('data-new-issue-param')).forEach(function (cb) {
|
||||
if (cb !== box) cb.checked = false;
|
||||
function boxes(attr, param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[' + attr + ']'), function (cb) {
|
||||
return !param || cb.getAttribute(attr) === param;
|
||||
});
|
||||
}
|
||||
updateLink();
|
||||
});
|
||||
|
||||
function updateLink() {
|
||||
var 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');
|
||||
var url = new URL(link.dataset.baseUrl, window.location.origin);
|
||||
|
||||
newIssueParamBoxes().forEach(function (cb) {
|
||||
var param = cb.getAttribute('data-new-issue-param');
|
||||
var ticked = newIssueParamBoxes(param).filter(function (b) { return b.checked; })[0];
|
||||
if (ticked) {
|
||||
url.searchParams.set(param, ticked.value);
|
||||
} else {
|
||||
url.searchParams.delete(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];
|
||||
}
|
||||
|
||||
link.setAttribute('href', url.toString());
|
||||
}
|
||||
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>
|
||||
@@ -52,7 +52,7 @@
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<h4><%=t(:estimates)%>:</h4>
|
||||
<%= render partial: 'estimates/list', locals: {estimates: @customer.estimates} %>
|
||||
<%= render partial: 'estimates/list', locals: {estimates: @customer.estimates, new_issue_checkboxes: true} %>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
|
||||
@@ -3,14 +3,19 @@
|
||||
<%= render partial: 'qbo_estimates/status_styles' %>
|
||||
<div class="qbo-estimate-list">
|
||||
<% estimates.sort.reverse.each do |estimate| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}", new_issue_param: 'issue[estimate_id]' }, class: "estimate-checkbox appointment" %>
|
||||
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
|
||||
<%# Ticking an estimate adds it to the customer page's New issue and Add appointment links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { new_issue_param: 'issue[estimate_id]', appointment_param: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= estimate.txn_date %></span>
|
||||
<%# QuickBooks status, cached by the estimate sync (kept current by the webhook) %>
|
||||
<% if estimate.txn_status.present? %>
|
||||
<span class="qbo-estimate-status qbo-estimate-status-<%= estimate.txn_status.downcase %>"><%= estimate.txn_status %></span>
|
||||
<% end %>
|
||||
<%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %>
|
||||
<span class="qbo-list-status">
|
||||
<% if estimate.txn_status.present? %>
|
||||
<span class="qbo-estimate-status qbo-estimate-status-<%= estimate.txn_status.downcase %>"><%= estimate.txn_status %></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="qbo-list-actions"><%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -13,14 +13,19 @@
|
||||
|
||||
<div class="qbo-invoice-list">
|
||||
<% invoices.sort.reverse.each do |invoice| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" if invoices.count > 1 %>
|
||||
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
|
||||
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %>
|
||||
<% if (status = invoice.status) %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: invoice.paid_on) %></span>
|
||||
<% end %>
|
||||
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "invoice_ids[]", invoice.id, false, class: "invoice-checkbox" if invoices.count > 1 %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= invoice.txn_date %></span>
|
||||
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date; short so the list
|
||||
stays narrow: "Paid", or "Paid +3d" when paid in full days after its date (the date on hover) %>
|
||||
<span class="qbo-list-status">
|
||||
<% if (status = invoice.status) %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>" title="<%= RedmineQboBilling::InvoiceStatus.title(status, paid_on: invoice.paid_on) %>"><%= RedmineQboBilling::InvoiceStatus.short_label(status, paid_on: invoice.paid_on, invoice_date: invoice.txn_date) %></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="qbo-list-actions"><%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -14,4 +14,11 @@
|
||||
.qbo-invoice-status-open { background: #e8eefa; color: #0d47a1; }
|
||||
.qbo-invoice-status-voided { background: #eceef1; color: #6b6c72; text-decoration: line-through; }
|
||||
.qbo-invoice-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
|
||||
/* The estimate and invoice lists: checkbox, number, date, status and actions in columns, so the edit/view icons
|
||||
line up; a list wider than its column scrolls instead of wrapping */
|
||||
.qbo-estimate-list, .qbo-invoice-list { display: grid; grid-template-columns: repeat(5, max-content); column-gap: .35em;
|
||||
row-gap: 2px; align-items: center; overflow-x: auto; }
|
||||
.qbo-estimate-list .row, .qbo-invoice-list .row { display: contents; }
|
||||
.qbo-estimate-list .row > *, .qbo-invoice-list .row > * { white-space: nowrap; }
|
||||
.qbo-list-status .qbo-estimate-status { margin-left: 0; }
|
||||
</style>
|
||||
Reference in new issue
Block a user