mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-02-14 09:43:59 -05:00
added js to copy vin on click
This commit is contained in:
@@ -5,7 +5,10 @@
|
||||
|
||||
<div class="vehicle_vin attribute">
|
||||
<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 class="vehicle_notes attribute">
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
<tr>
|
||||
<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>
|
||||
|
||||
<th><%= t(:label_trim) %></th>
|
||||
|
||||
28
assets/javascripts/copy.js
Normal file
28
assets/javascripts/copy.js
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,8 @@ module Vehicles
|
||||
|
||||
def view_layouts_base_html_head(context = {})
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user