|
|
@ -25,6 +25,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|
|
|
label="Description"
|
|
|
|
label="Description"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<.bids_inputs form={@form} myself={@myself} />
|
|
|
|
<.bids_inputs form={@form} myself={@myself} />
|
|
|
|
|
|
|
|
<.author_roles_inputs form={@form} myself={@myself} />
|
|
|
|
<.input field={@form[:format]} type="text" label="Format" /><.input
|
|
|
|
<.input field={@form[:format]} type="text" label="Format" /><.input
|
|
|
|
field={@form[:language]}
|
|
|
|
field={@form[:language]}
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
@ -110,6 +111,70 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|
|
|
{:noreply, socket}
|
|
|
|
{:noreply, socket}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def author_roles_inputs(assigns) do
|
|
|
|
|
|
|
|
~H"""
|
|
|
|
|
|
|
|
<h2>Authors</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<table class="w-full">
|
|
|
|
|
|
|
|
<thead class="border-b border-zinc-100">
|
|
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
|
|
<th class="text-left font-medium text-sm pb-1 px-3">Author</th>
|
|
|
|
|
|
|
|
<th class="text-left font-medium text-sm pb-1 px-3">Role</th>
|
|
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody phx-hook="authorRoleSort" id="authorRoleSort" phx-target={@myself}>
|
|
|
|
|
|
|
|
<.inputs_for :let={author_roles_form} field={@form[:author_roles]}>
|
|
|
|
|
|
|
|
<tr data-id={author_roles_form.index}>
|
|
|
|
|
|
|
|
<td class="px-3">
|
|
|
|
|
|
|
|
<label for={author_roles_form[:author_id].id} class="hidden">Type</label>
|
|
|
|
|
|
|
|
<.input field={author_roles_form[:author_id]} />
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<td class="px-3">
|
|
|
|
|
|
|
|
<label for={author_roles_form[:role].id} class="hidden">Id</label>
|
|
|
|
|
|
|
|
<.input field={author_roles_form[:role]} />
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
</.inputs_for>
|
|
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<.button_link phx-click="add-author-role" phx-target={@myself} kind="primary" size="sm" inverse>
|
|
|
|
|
|
|
|
Add Author
|
|
|
|
|
|
|
|
</.button_link>
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
|
|
|
def handle_event("add-author-role", params, socket) do
|
|
|
|
|
|
|
|
socket =
|
|
|
|
|
|
|
|
update(socket, :form, fn form ->
|
|
|
|
|
|
|
|
AshPhoenix.Form.add_form(form, :author_roles)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:noreply, socket}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
|
|
|
def handle_event("remove-author-role", %{"path" => path}, socket) do
|
|
|
|
|
|
|
|
socket =
|
|
|
|
|
|
|
|
update(socket, :form, fn form ->
|
|
|
|
|
|
|
|
AshPhoenix.Form.remove_form(form, path)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:noreply, socket}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
|
|
|
def handle_event("reorder-author-role", %{"order" => order}, socket) do
|
|
|
|
|
|
|
|
socket =
|
|
|
|
|
|
|
|
update(socket, :form, fn form ->
|
|
|
|
|
|
|
|
AshPhoenix.Form.sort_forms(form, [:author_roles], order)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:noreply, socket}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
@impl true
|
|
|
|
def update(assigns, socket) do
|
|
|
|
def update(assigns, socket) do
|
|
|
|
{:ok,
|
|
|
|
{:ok,
|
|
|
|