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, :public}} type="checkbox" label="public" />
|
||||||
<.input field={{f, :unauthorized}} type="checkbox" label="unauthorized" />
|
<.input field={{f, :unauthorized}} type="checkbox" label="unauthorized" />
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" id="continue_edit" name="continue_edit" value="false" />
|
||||||
|
<input type="hidden" id="publish" name="publish" value="false" />
|
||||||
<:actions>
|
<: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>
|
phx-disable-with="Saving...">Save Translation</.button>
|
||||||
<input type="hidden" id="continue_edit" name="continue_edit"
|
<.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit") |> JS.set_attribute({"value", "true"}, to: "#publish")}
|
||||||
value="false" />
|
phx-disable-with="Saving...">Save and Publish</.button>
|
||||||
<.button phx-click={JS.set_attribute({"value", "true"}, to: "#continue_edit")}
|
<.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>
|
phx-disable-with="Saving...">Save and Edit</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.simple_form>
|
</.simple_form>
|
||||||
<.tunit_editor current_tunit={@current_tunit} target={@myself} />
|
<.tunit_editor current_tunit={@current_tunit} target={@myself} />
|
||||||
</div>
|
</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}
|
<.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>
|
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} />
|
<progress :if={@deepl_progress} max="100" value={@deepl_progress} />
|
||||||
@ -106,6 +108,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
|||||||
"content",
|
"content",
|
||||||
socket.assigns.translation_content
|
socket.assigns.translation_content
|
||||||
)
|
)
|
||||||
|
|> publish(params, socket)
|
||||||
}
|
}
|
||||||
save_translation(socket, socket.assigns.action, params)
|
save_translation(socket, socket.assigns.action, params)
|
||||||
end
|
end
|
||||||
@ -188,4 +191,16 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
|||||||
defp continue_edit(socket, %{"continue_edit" => "false"}) do
|
defp continue_edit(socket, %{"continue_edit" => "false"}) do
|
||||||
socket |> push_navigate(to: socket.assigns.navigate)
|
socket |> push_navigate(to: socket.assigns.navigate)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user