added js to copy vin on click

This commit is contained in:
2026-02-13 21:28:45 -05:00
parent 12fb8b47ef
commit 5cad4a6856
4 changed files with 37 additions and 3 deletions

View File

@@ -5,7 +5,10 @@
<div class="vehicle_vin attribute"> <div class="vehicle_vin attribute">
<div class="label"><span><%=t(:field_vin)%></span>:</div> <div class="label"><span><%=t(:field_vin)%></span>:</div>
<div class="value"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></b></div> <div class="value" id="vin">
<a href="#" id="copyLink" onclick="handleCopy(event)"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></a>
</div>
</div> </div>
<div class="vehicle_notes attribute"> <div class="vehicle_notes attribute">

View File

@@ -18,7 +18,9 @@
<tr> <tr>
<th><%= t(:field_vin) %></th> <th><%= t(:field_vin) %></th>
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td> <td id="vin">
<a href="#" onclick="handleCopy(event)"><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></a>
</td>
</tr> </tr>
<th><%= t(:label_trim) %></th> <th><%= t(:label_trim) %></th>

View File

@@ -0,0 +1,28 @@
async function handleCopy(event) {
console.log("Copy link clicked");
// 1. Prevent the link from actually navigating
event.preventDefault();
// 2. Grab the text from our span
const text = document.getElementById('vin').innerText;
try {
// 3. Write to clipboard
await navigator.clipboard.writeText(text);
// 4. Update the UI to show it worked
const link = event.target;
const originalText = link.innerText;
link.innerText = "Copied!";
link.style.color = "#4CAF50"; // Turn green
// 5. Reset after 2 seconds
setTimeout(() => {
link.innerText = originalText;
link.style.color = "";
}, 2000);
} catch (err) {
console.error('Unable to copy', err);
}
}

View File

@@ -14,7 +14,8 @@ module Vehicles
def view_layouts_base_html_head(context = {}) def view_layouts_base_html_head(context = {})
safe_join([ safe_join([
stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all) stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all),
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles)
]) ])
end end