mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-02-13 01:03:59 -05:00
simplified appointment link javascript
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
<% estimates.sort.reverse.each do |estimate| %>
|
||||
<div class="row">
|
||||
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { id: estimate.id, doc: estimate.doc_number }, class: "estimate-checkbox" %>
|
||||
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { url: estimate_path(estimate), text: "Estimate ##{estimate.to_s}" }, class: "estimate-checkbox appointment" %>
|
||||
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<% invoices.sort.reverse.each do |invoice| %>
|
||||
<div class="row">
|
||||
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { id: invoice.id, doc: invoice.doc_number }, class: "invoice-checkbox" if invoices.count > 1 %>
|
||||
<%= 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 %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
function updateLink() {
|
||||
console.log("updateLink called");
|
||||
const linkElement = document.getElementById("appointment_link");
|
||||
const regex = /((?:<br\/>|%3Cbr\/?%3E))([\s\S]*?)(&dates)/gi;
|
||||
linkElement.href = linkElement.href.replace(regex, `$1${getSelectedDocs()}$3`);
|
||||
}
|
||||
|
||||
function getSelectedDocs() {
|
||||
const invoices = document.querySelectorAll('.invoice-checkbox');
|
||||
const estimates = document.querySelectorAll('.estimate-checkbox');
|
||||
const appointent_extras = document.querySelectorAll('.appointment');
|
||||
|
||||
let output = '';
|
||||
|
||||
for (const i of invoices) {
|
||||
if (i.checked) {
|
||||
console.log(i.value);
|
||||
console.log(i.dataset.doc);
|
||||
output += `%0A<a href="${window.location.origin}/invoices/${i.dataset.id}">Invoice:%20${i.dataset.doc}</a>%0A`;
|
||||
for (const item of appointent_extras) {
|
||||
if (item.checked) {
|
||||
console.log(`Checked item: ${item.dataset.text} with URL: ${item.dataset.url}`);
|
||||
output += `%0A`+ encodeURIComponent(`<a href="${window.location.origin}${item.dataset.url}">${item.dataset.text}</a>`) +`%0A`;
|
||||
}
|
||||
}
|
||||
|
||||
for (const e of estimates) {
|
||||
if (e.checked) {
|
||||
console.log(e.value);
|
||||
console.log(e.dataset.doc);
|
||||
output += `%0A<a href="${window.location.origin}/estimates/${e.value}">Estimate:%20${e.dataset.doc}</a>%0A`;
|
||||
}
|
||||
}
|
||||
|
||||
// You can return the array or use it as needed
|
||||
return output;
|
||||
|
||||
Reference in New Issue
Block a user