116 lines
4.8 KiB
Plaintext
116 lines
4.8 KiB
Plaintext
<%= form_with(model: reservation, class: "contents", data: { controller: "customer-search" }) do |form| %>
|
|
<% if reservation.errors.any? %>
|
|
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
|
|
<h2><%= pluralize(reservation.errors.count, "error") %> prohibited this reservation from being saved:</h2>
|
|
|
|
<ul>
|
|
<% reservation.errors.each do |error| %>
|
|
<li><%= error.full_message %></li>
|
|
<% end %>
|
|
</ul>
|
|
</div>
|
|
<% end %>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :customer %>
|
|
<%= form.select :customer_id,
|
|
[], # Start with empty options
|
|
{ prompt: "Type to search customers..." },
|
|
{
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
data: { customer_search_target: "select" }
|
|
} %>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :phone_number %>
|
|
<%= form.telephone_field :customer_original_phone,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
data: { customer_search_target: "phoneField" } %>
|
|
</div>
|
|
|
|
<div data-customer-search-target="newCustomerFields" class="hidden">
|
|
<div class="my-5">
|
|
<%= form.label :first_name %>
|
|
<%= form.text_field :customer_first_name,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
data: { customer_search_target: "firstNameField" } %>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :surname %>
|
|
<%= form.text_field :customer_surname,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
data: { customer_search_target: "surnameField" } %>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :birth_year %>
|
|
<%= form.number_field :customer_birth_year,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
data: { customer_search_target: "birthYearField" } %>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :team_id %>
|
|
<%= form.collection_select :team_id,
|
|
@company.teams,
|
|
:id,
|
|
:name,
|
|
{ prompt: "Select a team" },
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :start_time %>
|
|
<%= form.datetime_field :start_time,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
id: "start_time_field" %>
|
|
</div>
|
|
|
|
<div class="my-5">
|
|
<%= form.label :end_time %>
|
|
<%= form.datetime_field :end_time,
|
|
class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full",
|
|
id: "end_time_field" %>
|
|
</div>
|
|
|
|
<div class="inline">
|
|
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<script>
|
|
window.onload = function() {
|
|
// Only set default times for new records (not when editing)
|
|
<% unless reservation.persisted? %>
|
|
// Get current date and time
|
|
const now = new Date();
|
|
|
|
// Get local components
|
|
const year = now.getFullYear();
|
|
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
|
|
const day = String(now.getDate()).padStart(2, '0');
|
|
const hours = String(now.getHours()).padStart(2, '0');
|
|
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
|
|
// Format for datetime-local input (YYYY-MM-DDThh:mm)
|
|
const localStartTime = `${year}-${month}-${day}T${hours}:${minutes}`;
|
|
document.getElementById('start_time_field').value = localStartTime;
|
|
|
|
// Add 30 minutes for end time
|
|
const endDate = new Date(now.getTime() + 30 * 60000);
|
|
const endHours = String(endDate.getHours()).padStart(2, '0');
|
|
const endMinutes = String(endDate.getMinutes()).padStart(2, '0');
|
|
const localEndTime = `${year}-${month}-${day}T${endHours}:${endMinutes}`;
|
|
document.getElementById('end_time_field').value = localEndTime;
|
|
|
|
// For debugging - add this to see actual values
|
|
console.log("Start time set to: " + localStartTime);
|
|
console.log("End time set to: " + localEndTime);
|
|
console.log("Current browser time: " + now.toString());
|
|
<% end %>
|
|
};
|
|
</script>
|