use sidecar templates
This commit is contained in:
parent
42bc918abc
commit
e882330c14
@ -44,70 +44,6 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
|
|||||||
save_ammo_group(socket, action, ammo_group_params)
|
save_ammo_group(socket, action, ammo_group_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<h2 class="text-center title text-xl text-primary-500">
|
|
||||||
<%= @title %>
|
|
||||||
</h2>
|
|
||||||
<.form
|
|
||||||
let={f}
|
|
||||||
for={@changeset}
|
|
||||||
id="ammo_group-form"
|
|
||||||
phx-target={@myself}
|
|
||||||
phx-change="validate"
|
|
||||||
phx-submit="save"
|
|
||||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
|
||||||
>
|
|
||||||
<%= if @changeset.action do %>
|
|
||||||
<div class="invalid-feedback col-span-3 text-center">
|
|
||||||
<%= changeset_errors(@changeset) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= select(f, :ammo_type_id, ammo_type_options(@ammo_types),
|
|
||||||
class: "text-center col-span-2 input input-primary"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :ammo_type_id, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :count, gettext("Count"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= number_input(f, :count,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
min: 1
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :count, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :price_paid, gettext("Price paid"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= number_input(f, :price_paid,
|
|
||||||
step: "0.01",
|
|
||||||
class: "text-center col-span-2 input input-primary"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :notes, gettext("Notes"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= textarea(f, :notes,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
phx_hook: "MaintainAttrs"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :notes, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :container, gettext("Container"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= select(f, :container_id, container_options(@containers),
|
|
||||||
class: "text-center col-span-2 input input-primary"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :container_id, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= submit(dgettext("actions", "Save"),
|
|
||||||
phx_disable_with: dgettext("prompts", "Saving..."),
|
|
||||||
class: "mx-auto col-span-3 btn btn-primary"
|
|
||||||
) %>
|
|
||||||
</.form>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
# HTML Helpers
|
# HTML Helpers
|
||||||
@spec container_options([Container.t()]) :: [{String.t(), Container.id()}]
|
@spec container_options([Container.t()]) :: [{String.t(), Container.id()}]
|
||||||
defp container_options(containers) do
|
defp container_options(containers) do
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
<div>
|
||||||
|
<h2 class="text-center title text-xl text-primary-500">
|
||||||
|
<%= @title %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={@changeset}
|
||||||
|
id="ammo_group-form"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-change="validate"
|
||||||
|
phx-submit="save"
|
||||||
|
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||||
|
>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="invalid-feedback col-span-3 text-center">
|
||||||
|
<%= changeset_errors(@changeset) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= select(f, :ammo_type_id, ammo_type_options(@ammo_types),
|
||||||
|
class: "text-center col-span-2 input input-primary"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :ammo_type_id, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :count, gettext("Count"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= number_input(f, :count,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
min: 1
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :count, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :price_paid, gettext("Price paid"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= number_input(f, :price_paid,
|
||||||
|
step: "0.01",
|
||||||
|
class: "text-center col-span-2 input input-primary"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :notes, gettext("Notes"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= textarea(f, :notes,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
phx_hook: "MaintainAttrs"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :notes, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :container, gettext("Container"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= select(f, :container_id, container_options(@containers),
|
||||||
|
class: "text-center col-span-2 input input-primary"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :container_id, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= submit(dgettext("actions", "Save"),
|
||||||
|
phx_disable_with: dgettext("prompts", "Saving..."),
|
||||||
|
class: "mx-auto col-span-3 btn btn-primary"
|
||||||
|
) %>
|
||||||
|
</.form>
|
||||||
|
</div>
|
@ -34,139 +34,6 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
|
|||||||
save_ammo_type(socket, action, ammo_type_params)
|
save_ammo_type(socket, action, ammo_type_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<h2 class="text-center title text-xl text-primary-500">
|
|
||||||
<%= @title %>
|
|
||||||
</h2>
|
|
||||||
<.form
|
|
||||||
let={f}
|
|
||||||
for={@changeset}
|
|
||||||
id="ammo_type-form"
|
|
||||||
phx-target={@myself}
|
|
||||||
phx-change="validate"
|
|
||||||
phx-submit="save"
|
|
||||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
|
||||||
>
|
|
||||||
<%= if @changeset.action do %>
|
|
||||||
<div class="invalid-feedback col-span-3 text-center">
|
|
||||||
<%= changeset_errors(@changeset) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= label(f, :name, gettext("Name"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :name, class: "text-center col-span-2 input input-primary") %>
|
|
||||||
<%= error_tag(f, :name, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :desc, gettext("Description"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= textarea(f, :desc,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
phx_hook: "MaintainAttrs"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :desc, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<a
|
|
||||||
href="https://en.wikipedia.org/wiki/Bullet#Abbreviations"
|
|
||||||
class="col-span-3 text-center link title text-md text-primary-600"
|
|
||||||
>
|
|
||||||
<%= gettext("Example bullet type abbreviations") %>
|
|
||||||
</a>
|
|
||||||
<%= label(f, :bullet_type, gettext("Bullet type"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :bullet_type,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: gettext("FMJ")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :bullet_type, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :bullet_core, gettext("Bullet core"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :bullet_core,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: gettext("Steel")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :bullet_core, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :cartridge, gettext("Cartridge"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :cartridge,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: "5.56x46mm NATO"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :cartridge, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :caliber, gettext("Caliber"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :caliber,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: ".223"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :caliber, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :case_material, gettext("Case material"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :case_material,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: gettext("Brass")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :grains, gettext("Grains"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= number_input(f, :grains,
|
|
||||||
step: "1",
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
min: 1
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :grains, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :pressure, gettext("Pressure"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :pressure,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: "+P"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :pressure, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :primer_type, gettext("Primer type"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :primer_type,
|
|
||||||
class: "text-center col-span-2 input input-primary",
|
|
||||||
placeholder: "Boxer"
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :primer_type, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :rimfire, gettext("Rimfire"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= checkbox(f, :rimfire, class: "text-center col-span-2 checkbox") %>
|
|
||||||
<%= error_tag(f, :rimfire, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :tracer, gettext("Tracer"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= checkbox(f, :tracer, class: "text-center col-span-2 checkbox") %>
|
|
||||||
<%= error_tag(f, :tracer, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :incendiary, gettext("Incendiary"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= checkbox(f, :incendiary, class: "text-center col-span-2 checkbox") %>
|
|
||||||
<%= error_tag(f, :incendiary, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :blank, gettext("Blank"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= checkbox(f, :blank, class: "text-center col-span-2 checkbox") %>
|
|
||||||
<%= error_tag(f, :blank, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :corrosive, gettext("Corrosive"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= checkbox(f, :corrosive, class: "text-center col-span-2 checkbox") %>
|
|
||||||
<%= error_tag(f, :corrosive, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :manufacturer, gettext("Manufacturer"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :manufacturer, class: "text-center col-span-2 input input-primary") %>
|
|
||||||
<%= error_tag(f, :manufacturer, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :sku, gettext("SKU"), class: "mr-4 title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :sku, class: "text-center col-span-2 input input-primary") %>
|
|
||||||
<%= error_tag(f, :sku, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= submit(dgettext("actions", "Save"),
|
|
||||||
phx_disable_with: dgettext("prompts", "Saving..."),
|
|
||||||
class: "mx-auto col-span-3 btn btn-primary"
|
|
||||||
) %>
|
|
||||||
</.form>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
defp save_ammo_type(
|
defp save_ammo_type(
|
||||||
%{assigns: %{ammo_type: ammo_type, current_user: current_user, return_to: return_to}} =
|
%{assigns: %{ammo_type: ammo_type, current_user: current_user, return_to: return_to}} =
|
||||||
socket,
|
socket,
|
||||||
|
127
lib/cannery_web/live/ammo_type_live/form_component.html.heex
Normal file
127
lib/cannery_web/live/ammo_type_live/form_component.html.heex
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<div>
|
||||||
|
<h2 class="text-center title text-xl text-primary-500">
|
||||||
|
<%= @title %>
|
||||||
|
</h2>
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={@changeset}
|
||||||
|
id="ammo_type-form"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-change="validate"
|
||||||
|
phx-submit="save"
|
||||||
|
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||||
|
>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="invalid-feedback col-span-3 text-center">
|
||||||
|
<%= changeset_errors(@changeset) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label(f, :name, gettext("Name"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :name, class: "text-center col-span-2 input input-primary") %>
|
||||||
|
<%= error_tag(f, :name, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :desc, gettext("Description"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= textarea(f, :desc,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
phx_hook: "MaintainAttrs"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :desc, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="https://en.wikipedia.org/wiki/Bullet#Abbreviations"
|
||||||
|
class="col-span-3 text-center link title text-md text-primary-600"
|
||||||
|
>
|
||||||
|
<%= gettext("Example bullet type abbreviations") %>
|
||||||
|
</a>
|
||||||
|
<%= label(f, :bullet_type, gettext("Bullet type"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :bullet_type,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: gettext("FMJ")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :bullet_type, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :bullet_core, gettext("Bullet core"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :bullet_core,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: gettext("Steel")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :bullet_core, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :cartridge, gettext("Cartridge"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :cartridge,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: "5.56x46mm NATO"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :cartridge, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :caliber, gettext("Caliber"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :caliber,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: ".223"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :caliber, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :case_material, gettext("Case material"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :case_material,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: gettext("Brass")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :grains, gettext("Grains"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= number_input(f, :grains,
|
||||||
|
step: "1",
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
min: 1
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :grains, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :pressure, gettext("Pressure"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :pressure,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: "+P"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :pressure, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :primer_type, gettext("Primer type"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :primer_type,
|
||||||
|
class: "text-center col-span-2 input input-primary",
|
||||||
|
placeholder: "Boxer"
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :primer_type, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :rimfire, gettext("Rimfire"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= checkbox(f, :rimfire, class: "text-center col-span-2 checkbox") %>
|
||||||
|
<%= error_tag(f, :rimfire, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :tracer, gettext("Tracer"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= checkbox(f, :tracer, class: "text-center col-span-2 checkbox") %>
|
||||||
|
<%= error_tag(f, :tracer, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :incendiary, gettext("Incendiary"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= checkbox(f, :incendiary, class: "text-center col-span-2 checkbox") %>
|
||||||
|
<%= error_tag(f, :incendiary, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :blank, gettext("Blank"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= checkbox(f, :blank, class: "text-center col-span-2 checkbox") %>
|
||||||
|
<%= error_tag(f, :blank, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :corrosive, gettext("Corrosive"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= checkbox(f, :corrosive, class: "text-center col-span-2 checkbox") %>
|
||||||
|
<%= error_tag(f, :corrosive, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :manufacturer, gettext("Manufacturer"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :manufacturer, class: "text-center col-span-2 input input-primary") %>
|
||||||
|
<%= error_tag(f, :manufacturer, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :sku, gettext("SKU"), class: "mr-4 title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :sku, class: "text-center col-span-2 input input-primary") %>
|
||||||
|
<%= error_tag(f, :sku, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= submit(dgettext("actions", "Save"),
|
||||||
|
phx_disable_with: dgettext("prompts", "Saving..."),
|
||||||
|
class: "mx-auto col-span-3 btn btn-primary"
|
||||||
|
) %>
|
||||||
|
</.form>
|
||||||
|
</div>
|
@ -44,34 +44,6 @@ defmodule CanneryWeb.ContainerLive.AddTagComponent do
|
|||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<h2 class="mb-4 text-center title text-xl text-primary-500">
|
|
||||||
<%= @title %>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<.form
|
|
||||||
let={f}
|
|
||||||
for={:tag}
|
|
||||||
id="add-tag-to-container-form"
|
|
||||||
class="grid grid-cols-3 justify-center items-center space-x-2"
|
|
||||||
phx-target={@myself}
|
|
||||||
phx-submit="save"
|
|
||||||
>
|
|
||||||
<%= select(f, :tag_id, tag_options(@tags), class: "text-center col-span-2 input input-primary") %>
|
|
||||||
<%= error_tag(f, :tag_id, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= submit(dgettext("actions", "Add"),
|
|
||||||
class: "mx-auto btn btn-primary",
|
|
||||||
phx_disable_with: dgettext("prompts", "Adding...")
|
|
||||||
) %>
|
|
||||||
</.form>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec tag_options([Tag.t()]) :: [{String.t(), Tag.id()}]
|
@spec tag_options([Tag.t()]) :: [{String.t(), Tag.id()}]
|
||||||
defp tag_options(tags) do
|
defp tag_options(tags) do
|
||||||
tags |> Enum.map(fn %{id: id, name: name} -> {name, id} end)
|
tags |> Enum.map(fn %{id: id, name: name} -> {name, id} end)
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<div>
|
||||||
|
<h2 class="mb-4 text-center title text-xl text-primary-500">
|
||||||
|
<%= @title %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={:tag}
|
||||||
|
id="add-tag-to-container-form"
|
||||||
|
class="grid grid-cols-3 justify-center items-center space-x-2"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-submit="save"
|
||||||
|
>
|
||||||
|
<%= select(f, :tag_id, tag_options(@tags), class: "text-center col-span-2 input input-primary") %>
|
||||||
|
<%= error_tag(f, :tag_id, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= submit(dgettext("actions", "Add"),
|
||||||
|
class: "mx-auto btn btn-primary",
|
||||||
|
phx_disable_with: dgettext("prompts", "Adding...")
|
||||||
|
) %>
|
||||||
|
</.form>
|
||||||
|
</div>
|
@ -35,67 +35,6 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
|
|||||||
save_container(socket, action, container_params)
|
save_container(socket, action, container_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<h2 class="text-center title text-xl text-primary-500">
|
|
||||||
<%= @title %>
|
|
||||||
</h2>
|
|
||||||
<.form
|
|
||||||
let={f}
|
|
||||||
for={@changeset}
|
|
||||||
id="container-form"
|
|
||||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
|
||||||
phx-target={@myself}
|
|
||||||
phx-change="validate"
|
|
||||||
phx-submit="save"
|
|
||||||
>
|
|
||||||
<%= if @changeset.action do %>
|
|
||||||
<div class="invalid-feedback col-span-3 text-center">
|
|
||||||
<%= changeset_errors(@changeset) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :name,
|
|
||||||
class: "input input-primary col-span-2",
|
|
||||||
placeholder: gettext("My cool ammo can")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :name, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :desc, gettext("Description"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= textarea(f, :desc,
|
|
||||||
class: "input input-primary col-span-2",
|
|
||||||
phx_hook: "MaintainAttrs",
|
|
||||||
placeholder: gettext("Metal ammo can with the anime girl sticker")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :desc, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :type, gettext("Type"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :type,
|
|
||||||
class: "input input-primary col-span-2",
|
|
||||||
placeholder: gettext("Magazine, Clip, Ammo Box, etc")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :type, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= label(f, :location, gettext("Location"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= textarea(f, :location,
|
|
||||||
class: "input input-primary col-span-2",
|
|
||||||
phx_hook: "MaintainAttrs",
|
|
||||||
placeholder: gettext("On the bookshelf")
|
|
||||||
) %>
|
|
||||||
<%= error_tag(f, :location, "col-span-3 text-center") %>
|
|
||||||
|
|
||||||
<%= submit(dgettext("actions", "Save"),
|
|
||||||
class: "mx-auto btn btn-primary col-span-3",
|
|
||||||
phx_disable_with: dgettext("prompts", "Saving...")
|
|
||||||
) %>
|
|
||||||
</.form>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
defp save_container(
|
defp save_container(
|
||||||
%{assigns: %{container: container, current_user: current_user, return_to: return_to}} =
|
%{assigns: %{container: container, current_user: current_user, return_to: return_to}} =
|
||||||
socket,
|
socket,
|
||||||
|
55
lib/cannery_web/live/container_live/form_component.html.heex
Normal file
55
lib/cannery_web/live/container_live/form_component.html.heex
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<div>
|
||||||
|
<h2 class="text-center title text-xl text-primary-500">
|
||||||
|
<%= @title %>
|
||||||
|
</h2>
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={@changeset}
|
||||||
|
id="container-form"
|
||||||
|
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-change="validate"
|
||||||
|
phx-submit="save"
|
||||||
|
>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="invalid-feedback col-span-3 text-center">
|
||||||
|
<%= changeset_errors(@changeset) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :name,
|
||||||
|
class: "input input-primary col-span-2",
|
||||||
|
placeholder: gettext("My cool ammo can")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :name, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :desc, gettext("Description"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= textarea(f, :desc,
|
||||||
|
class: "input input-primary col-span-2",
|
||||||
|
phx_hook: "MaintainAttrs",
|
||||||
|
placeholder: gettext("Metal ammo can with the anime girl sticker")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :desc, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :type, gettext("Type"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :type,
|
||||||
|
class: "input input-primary col-span-2",
|
||||||
|
placeholder: gettext("Magazine, Clip, Ammo Box, etc")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :type, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= label(f, :location, gettext("Location"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= textarea(f, :location,
|
||||||
|
class: "input input-primary col-span-2",
|
||||||
|
phx_hook: "MaintainAttrs",
|
||||||
|
placeholder: gettext("On the bookshelf")
|
||||||
|
) %>
|
||||||
|
<%= error_tag(f, :location, "col-span-3 text-center") %>
|
||||||
|
|
||||||
|
<%= submit(dgettext("actions", "Save"),
|
||||||
|
class: "mx-auto btn btn-primary col-span-3",
|
||||||
|
phx_disable_with: dgettext("prompts", "Saving...")
|
||||||
|
) %>
|
||||||
|
</.form>
|
||||||
|
</div>
|
@ -30,45 +30,6 @@ defmodule CanneryWeb.InviteLive.FormComponent do
|
|||||||
save_invite(socket, action, invite_params)
|
save_invite(socket, action, invite_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<h2 class="text-center title text-xl text-primary-500">
|
|
||||||
<%= @title %>
|
|
||||||
</h2>
|
|
||||||
<.form
|
|
||||||
let={f}
|
|
||||||
for={@changeset}
|
|
||||||
id="invite-form"
|
|
||||||
class="grid grid-cols-3 justify-center items-center space-y-4"
|
|
||||||
phx-target={@myself}
|
|
||||||
phx-change="validate"
|
|
||||||
phx-submit="save"
|
|
||||||
>
|
|
||||||
<%= if @changeset.action do %>
|
|
||||||
<div class="invalid-feedback col-span-3 text-center">
|
|
||||||
<%= changeset_errors(@changeset) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= text_input(f, :name, class: "input input-primary col-span-2") %>
|
|
||||||
<%= error_tag(f, :name, "col-span-3") %>
|
|
||||||
|
|
||||||
<%= label(f, :uses_left, gettext("Uses left"), class: "title text-lg text-primary-500") %>
|
|
||||||
<%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
|
|
||||||
<%= error_tag(f, :uses_left, "col-span-3") %>
|
|
||||||
|
|
||||||
<%= submit(dgettext("actions", "Save"),
|
|
||||||
class: "mx-auto btn btn-primary col-span-3",
|
|
||||||
phx_disable_with: dgettext("prompts", "Saving...")
|
|
||||||
) %>
|
|
||||||
</.form>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
defp save_invite(
|
defp save_invite(
|
||||||
%{assigns: %{current_user: current_user, invite: invite, return_to: return_to}} = socket,
|
%{assigns: %{current_user: current_user, invite: invite, return_to: return_to}} = socket,
|
||||||
:edit,
|
:edit,
|
||||||
|
33
lib/cannery_web/live/invite_live/form_component.html.heex
Normal file
33
lib/cannery_web/live/invite_live/form_component.html.heex
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<div>
|
||||||
|
<h2 class="text-center title text-xl text-primary-500">
|
||||||
|
<%= @title %>
|
||||||
|
</h2>
|
||||||
|
<.form
|
||||||
|
let={f}
|
||||||
|
for={@changeset}
|
||||||
|
id="invite-form"
|
||||||
|
class="grid grid-cols-3 justify-center items-center space-y-4"
|
||||||
|
phx-target={@myself}
|
||||||
|
phx-change="validate"
|
||||||
|
phx-submit="save"
|
||||||
|
>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="invalid-feedback col-span-3 text-center">
|
||||||
|
<%= changeset_errors(@changeset) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= text_input(f, :name, class: "input input-primary col-span-2") %>
|
||||||
|
<%= error_tag(f, :name, "col-span-3") %>
|
||||||
|
|
||||||
|
<%= label(f, :uses_left, gettext("Uses left"), class: "title text-lg text-primary-500") %>
|
||||||
|
<%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
|
||||||
|
<%= error_tag(f, :uses_left, "col-span-3") %>
|
||||||
|
|
||||||
|
<%= submit(dgettext("actions", "Save"),
|
||||||
|
class: "mx-auto btn btn-primary col-span-3",
|
||||||
|
phx_disable_with: dgettext("prompts", "Saving...")
|
||||||
|
) %>
|
||||||
|
</.form>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user