Add "publish" button to translation form
This commit is contained in:
@ -32,18 +32,20 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
<.input field={{f, :public}} type="checkbox" label="public" />
|
||||
<.input field={{f, :unauthorized}} type="checkbox" label="unauthorized" />
|
||||
</div>
|
||||
<input type="hidden" id="continue_edit" name="continue_edit" value="false" />
|
||||
<input type="hidden" id="publish" name="publish" value="false" />
|
||||
<:actions>
|
||||
<.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit")}
|
||||
<.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit") |> JS.set_attribute({"value", "false"}, to: "#publish")}
|
||||
phx-disable-with="Saving...">Save Translation</.button>
|
||||
<input type="hidden" id="continue_edit" name="continue_edit"
|
||||
value="false" />
|
||||
<.button phx-click={JS.set_attribute({"value", "true"}, to: "#continue_edit")}
|
||||
<.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit") |> JS.set_attribute({"value", "true"}, to: "#publish")}
|
||||
phx-disable-with="Saving...">Save and Publish</.button>
|
||||
<.button phx-click={JS.set_attribute({"value", "true"}, to: "#continue_edit") |> JS.set_attribute({"value", "false"}, to: "#publish")}
|
||||
phx-disable-with="Saving...">Save and Edit</.button>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
<.tunit_editor current_tunit={@current_tunit} target={@myself} />
|
||||
</div>
|
||||
<div class="article basis-1/2 overflow-auto">
|
||||
<div class="article basis-1/2 max-h-screen overflow-auto">
|
||||
<.button phx-disable-with="Translating..." phx-click="translate-deepl" phx-target={@myself}
|
||||
data-confirm-not="Are you sure? All previously translated text will be lost.">Translate with Deepl</.button>
|
||||
<progress :if={@deepl_progress} max="100" value={@deepl_progress} />
|
||||
@ -106,6 +108,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
"content",
|
||||
socket.assigns.translation_content
|
||||
)
|
||||
|> publish(params, socket)
|
||||
}
|
||||
save_translation(socket, socket.assigns.action, params)
|
||||
end
|
||||
@ -188,4 +191,16 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
defp continue_edit(socket, %{"continue_edit" => "false"}) do
|
||||
socket |> push_navigate(to: socket.assigns.navigate)
|
||||
end
|
||||
|
||||
defp publish(translation_params, %{"publish" => "true"}, socket) do
|
||||
translation_params
|
||||
|> Map.put("public_content",
|
||||
OutlookWeb.HtmlDocComponent.render_doc(%{tree: InternalTree.render_translation(socket.assigns.translation.article.content,
|
||||
translation_params["content"]), tunit_tag: "span"})
|
||||
|> Phoenix.HTML.Safe.to_iodata()
|
||||
|> IO.iodata_to_binary())
|
||||
end
|
||||
defp publish(translation_params, %{"publish" => "false"}, _) do
|
||||
translation_params
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user