2 Commits

5 changed files with 27 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
<h4><%=t(:field_vehicles)%>:</h4>
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:page]) } %>
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:page]), show_customer: false, show_checkbox: false } %>
<div style="float: right;">
<%= button_to t(:button_new_vehicle), new_customer_vehicle_path(customer), method: :get %>
</div>

View File

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

View File

@@ -5,14 +5,23 @@
<div class="container">
<% if show_checkbox %>
<%= check_box_tag "vehicle_ids[]", vehicle.id, false, onchange: "updateLink()", data: { url: vehicle_path(vehicle).html_safe, text: vehicle.to_s }, class: "appointment checkbox" %>
<% else %>
<div class='checkbox'>
</div>
<% end %>
<div class='label-main'>
<%= link_to vehicle.to_s, vehicle_path(vehicle) %>
</div>
<div class="label-sub">
<%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b>
<a href="#" onclick="handleCopy(event)"><%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b></a>
<% if show_customer %>
<br/>
<%= vehicle.customer %>
<% end %>
</div>
</div>

View File

@@ -1,4 +1,4 @@
<h2><%=t(:label_customer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
<br/>
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles} %>
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles, show_customer: true, show_checkbox: false} %>

View File

@@ -1,17 +1,25 @@
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;
let text;
let link;
// 2. Grab the text from our clicked link
if(event.target.tagName.toLowerCase() === 'b'){
text = event.target.parentElement.innerText;
link = event.target.parentElement;
} else {
text = event.target.innerText;
link = event.target;
}
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.innerHTML = "<b>Copied!</b>";
link.style.color = "#4CAF50"; // Turn green