Update the Book form to select Author for AuthorRole via the components.
This commit is contained in:
@@ -55,7 +55,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} />
|
<.author_roles_inputs form={@form} myself={@myself} notify_component={@myself} />
|
||||||
<.input field={@form[:format]} type="text" label="Format" />
|
<.input field={@form[:format]} type="text" label="Format" />
|
||||||
<.input
|
<.input
|
||||||
field={@form[:language]}
|
field={@form[:language]}
|
||||||
@@ -100,6 +100,21 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
notify_component={@myself}
|
notify_component={@myself}
|
||||||
/>
|
/>
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
|
<.modal
|
||||||
|
:if={@select_author_open? == true}
|
||||||
|
id="select-author-modal"
|
||||||
|
show
|
||||||
|
on_cancel={JS.push("close-select-author", target: @myself)}
|
||||||
|
>
|
||||||
|
<.live_component
|
||||||
|
id="select-author"
|
||||||
|
module={SelectAuthor}
|
||||||
|
current_user={@current_user}
|
||||||
|
notify_component={@myself}
|
||||||
|
form_path={@form_path}
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
@@ -213,6 +228,11 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
<td class="px-3 w-96">
|
<td class="px-3 w-96">
|
||||||
<label for={author_roles_form[:author_id].id} class="hidden">Type</label>
|
<label for={author_roles_form[:author_id].id} class="hidden">Type</label>
|
||||||
<.input field={author_roles_form[:author_id]} />
|
<.input field={author_roles_form[:author_id]} />
|
||||||
|
<.selected_author
|
||||||
|
author_form={author_roles_form[:author_id]}
|
||||||
|
notify_component={@notify_component}
|
||||||
|
form_path={author_roles_form.name}
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-3">
|
<td class="px-3">
|
||||||
<label for={author_roles_form[:role].id} class="hidden">Id</label>
|
<label for={author_roles_form[:role].id} class="hidden">Id</label>
|
||||||
@@ -279,6 +299,8 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
socket
|
socket
|
||||||
|> assign(assigns)
|
|> assign(assigns)
|
||||||
|> assign(:select_publisher_open?, false)
|
|> assign(:select_publisher_open?, false)
|
||||||
|
|> assign(:select_author_open?, false)
|
||||||
|
|> assign(:form_path, nil)
|
||||||
|> assign_form()}
|
|> assign_form()}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -370,4 +392,37 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("select-author", %{"author" => author_id, "path" => path}, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> update(:form, fn form ->
|
||||||
|
form
|
||||||
|
|> AshPhoenix.Form.update_form(path, fn nested_form ->
|
||||||
|
params = Map.put(nested_form.params, "author_id", author_id)
|
||||||
|
AshPhoenix.Form.validate(nested_form, params)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|> assign(:select_author_open?, false)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("open-select-author", %{"path" => path, "value" => value}, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:select_author_open?, true)
|
||||||
|
|> assign(:form_path, path)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("close-select-author", _params, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:select_author_open?, false)
|
||||||
|
|> assign(:form_path, nil)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user