2023-08-24 21:58:03 +02:00
|
|
|
use crate::locales::trl;
|
2023-08-18 12:22:23 +02:00
|
|
|
use leptos::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
|
pub struct DialogOpener {
|
|
|
|
|
visible: ReadSignal<bool>,
|
|
|
|
|
set_visible: WriteSignal<bool>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DialogOpener {
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn new() -> Self {
|
|
|
|
|
let (visible, set_visible) = create_signal(false);
|
2023-08-18 12:22:23 +02:00
|
|
|
DialogOpener {
|
|
|
|
|
visible,
|
|
|
|
|
set_visible,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn visible(&self) -> bool {
|
|
|
|
|
self.visible.get()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn show(&self) {
|
2023-08-24 21:58:03 +02:00
|
|
|
self.set_visible.update(|state| *state = true);
|
2023-08-18 12:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn hide(&self) {
|
2023-08-24 21:58:03 +02:00
|
|
|
self.set_visible.update(|state| *state = false);
|
2023-08-18 12:22:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
|
pub fn ModalDialog(
|
|
|
|
|
opener: DialogOpener,
|
2023-08-24 21:58:03 +02:00
|
|
|
title: &'static str,
|
2023-08-18 12:22:23 +02:00
|
|
|
children: Children,
|
|
|
|
|
) -> impl IntoView {
|
2023-09-15 13:55:01 +02:00
|
|
|
view! {
|
2023-08-18 12:22:23 +02:00
|
|
|
<div class={ move || if opener.visible() {"modal fade show"} else {"modal fade"}}
|
|
|
|
|
style={ move || if opener.visible() {"display: block;"} else {""}}
|
|
|
|
|
id="modalCenter" tabindex="-1" aria-hidden="true">
|
|
|
|
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
|
|
|
|
<div class="modal-content">
|
|
|
|
|
<div class="modal-header">
|
2023-09-15 13:55:01 +02:00
|
|
|
<h5 class="modal-title" id="modalCenterTitle">{trl(title)}</h5>
|
2023-08-18 12:22:23 +02:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="btn-close"
|
|
|
|
|
data-bs-dismiss="modal"
|
|
|
|
|
aria-label="Close"
|
|
|
|
|
on:click=move |_| opener.hide()/>
|
|
|
|
|
</div>
|
2023-09-15 13:55:01 +02:00
|
|
|
{children()}
|
2023-08-18 12:22:23 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[component]
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn ModalBody(children: Children) -> impl IntoView {
|
|
|
|
|
view! {
|
2023-08-18 12:22:23 +02:00
|
|
|
<div class="modal-body">
|
2023-09-15 13:55:01 +02:00
|
|
|
{children()}
|
2023-08-18 12:22:23 +02:00
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[component]
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn ModalFooter(children: Children) -> impl IntoView {
|
|
|
|
|
view! {
|
2023-08-18 12:22:23 +02:00
|
|
|
<div class="modal-footer">
|
2023-09-15 13:55:01 +02:00
|
|
|
{children()}
|
2023-08-18 12:22:23 +02:00
|
|
|
</div>
|
|
|
|
|
}
|
2023-08-24 21:58:03 +02:00
|
|
|
}
|
2023-09-08 11:53:08 +02:00
|
|
|
|
|
|
|
|
#[component]
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn DlgNotLoaded(opener: DialogOpener, title: &'static str) -> impl IntoView {
|
|
|
|
|
view! {
|
2023-09-08 11:53:08 +02:00
|
|
|
<ModalDialog opener=opener title=title>
|
|
|
|
|
<ModalBody>
|
2023-09-15 13:55:01 +02:00
|
|
|
<div>{trl("Entity not loaded")}</div>
|
2023-09-08 11:53:08 +02:00
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal" on:click=move |_| opener.hide()>
|
2023-09-15 13:55:01 +02:00
|
|
|
{trl("Close")}
|
2023-09-08 11:53:08 +02:00
|
|
|
</button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</ModalDialog>
|
|
|
|
|
}
|
|
|
|
|
}
|