From 5cad4a685670ace9585bdef4999d07a7b9cc6ebe Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Fri, 13 Feb 2026 21:28:45 -0500 Subject: [PATCH] added js to copy vin on click --- .../issues/_show_issue_view_right.html.erb | 5 +++- app/views/vehicles/_details.html.erb | 4 ++- assets/javascripts/copy.js | 28 +++++++++++++++++++ lib/vehicles/hooks/view_hook_listener.rb | 3 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 assets/javascripts/copy.js diff --git a/app/views/issues/_show_issue_view_right.html.erb b/app/views/issues/_show_issue_view_right.html.erb index 06f8593..bbdf1e6 100644 --- a/app/views/issues/_show_issue_view_right.html.erb +++ b/app/views/issues/_show_issue_view_right.html.erb @@ -5,7 +5,10 @@
<%=t(:field_vin)%>:
-
<%=split_vin[0] if split_vin%><%=split_vin[1] if split_vin%>
+ +
diff --git a/app/views/vehicles/_details.html.erb b/app/views/vehicles/_details.html.erb index 2875758..097a6f4 100644 --- a/app/views/vehicles/_details.html.erb +++ b/app/views/vehicles/_details.html.erb @@ -18,7 +18,9 @@ <%= t(:field_vin) %> - <%= @vin[0] if @vin %><%=@vin[1] if @vin%> + + <%= @vin[0] if @vin %><%=@vin[1] if @vin%> + <%= t(:label_trim) %> diff --git a/assets/javascripts/copy.js b/assets/javascripts/copy.js new file mode 100644 index 0000000..801694d --- /dev/null +++ b/assets/javascripts/copy.js @@ -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); + } +} \ No newline at end of file diff --git a/lib/vehicles/hooks/view_hook_listener.rb b/lib/vehicles/hooks/view_hook_listener.rb index 3420f46..c02eefc 100644 --- a/lib/vehicles/hooks/view_hook_listener.rb +++ b/lib/vehicles/hooks/view_hook_listener.rb @@ -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